Repository navigation
fix(chat): reconnect after a question pending across a restart - #7919
Conversation
🏆 Review leaderboardOct 31, 2026–Nov 7, 2026 · UTC
Ranked by distinct external PRs reviewed, then review rounds, then PR comments. Self-activity and bot activity are excluded. Show 8 more reviewers
|
Meraj-08
left a comment
There was a problem hiding this comment.
Thanks for digging into this. I ran #7658's exact question call on real OpenCode 2.2.5 through the daemon and the desktop app, on main and on this branch, and the stuck state comes from somewhere else.
[P1] The stuck question comes from a replay collision, not a missing turn link. With the question pending, I restarted the daemon and let the surviving chat host reconnect. The replayed input.requested fails with UNIQUE constraint failed: conversation_activities.conversation_id, conversation_activities.request_id and the projection stops, so the turn stays running, resolving the input returns CHAT_CONTROLLER_NOT_READY, and Resume agent hits the same error again. It happens the same way on b3f658811e. UpsertActivity only matches an existing row by ProviderItemID, and a question carries only a RequestID, so the replay inserts a second row. In every run, including both restarts, the original row was linked to the running turn. Details are in #7944. Could the fix make the replayed request update the existing row by request_id instead?
[P2] The dock change only affects the case where no turn is running. On main, latestPendingInteraction already docks a question with no turn link while a turn runs, and the new ChatWorkspace test passes against main's component unchanged. The only behavior this changes is docking such a question when nothing is running, which could show a stale question whose answer has nowhere to go. Could the description and the doc comment say which case this is for, with a test that fails on main?
The chat host replays a pending interaction after the daemon reconnects, and an elicited question reaches UpsertActivity with only its request id. UpsertActivity matched existing rows by provider item id alone, so the replay went to insert and hit the (conversation_id, request_id) index. The controller treats a failed projection as fatal: it stops with the provider retained for replay, the turn stays running, resolving the question returns CHAT_CONTROLLER_NOT_READY, and every retry - including Resume agent - replays into the same wall (OrchestratorInc#7944). A replay now refreshes the row already stored for that request id. A pending or failed row is brought back up to date: a failed row is a question the previous controller's death stranded, and the replayed request is live again. A resolved row is left alone, so a late replay cannot reopen an answered question. Fixes OrchestratorInc#7944
b3f6588 to
55f43d0
Compare
|
Thank you — this review found the real mechanism, and the PR is reworked around it. Both points addressed, plus one correction on my side. P1 — done as requested. P2 — reverted. You were right and I had the condition backwards: Description rewritten accordingly (mechanism, fix, and the two dropped approaches). |
Meraj-08
left a comment
There was a problem hiding this comment.
Re-tested 55f43d0dd5 on real OpenCode 2.2.5 through the daemon against main at 5cde191aad. With a question pending, a hard daemon kill and an ao stop/start now both reconnect within 5 seconds, the answer returns 204 and the turn completes, where main stops on the unique constraint every time. One P2 on the failed-row path.
settleOrphanedWork fails a pending question and its turn in the same pass, so the replay guard (status <> resolved) turned that row back to pending on a failed turn - a pending question latestPendingInteraction never docks, invisible to the user. Only an in-flight row (pending/running) is refreshed now, so a replay cannot reopen any settled question: answered (resolved), failed, cancelled, or completed. Covers the failed case with a test. Addresses the review P2 on PR OrchestratorInc#7919.
Meraj-08
left a comment
There was a problem hiding this comment.
LGTM. Reviewed through 89922c542d: with a question pending, both a killed daemon and ao stop/start now reconnect within 5s, the answer returns 204, and the agent continues, where main stops the projection on the duplicate insert.
One non-blocking note: the description still says a pending or failed row is refreshed, but the second commit narrows that to pending and running rows. Could the description match? Fine as a follow-up.
|
Done - the description now matches the second commit: only pending/running rows refresh, and settled rows (resolved, failed, cancelled, completed) stay settled, with the failed-turn rationale spelled out. Counts recalculated for the three-commit diff; golangci-lint still 0 issues. |
…stratorInc#7919) * fix(chat): reconnect after a question pending across a restart The chat host replays a pending interaction after the daemon reconnects, and an elicited question reaches UpsertActivity with only its request id. UpsertActivity matched existing rows by provider item id alone, so the replay went to insert and hit the (conversation_id, request_id) index. The controller treats a failed projection as fatal: it stops with the provider retained for replay, the turn stays running, resolving the question returns CHAT_CONTROLLER_NOT_READY, and every retry - including Resume agent - replays into the same wall (OrchestratorInc#7944). A replay now refreshes the row already stored for that request id. A pending or failed row is brought back up to date: a failed row is a question the previous controller's death stranded, and the replayed request is live again. A resolved row is left alone, so a late replay cannot reopen an answered question. Fixes OrchestratorInc#7944 * fix(chat): do not reopen a failed question when the chat host replays it settleOrphanedWork fails a pending question and its turn in the same pass, so the replay guard (status <> resolved) turned that row back to pending on a failed turn - a pending question latestPendingInteraction never docks, invisible to the user. Only an in-flight row (pending/running) is refreshed now, so a replay cannot reopen any settled question: answered (resolved), failed, cancelled, or completed. Covers the failed case with a test. Addresses the review P2 on PR OrchestratorInc#7919. (cherry picked from commit 32fd8d2)
Code changes: +53 -0
Tests: +100 -0
Others: +73 -0 (generated sqlc)
Fixes #7944. Surfaced by #7658; that report's no-card symptom is not reproduced by this change (see the review discussion).
What was wrong
The chat host survives a daemon restart and replays its pending requests. An elicited question reaches
UpsertActivitywith only itsRequestID— it has noProviderItemID— andUpsertActivitymatched existing rows by provider item id alone. The replay therefore went to insert and hit the partial unique index onconversation_activities (conversation_id, request_id). The controller treats a failed projection as fatal: it stops with the provider retained for replay, the turn staysrunning, resolving the question returnsCHAT_CONTROLLER_NOT_READY, and every retry — including Resume agent — replays into the same wall (#7944).The fix
A replay now refreshes the row AO already stored for that request id, in
UpsertActivity:request_idwhen the activity carries no provider item, and settle that row instead of inserting a duplicate;pendingorrunning) is brought up to date;resolvedrow (an answered question), and equally afailedone —settleOrphanedWorkfails a stranded question together with its turn, and reviving it would park a pending question on a failed turn, one the dock never shows.Approaches explored and dropped after review:
ActivateLiveReconnectinstalls the turn correlation before the replay gate opens, and the stored row is already linked to the running turn in every observed run.mainalready docks a turn-less pending question while a turn runs (the: !turnbranch of the skip condition is false when a turn exists), and docking one while nothing runs would surface stale questions.Tests
TestUpsertActivityReplayRefreshesTheStoredQuestionInsteadOfColliding— a replayedinput.requestedlands on the stored row (fails onmainwith exactlyUNIQUE constraint failed: conversation_activities.conversation_id, conversation_activities.request_id, verified on pristinemain), stays pending, and a late replay after the user answered keeps the row resolved.TestUpsertActivityReplayDoesNotReopenAFailedQuestion— afterFailPendingInputs(thesettleOrphanedWorkpath: row and turn fail in the same pass), a replay keeps the row failed instead of reviving it to a pending question on a failed turn.Validation
go test ./internal/storage/sqlite/store/green, including both new tests; focusedinternal/service/chatfailures are pre-existing Windows-environment issues (drive-lettermkdirsyntax, symlink privilege, POSIX file mode) and reproduce identically on pristinemain.0 issuesfor./internal/storage/sqlite/....npm run sqlcregenerated; the committedgen/output matches (CI sqlc-drift validates).