Skip to content

fix(runtime): preserve execution ownership across stream loss - #1301

Merged
XuPeng-SH merged 5 commits into
mainfrom
fix/verified-main-execution-closure
Nov 15, 2026
Merged

XuPeng-SH merged 5 commits into
mainfrom
fix/verified-main-execution-closure

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Capability assessment: Unchanged: Runtime, Work, CLI, Web and MCP retain their existing support status and runtime profiles. This repairs stream observation, diagnostics and result reporting; permissions, the MOI gate and prompt-cache behavior are unchanged.

Summary

A lost stream could invent a failed run, replace its actionable cause, cancel an already-started tool, or discard an uncertain Work request. Keep execution settlement with its owner and make observation failure recoverable.

  • Remove synthetic failed terminals, duplicate pending-error/root identity state and the SDK transport execution-terminal classifier.
  • Commit durable replay cursors only on the final receipt; release physical readers at DONE without flushing incomplete frames.
  • Preserve tool custody, partial results and the original request/branch/attachment IDs. Only a first-attempt definite pre-admission 4xx other than 408 releases a rejected request; other HTTP/protocol failures remain unconfirmed, with explicit same-ID recovery. A later recovery rejection cannot discard the original uncertain request. Fresh guidance retires the previous interaction root; same-request recovery preserves its own identity.
  • Keep confirmed completed/paused chat results and resume bindings when supplemental artifact loading fails. Report the auxiliary failure through the existing warning channel and fence late reads after cancellation, replacement or resume.
  • Keep POST 408 unconfirmed without replay, restore the existing transient GET retry budget, and prevent cancelled HTTP decoders from publishing late errors.
  • Preserve bounded HTTP error code/category/action hints in CLI diagnostics. Report CLI cache.hit as null when coverage is unknown.

Related issue

Refs #1016, #1249, #1261, #1100, #1119, #1290, #1291. Existing fixes and controlled baselines are reused where applicable; this PR does not claim complete closure of all seven reports.

Change type

  • Bug fix
  • Documentation
  • Refactor or performance improvement
  • Test

User and compatibility impact

An unconfirmed stream emits the existing stream_observation_interrupted error instead of a fabricated failed run_finished. Only producer-owned receipts settle execution. Live completed/paused receipts require their response projection; indexed durable replay uses its journaled answer.

Finite replay/error and live responses use the existing SSE DONE marker. Web delivers supplemental artifacts or an auxiliary warning before its one downstream marker. The selected result and paused resume identity survive that optional read failing; cancelled or superseded readers cannot publish late data.

Work runtime observations pass the canonical server projection without a second SDK event allowlist. Identity and control-envelope validation remain strict. SDK Work callbacks have an open event union; unguarded event.type switches may require migration to isWorkTurnEventType. CLI JSON cache.hit is nullable for unknown coverage; observed hits and supported complete zero reads retain their meaning.

Architecture and complexity delta

  • Canonical owners extended: runtime SSE adapter, shared Rust dispatcher/stream host, existing CLI Work outcome/acceptance boundary, SDK root projection and Web proxy/lease.
  • Callers checked: thin client, CLI/TUI, SDK hooks and Work decoder, browser chat, Work composer and store projection.
  • Removed: fabricated terminal fallbacks, duplicate pending error/root identity, unreachable Interrupted/root-guessing branches and redundant Work event catalog.
  • Reuse the existing Unknown outcome, pending request, warning/error channels, bounded diagnostic formatter and projection lease. Work recovery knowledge stays on that pending request across reconnect, takeover and viewing; Web no longer relies on entrypoint mode flags. No new lifecycle status, execution path, retry mechanism, store, poller, schema or SQL. Unknown requests retain custody; metadata failure has no settlement authority.
  • Prompt content, provider cache keys/prefixes, tool permissions and all pinned MOI gate files are unchanged.

Verification

