Skip to content

refactor(agent-service): redesign sync-execution result and error model#5927

Draft
bobbai00 wants to merge 11 commits into
apache:mainfrom
bobbai00:refactor/agent-service-execution-model
Draft

refactor(agent-service): redesign sync-execution result and error model#5927
bobbai00 wants to merge 11 commits into
apache:mainfrom
bobbai00:refactor/agent-service-execution-model

Conversation

@bobbai00

@bobbai00 bobbai00 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Stacked on #5751 (foundation). This is the second of the split: it carries the sync-execution result/error model redesign (no overlap with the foundation PR — types/execution.ts is untouched there).

  • Replace the flat OperatorInfo with OperatorExecutionSummary (orthogonal sub-summaries: state, errorMessages, resultSummary?, consoleLogsSummary?); rename SyncExecutionResultWorkflowExecutionSummary.
  • resultSummary.sampleTuples is now SampleRow[] ({ rowIndex, tuple }) instead of JSON rows with an embedded __row_index__; drop the table-shape types (the agent derives input-port shapes from the DAG).
  • Reuse the engine's WorkflowFatalError for per-operator errors (the same type the compiling service returns), replacing the bespoke OperatorError so compile and execution errors share one wire shape.
  • errorMessages / errors are non-optional (empty = none); drop compilationErrors; collapse the console-message types and derive warnings from WARNING:-titled messages.
  • The WS operatorResults payload carries the canonical OperatorExecutionSummary; the frontend maps it to its flat display type.

Touches the Scala producer (SyncExecutionResource), the agent-service consumers (result-formatting, workflow-execution-tools, workflow-result-state, server), and the frontend WS mapping. Representation/type-level; behavior preserved (input-port shape lines are now derived rather than explicitly rendered).

Any related issues, documentation, discussions?

Closes #5750
Part of #5747.

How was this PR tested?

  • bunx tsc --noEmit, bun test (121 pass / 0 fail), prettier --check in agent-service; sbt WorkflowExecutionService/compile for amber.
  • End-to-end on the full local stack with a Claude Haiku 4.5 agent: it built and executed a CSV workflow; /operator-results returned the new shape — resultSummary.sampleTuples: [{ rowIndex, tuple }], errorMessages: [] — and the agent rendered the rows correctly.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.8 (1M context)

bobbai00 and others added 11 commits June 23, 2026 22:38
…module

Foundation slice of the agent-service reorganization (no runtime behavior
change):

- Add src/types/api.ts (wire DTOs) and src/types/metadata.ts (operator
  metadata types extracted out of api/backend-api.ts); export both from the
  types barrel.
- Add src/config/endpoints.ts exposing getServiceEndpoints().
- Move src/api/auth-api.ts -> src/auth/jwt.ts (content unchanged) and add
  src/auth/jwt.test.ts; update auth import paths.
- Keep api/backend-api.ts transitional: it now imports/re-exports the metadata
  types from ../types/metadata and retains getBackendConfig/fetchOperatorMetadata,
  which the follow-up clients PR relocates.

