Repository navigation
fix(server): finalize runs when provider streams stop - #15776
Open
Adamulek123 wants to merge 6 commits into
Open
Adamulek123 wants to merge 6 commits into
Adamulek123 wants to merge 6 commits into
Conversation
Adamulek123
marked this pull request as ready for review
October 4, 2026 22:23
Contributor
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR substantially changes production orchestration behavior across provider-stream termination, startup failures, steering, shutdown recovery, artifact persistence, and checkpoint finalization. Its transactional guards and concurrency changes span multiple server components, so the runtime lifecycle impact is broader than a routine bug fix. You can add or adjust custom eligibility rules. Learn more. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A provider stream can end without an accepted root terminal, leaving a run active and partial assistant text or plans still streaming. Startup failure can also race event ingestion. This change finalizes those paths once, closes artifacts belonging to the ending attempt and preserves successor artifacts and longer projected content.
Finalization retains main's transactional event/effect writes and current-attempt guard. Synthetic failures can bypass a failed ownership-read predicate while the transaction still checks attempt identity. Normal terminal races and Stop retain the same guard. Checkpoint context lookup failures and missing checkpoint scopes are surfaced instead of silently skipping workspace refresh.
The latest review reproduced a regression in this PR's clean-drain handling: normal managed server shutdown could persist a failed run before recovery, causing a prepared restart continuation to be rejected. Managed event subscriptions now expose an optional local shutdown hint. Run execution reads it only when a stream closes successfully without an accepted root terminal and leaves settlement to runtime recovery. Unexpected stream loss, startup failure, manual provider release and accepted terminals keep their handling. This adds no client wire field or per-event work.
The regression uses the actual session manager, Orchestrator, effect worker and in-memory SQLite. Before the correction it observed a failed source run. Afterward, recovery cancels the source and a fresh manager and worker over the same database deliver the prepared continuation and persist a running successor provider turn. Four controls cover unexpected drain, manual release, provider-announced Stop without a terminal and normal completion followed by shutdown. Tests await persisted events or Deferred milestones without sleeps.
Validation on main
d81afa0a6f403bd6e5562ffcee2484089a1fdc3fand head0a115626b43ffba815df144d3066254ea9595e35:Replay remains a validation limit. A filtered replay attempt recorded a Pi
thread_rollback_after_stopfixture failure with the first run still starting, plus Windows EBUSY cleanup output, and was interrupted before a completed aggregate receipt. The parent isolated that Pi fixture in a worktree whose relevant runtime, Pi adapter and replay sources match pinned main; it failed with the same starting-run error. That worktree differs from main only in the unrelated OpenCode adapter and its tests. No replay success count is inferred, the full replay matrix was not run, and timeouts, skips and cleanup were not changed to hide failures.Current main's startup and interrupted-attach cleanup, idle unload, package moves and transactional finalization are preserved. Former external-launcher fixture helper corrections are now absorbed by main and no longer part of the diff. This PR does not add the separate attempt-ownership redesign or request-retirement changes. Shared server state serves web, desktop and mobile; no live client/provider verification or performance benchmark was run. Maintainer issue triage remains outstanding. CI must validate this new head.
Implemented and independently reviewed with GPT-6.1 Sol through the Codex harness.