Current correction on machine 57:

  • Complete CLI CI inventory: 5,496 passed; 23 configured skips. Real ThinClient/WireMock covers 408, 302 without a Location header, and definite 403; checks actual request bodies, no automatic retry/cleanup, retained acceptance state, explicit same-ID retry and rejection cleanup.
  • Web: 1,036 full-suite passes, including immutable late-write snapshots, mixed recovery attempts and fresh guidance after refreshed or locally answered earlier interactions. The composer suite has 40 passing cases; two first-rejection tests were consolidated into six actual-SDK cases. Actual POST route/store/browser consumer verifies completed/paused callbacks, warning diagnostics, one DONE, delayed artifact success/failure, cancellation, replacement, resume and stale reader cleanup.
  • SDK: 573 offline passes; 13 opt-in live cases unrun. Typecheck and build pass.
  • CLI cargo check, all-target Clippy with warnings denied, Rust formatting and diff checks pass. Web typecheck, affected ESLint and production build pass.
  • Terra/max design and overall review: gpt-6.1-terra / max approved the initial design and this identity correction design (thread 01a1dd56-1693-7ff1-b0a3-26e70e79b151); final overall review approved the exact 49-file candidate with no material blocker (thread 01a1dd5d-a419-72f3-973c-3ed38e3a88c9, full-diff SHA-256 e0c1674037053d2b5b2a2b92cd404b92385bdf220289fda5ec5996e9a91960d2).

Reused evidence for unchanged boundaries:

  • Baseline 904c597: 41 GitHub checks completed; 38 success, 2 configured skips, 1 neutral. Reused unchanged runtime full inventory: 6,058 passed (204 configured skips). Earlier SDK evidence is superseded by the current 573-pass run.
  • Initial owning Rust/SSE/callback/accounting contracts and deterministic started-versus-queued execution races passed. Frozen MOI fresh-database gate, two Work HTTP/database boundary tests, native Work/continuation/compaction/cache-prefix controls and the Linux public ToolExecutor browser journey passed.
  • Nine real Router/MatrixOne SQL scenarios retained 17 cold / 19 warm / 18 held-control statements and two transaction windows. This correction changes no persistence query or schema.
  • No Go code changed: Go-race is inapplicable. Rust/TypeScript logical concurrency is exercised with actual HTTP and controlled channels/promises; no sanitizer pass is claimed.

Remaining limits: the original deployed macOS/browser incident, cross-instance MCP cancellation/reaping and historical comparable 3× latency target remain unverified. The existing SDK artifact read exposes no abort signal; submitted reads follow existing fetch behavior and late results are fenced. No new timeout or retry is introduced, and no finite SDK timeout is claimed. The new hosted CI run is not awaited.

Final checklist

  • Tests cover owning public boundaries and unhappy paths.
  • Design documentation reflects the observation/outcome contract.
  • Diff checked for credentials, private endpoints, generated files and unrelated changes.
  • Conventional Commit title.

@mergify

mergify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

Copy link
Copy Markdown
Collaborator Author

Request changes on head 03f0a65. The ownership direction is reasonable, but two existing fallback paths still violate the behavior this PR changes.

  1. [P2] Preserve the confirmed outcome when supplemental artifact loading fails. The post-turn artifact fetch and broad catch still turn an auxiliary read failure into a failed assistant message and clear the active run. This now overwrites the paused binding selected by finishRunResponse.

    Reproduced through the real POST route, chat store and public streamChatMessage consumer: session_info → text_done → owned run_finished(completed/paused, generation 4) → authoritative turn_complete → DONE. The preflight artifact read succeeds; only the post-turn read fails. Both cases produce WebApiError(500), stored status failed and activeRun null; neither completion callback fires. Both successful-artifact controls pass. For paused runs this removes the resume binding, not just the artifact display. Keep the ancillary failure in the existing warning/auxiliary channel after a confirmed outcome; preserve that outcome and binding. This catch predates the PR but remains incompatible with the changed owner/projection boundary.

  2. [P2] Keep CLI Work custody for HTTP 408 as well as 5xx. The API-error classification treats only 5xx as Unknown; 408 becomes Rejected. This takes the attachment-deletion branch at line 1084 and removes the original request from pending_work_retries at line 1155. A timeout after forwarding does not establish non-admission. The Web composer already explicitly excludes 408 from definite rejection, and the PR claims this custody behavior across clients.

    Reproduced by adding one ResponseTemplate::new(408) case to the existing real ThinClient/WireMock test work_continue_keeps_server_error_unknown_for_exact_retry: its Unknown assertion fails. Handle 408 in the existing inconclusive-status branch, retaining the attachment/request ID and explicit same-ID recovery. No new retry mechanism or state machine is needed. This classification also predates the PR; it is an incomplete custody integration on the modified path.