The types/agent.ts and types/workflow.ts reshaping is deferred to the PR that
also updates server.ts/workflow-state.ts, since those renames are coupled.
Split types/api.ts into types/wire.ts (backend wire DTOs) and types/ws.ts
(this service's own WebSocket frames), and consume them at the real call
sites instead of the duplicate definitions that previously lived inline:

- server.ts imports WsMessage/WsOutgoingMessage/OperatorResultSummaryWs from
  types/ws (local copies removed).
- api/workflow-api.ts imports Workflow/WorkflowPersistRequest from types/wire.
- api/compile-api.ts, agent/util/context-utils.ts, and agent/texera-agent.ts
  import WorkflowFatalError/WorkflowCompilationResponse from types/wire.

Correct WorkflowFatalError to match the backend proto (workflowruntimestate.proto):
`type` is the FatalErrorType enum name (string), with details/operatorId/
workerId/timestamp optional, replacing the inaccurate `type: { name }` /
all-required shape. Type-level only; consumers read only `.message`, so there
is no runtime behavior change.

tsc --noEmit, prettier --check, and bun test (101 pass / 0 fail) all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Encode test JWT segments as base64url (not base64) to match real tokens,
  including a case whose payload contains `-`/`_` to pin url-safe decoding.
- Add extractBearerToken coverage: valid bearer, case-insensitive scheme,
  non-Bearer scheme, missing token, absent header.

Addresses the Copilot review comments on src/auth/jwt.test.ts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure file rename plus import-path updates; no type or behavior changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…hema from types/metadata

workflow-system-metadata.ts defined its own copies of these two interfaces,
identical to the canonical ones in types/metadata.ts. Import the canonical
types and delete the duplicates so the centralized definitions are actually
used. Type-level only; no behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…initions

Remove all `any` from src/types/*.ts:
- opaque/object JSON blobs -> unknown / Record<string, unknown> (jsonSchema,
  operatorProperties, result rows, sampleRecords, ReActStep tool input/output,
  physicalPlan, OperatorSchemaInfo/CompactOperatorSchema).
- WsOutgoingMessage.workflowContent -> WorkflowContent (it is assigned from
  WorkflowState.getWorkflowContent()).

Type-level only; tsc, prettier, and tests pass with no consumer changes needed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…o *.spec.ts

- Rename all *.test.ts to *.spec.ts (bun discovers .spec by default; no config change).
- Add workflow-system-metadata.spec.ts: schema compaction ($ref inlining, key
  filtering), getAllSchemasAsJson, Ajv property validation, and the formatting helpers.
- Add workflow-api.spec.ts and compile-api.spec.ts: persist/retrieve/compile over a
  mocked fetch, exercising the proto-accurate WorkflowFatalError shape.

126 pass / 0 fail; tsc and prettier green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ReActStep used `unknown` for fields whose shapes we actually know:
- inputMessages -> ModelMessage[] (the prepared AI SDK messages)
- toolCalls[].input -> Record<string, unknown> (tool args are JSON objects)
- toolResults[].output -> string (every tool returns via createToolResult/createErrorResult)

The AI SDK types tc.input / tr.output as `unknown` for dynamically registered
tools, so narrow at the single construction boundary in texera-agent.ts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ted unions

Replace the flat src/types/ws.ts with a types/ws/ directory:
- client.ts: WsClientRequest = WsClientRequestPrompt | WsClientRequestStopCommand
  (each extending a base; orthogonal fields instead of one all-optional interface)
- server.ts: WsServerMessage union (init/step/state/complete/error/headChange),
  each declaring only the fields it sends; OperatorResultSummaryWs moves here
- index.ts: barrel so types/index.ts's `export * from "./ws"` resolves to the dir

The client->server wire discriminator changes from "message"/"stop" to
"prompt"/"command" (stop becomes commandType:"stop"); server->client `type`
values are unchanged. server.ts parses WsClientRequest and switches on the new
shapes, and the frontend agent.service.ts WS sends are updated in lockstep so
the protocol stays consistent end-to-end.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ndation PR

The execution-result redesign (OperatorExecutionSummary etc.) lives in a
follow-up PR; revert the lone any->unknown tweak so this PR leaves
types/execution.ts byte-identical to main.
Restructure the per-operator summary the sync-execution backend returns and the
agent-service/frontend consume, for a leaner and consistent wire contract:

- Replace flat OperatorInfo with OperatorExecutionSummary: state, errorMessages,
  resultSummary?, consoleLogsSummary? (orthogonal sub-summaries; no shape stats).
- Rename SyncExecutionResult -> WorkflowExecutionSummary; drop compilationErrors
  (folded into errors). errors and per-op errorMessages are non-optional (empty
  means none).
- OperatorResultSummary.sampleTuples is now List[SampleRow] ({rowIndex, tuple})
  instead of a JSON array with an embedded __row_index__. Drop the table-shape
  types (TableShape/InputPortTableShape): the agent derives input-port shapes
  from the DAG + each upstream's output shape; output shape comes from the result
  summary.
- Reuse the engine's WorkflowFatalError for per-operator errors (the same type
  the compiling service returns for compilation errors), replacing the bespoke
  OperatorError so compile and execution errors share one wire shape.
- Collapse console messages onto one type; derive warnings from WARNING-titled
  messages rather than a separate field.
- Replace OperatorResultSummaryWs: the WS operatorResults payload now carries the
  canonical OperatorExecutionSummary; the frontend maps it to its flat display
  type (re-flattening sampleTuples to keep the display components unchanged).

Touches the Scala producer (SyncExecutionResource), the agent-service consumers
(result-formatting, workflow-execution-tools, workflow-result-state, server) and
the frontend WS mapping. Representation/type-level change; behavior preserved,
except input-port shape lines are now derived rather than explicitly rendered.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012qFkyrpTd5PrkNBPcBeo4Q
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @Ma77Ball, @officialasishkumar
    You can notify them by mentioning @Ma77Ball, @officialasishkumar in a comment.

@codecov-commenter

codecov-commenter commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.55914% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.19%. Comparing base (1c580e5) to head (3a1c181).

Files with missing lines Patch % Lines
...ervice/src/agent/tools/workflow-execution-tools.ts 3.33% 29 Missing ⚠️
agent-service/src/server.ts 17.64% 14 Missing ⚠️
...d/src/app/workspace/service/agent/agent.service.ts 0.00% 9 Missing ⚠️
agent-service/src/agent/texera-agent.ts 14.28% 6 Missing ⚠️
agent-service/src/agent/workflow-result-state.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5927      +/-   ##
============================================
+ Coverage     54.60%   55.19%   +0.59%     
  Complexity     2927     2927              
============================================
  Files          1109     1109              
  Lines         42828    42630     -198     
  Branches       4608     4604       -4     
============================================
+ Hits          23385    23529     +144     
+ Misses        18081    17738     -343     
- Partials       1362     1363       +1     
Flag Coverage Δ *Carryforward flag
access-control-service 70.44% <ø> (ø) Carriedforward from 2bae592
agent-service 40.03% <40.47%> (+5.67%) ⬆️
amber 57.06% <ø> (+0.33%) ⬆️ Carriedforward from 2bae592
computing-unit-managing-service 1.65% <ø> (ø) Carriedforward from 2bae592
config-service 57.35% <ø> (ø) Carriedforward from 2bae592
file-service 58.59% <ø> (ø) Carriedforward from 2bae592
frontend 48.29% <0.00%> (-0.02%) ⬇️
pyamber 90.20% <ø> (ø) Carriedforward from 2bae592
python 90.76% <ø> (ø) Carriedforward from 2bae592
workflow-compiling-service 58.69% <ø> (ø) Carriedforward from 2bae592

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

✅ No material benchmark regressions detected

🟢 0 better · 🔴 0 worse · ⚪ 15 noise (<±5%) · 0 without baseline

Compared against main 1c580e5 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
bs=10 sw=10 sl=64 439 0.268 21,713/31,124/31,124 us ⚪ within ±5% / 🟢 -11.0%
bs=100 sw=10 sl=64 965 0.589 104,818/118,185/118,185 us ⚪ within ±5% / 🟢 -15.5%
bs=1000 sw=10 sl=64 1,114 0.68 899,323/950,203/950,203 us ⚪ within ±5% / 🟢 -7.5%
Baseline details

Latest main 1c580e5 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 439 tuples/sec 456 tuples/sec 410.82 tuples/sec -3.7% +6.9%
bs=10 sw=10 sl=64 MB/s 0.268 MB/s 0.278 MB/s 0.251 MB/s -3.6% +6.9%
bs=10 sw=10 sl=64 p50 21,713 us 20,941 us 23,785 us +3.7% -8.7%
bs=10 sw=10 sl=64 p95 31,124 us 31,618 us 34,980 us -1.6% -11.0%
bs=10 sw=10 sl=64 p99 31,124 us 31,618 us 34,980 us -1.6% -11.0%
bs=100 sw=10 sl=64 throughput 965 tuples/sec 981 tuples/sec 891.94 tuples/sec -1.6% +8.2%
bs=100 sw=10 sl=64 MB/s 0.589 MB/s 0.599 MB/s 0.544 MB/s -1.7% +8.2%
bs=100 sw=10 sl=64 p50 104,818 us 102,364 us 112,277 us +2.4% -6.6%
bs=100 sw=10 sl=64 p95 118,185 us 112,646 us 139,802 us +4.9% -15.5%
bs=100 sw=10 sl=64 p99 118,185 us 112,646 us 139,802 us +4.9% -15.5%
bs=1000 sw=10 sl=64 throughput 1,114 tuples/sec 1,115 tuples/sec 1,041 tuples/sec -0.1% +7.0%
bs=1000 sw=10 sl=64 MB/s 0.68 MB/s 0.681 MB/s 0.635 MB/s -0.1% +7.0%
bs=1000 sw=10 sl=64 p50 899,323 us 895,460 us 972,714 us +0.4% -7.5%
bs=1000 sw=10 sl=64 p95 950,203 us 962,472 us 1,023,057 us -1.3% -7.1%
bs=1000 sw=10 sl=64 p99 950,203 us 962,472 us 1,023,057 us -1.3% -7.1%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,455.19,200,128000,439,0.268,21712.58,31124.48,31124.48
1,100,10,64,20,2072.22,2000,1280000,965,0.589,104817.72,118184.64,118184.64
2,1000,10,64,20,17957.45,20000,12800000,1114,0.680,899322.80,950203.24,950203.24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-service engine frontend Changes related to the frontend GUI refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(agent-service): redesign the sync-execution result and error model

2 participants