fix(web): derive thread runtime phase from canonical turn state - #1772
Merged
Merged
Conversation
A half-open socket answers nothing and never fires close, so every recovery mechanism (reconnect, hydration, subscription replay) waited forever while the UI showed stale streaming state. A 30s interval now issues the existing app.version RPC with a 10s deadline; an unanswered probe closes the socket locally and the established onclose ladder owns recovery. agent.send gains a 20s timeout so a composer submit cannot park forever on a dead socket. The wedged-socket test now answers the liveness probe, since a socket that ignores it is exactly what the watchdog closes.
The reducer now writes routing.executionId onto the stored turn so clients can correlate a canonical turn to the local runtime without threading the event envelope through state. A payload-supplied executionId that disagrees with routing is rejected as a routing conflict.
Composer, project tree, and running-thread indicators now follow the canonical replica once a turn correlates by execution identity, so a dropped legacy terminal event can no longer strand runningThreadIds. The optimistic window before turnStarted and the finalizing phase stay on the legacy path until a canonical turn proves correlation. The narrative projection keeps its existing child-only lifecycle gate.
This was referenced Sep 27, 2026
…hase The runtime reconcile stamps runtimePhase from a correlated canonical turn but never correlated the record's execution identity, so a canonically owned "running" phase made getCanonicalLifecycleTurn treat the provider-owned child turn as a local execution and suppress its projection. A later terminal canonical event could then no longer clear the stamped phase either. reconcileCanonicalRuntime now stamps turnExecutionId from the claiming turn's executionId on live claims, and the lifecycle gate only treats runtimePhase as locally owned when the canonical runtime turn is not the latest turn.
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.
What
Stacked on #1771. Runtime state is now canonical-owned once correlation is proven.
AgentTurngains an optionalexecutionId; the reducer stamps it fromrouting.executionIdand rejects a payload value that disagrees, so snapshots and replayed history both carry the identity.getCanonicalRuntimeTurncorrelates the latest canonical turn torecord.turnExecutionId. A matching terminal clears stalerunning; a mismatch (older turn, or an optimistic send whoseturnStartedhas not landed) falls back to legacy.finalizingis never overridden.reconcileCanonicalRuntimesyncsruntimePhaseandrunningThreadIdsinside both canonical apply points (push events and reconnect recoveries), so composer, project tree, and everyrunningThreadIdsreader converge on the same truth.The narrative projection (
getCanonicalLifecycleTurn) keeps its child-only gate, so parent chat rendering is unchanged until the narrative migration lands.Why
Two writers owned the running flag. Legacy
agent.eventterminal events pass ownership guards that can silently drop them, leaving composer and tree saying "streaming" after the turn is done. Canonical turn status is persisted server-side with revisions and gap recovery, so it is the right authority.Evidence
src/__tests__/canonical-runtime-reconcile.test.ts: correlated terminal clears stale running, canonical running claims an idle record, optimistic window survives, mismatched identity is ignored, interrupted maps correctly.tsc --noEmitclean forapps/webandpackages/agent-model.Review notes
fix/ws-liveness-heartbeatand must retarget tomainafter PR 1 merges.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.