The CI repair is pushed as 03f0a6588: remove synthetic cancellation text when the actual callback cause replaces it, and align SSE/owner/cursor fixtures with the producer contract. No workflow, MOI gate, SQL or prompt-cache changes.

Validation on machine 57: all eight original CI failures now pass; runtime complete CI inventory 6058 passed (204 skipped); CLI inventory 5493 passed, with two inherited NO_COLOR=1 banner failures separately passing under a controlled color environment (23 originally skipped). CLI/runtime all-target Clippy with -D warnings and formatting pass. The new hosted CI run is not awaited. The review-only counterexamples were kept out of the repair commit.

GitHub rejected the formal review because the authenticated account is this PR author. This comment records the request-changes recommendation; it does not set the formal GitHub REQUEST_CHANGES review state.

@XuPeng-SH

Copy link
Copy Markdown
Collaborator Author

Follow-up fixes are pushed in 904c597.

  • Confirmed completed/paused chat results survive an optional artifact-read failure; warning diagnostics remain available and late cancelled/replaced readers cannot publish.
  • Inconclusive HTTP responses retain the original Work request and attachment IDs. Reconnect, takeover and Keep viewing share the pending request’s knowledge; a later recovery rejection cannot erase earlier uncertainty. Definite first-admission rejection still cleans up.
  • POST 408 does not fabricate execution failure or replay the POST. GET 408/429 uses the existing cancellable retry budget. Cancelled HTTP decoding cannot publish a late error. CLI keeps bounded original code/category/action hints.

These address both findings in the earlier review and the subsequently reproduced recovery counterexamples without adding SQL, storage, polling, a lifecycle state machine or a retry controller. Prompt-cache behavior, permissions and the MOI gate are unchanged.

Current local validation: CLI 5,496 passed / 23 configured skips; SDK 573 passed / 13 opt-in live cases unrun; Web 1,032 passed. Rust all-target check/Clippy/format, SDK typecheck/build, Web typecheck/affected ESLint/production build and PR metadata validation passed. Actual HTTP and controlled async tests cover cancellation, replacement, same-ID recovery and stale publication; no sanitizer pass is claimed.

gpt-6.1-terra / max design and final overall review approved the exact content, with no unresolved material blocker. Complete reviewed diff SHA-256: 803089d5e125b5932f450cc6b75933df9ed974274685a037d8fb10a6ac3ac67e. Final review thread: 01a1dd2c-7670-7d43-94da-b21c5a2e9a9d.

The PR description retains the original macOS, cross-instance MCP and comparable historical performance validation gaps. This does not claim blanket closure of the seven referenced issues. Hosted CI is not awaited.

@XuPeng-SH

Copy link
Copy Markdown
Collaborator Author

Request changes on commit 904c597.

[P2] Scope admission knowledge to the new pending turn, not an old interaction run. The first-rejection checks still require !rootRunId.current, but interaction refresh retains the previous run ID when the interaction list becomes empty. Submitting new guidance creates a fresh PendingTurn without retiring that old binding. The real parent keys the composer by Work/branch, so its interaction refresh does not remount it.

Reachable sequence: open a Work with an approval/question from old run A; another surface answers it and a refresh supplies an empty interaction list; send a new instruction B; B's very first HTTP response is a definite pre-admission rejection. With 403, pending is never cleared, guidance remains disabled and Reconnect is incorrectly offered for a request known to be rejected. With 409 writer_conflict, mayHaveRun is not reset, so Keep viewing enters the uncertain-request branch instead of restoring the draft and releasing the rejected turn.

Executed on machine 57 using the real SDK SSEClient, React component and controlled HTTP responses: both old-interaction cases fail; the otherwise identical no-old-interaction 403/409 controls pass. Replacing only the composer with its merge-base version makes all four probes pass; the candidate component was restored afterward. This is a component regression control using the same current SDK, not a full-base benchmark.

Retire the old request-scoped root binding when creating a genuinely new pending turn, or otherwise derive first-admission knowledge only from this pending request. Preserve that binding across actual same-request recovery. Reuse the existing owners; no new state machine, query or compatibility layer is needed. Cover refreshed old-interaction -> fresh 403 and -> fresh writer_conflict/Keep viewing alongside the existing uncertain-recovery controls.

The two substantive findings in the earlier discussion are addressed: post-turn artifact failure now uses the warning channel without replacing confirmed completed/paused outcomes, and CLI 408/inconclusive HTTP retains request custody and bounded original diagnostics. There are no formal reviews or inline threads at the reviewed snapshot; the merge-queue bot comment requires no code change.

I checked the complete 49-file delta by owner: execution/receipt ownership in runtime and turn-core; Rust thin-client/CLI consumers; SDK transport/projection and hooks; Web projection lease and Work interaction lifecycle. Removing synthetic terminals, duplicate error/root tracking and the SDK event allowlist is coherent. The remaining blocker is the stale old/new identity assumption above, not a need for another recovery path.

Implementation, tests and documentation were considered separately. Existing exact-source CLI 5,496 / SDK 573 / Web 1,032 passing evidence is reused rather than represented as fresh review executions. The new four-case QA probe has 2 failures and 2 controls passing; all four component baseline controls pass. Existing tests start the first-rejection cases with no prior interaction, which is why they miss this regression. Documentation accurately limits execution settlement to its owner and does not promise blanket closure of the seven issues.

Cost: no new schema, query, persistence writer or polling loop in this delta; the recorded nine real Router/MatrixOne scenarios retain 17 cold / 19 existing-context / 18 held-control SQL statements. This is unchanged SQL cost, not a measured storage reduction or latency improvement. Original macOS, cross-instance MCP and historical comparable performance limits remain unverified.

No subagents, implementation changes, commits or pushes were made for this review. The main PR checkout stayed clean and its 49 source hashes match the reviewed full-diff SHA-256 803089d5e125b5932f450cc6b75933df9ed974274685a037d8fb10a6ac3ac67e. Only an isolated review worktree carried the saved test probes. Final diff check passed; hosted CI was not waited on.

GitHub rejected the formal REQUEST_CHANGES review because the authenticated account is the PR author. This comment records the recommendation; it does not set the formal GitHub review state.

@XuPeng-SH

Copy link
Copy Markdown
Collaborator Author

The stale prior-interaction identity finding is fixed in 5962e31.

Fresh guidance now retires the earlier interaction's root immediately before creating its pending request. Same-request reconnect and takeover preserve their existing identity, uncertainty and receipt. This uses the existing owner: no new field, state machine, SQL, storage or retry path.

Two older first-rejection tests were consolidated into one real-SDK/React six-case table: first403 and writer-conflict409, each with no prior interaction, an earlier interaction removed by refresh, or an interaction answered locally before updated props arrive. Before the production fix, all four old-interaction cases failed and both no-history controls passed. After the fix, all six pass; the full Web suite passes 1,036 tests, including 40 composer cases and the existing genuine-uncertainty/reconnect/takeover controls. First403 releases input without Reconnect; first409/Keep viewing restores the draft and removes optimistic messages without taking control.

Production delta is one synchronous assignment and its comment. The test file is net+8lines after consolidation. Web typecheck, affected ESLint, production build, diff and PR metadata checks passed. The 47 unchanged files retain their prior Rust/SDK/runtime/native/MOI/SQL evidence; no storage reduction or measured latency improvement is claimed.

gpt-6.1-terra / max approved the design before implementation (thread 01a1dd56-1693-7ff1-b0a3-26e70e79b151) and the final overall review with no remaining material blocker (thread 01a1dd5d-a419-72f3-973c-3ed38e3a88c9). Exact complete candidate diff SHA-256: e0c1674037053d2b5b2a2b92cd404b92385bdf220289fda5ec5996e9a91960d2. This is model review, not a formal GitHub self-approval.

The original macOS, cross-instance and historical performance validation limits remain. New hosted CI is not awaited. No merge or deployment was performed.

@XuPeng-SH
XuPeng-SH merged commit cba30c5 into main Nov 15, 2026
40 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/verified-main-execution-closure branch November 15, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant