Repository navigation
fix(tots): report Completed only after awaited background work settles - #77
Merged
Merged
Conversation
A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run.
CarsonJF
added a commit
that referenced
this pull request
Nov 19, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
added a commit
that referenced
this pull request
Nov 20, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 20, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 21, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 21, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 21, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 21, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 22, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 22, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 22, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 22, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 22, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 22, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 23, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 23, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 23, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 23, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 24, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 24, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 24, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 24, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 25, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 25, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 25, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 25, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 25, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 25, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 25, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 25, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CarsonJF
added a commit
that referenced
this pull request
Nov 25, 2026
#77) A watched run that ended while its thread still held awaited background work was read as completed, so TotService woke the creating Tot with Completed: <thread> before the work was done. The nightly repair paid for four of those wake-ups. Read such a shell as waiting, reusing backgroundWorkHoldsCompletion, the same rule the MCP thread status uses. The watch then survives to the real settle and reports Completed exactly once. Questions, approvals and failed runs still report as before. Remote followers keep the old timing: a forwarded thread wait exposes the run status but not pending background tasks, so it cannot tell awaited work from a finished run. Co-authored-by: OpenCode <opencode@local>
CarsonJF
pushed a commit
that referenced
this pull request
Nov 25, 2026
#77 made a completed run that still holds awaited work read as waiting, but the watcher only looked at a thread on run, request and thread events, so it never looked again when the work ended: the Tot got no Completed, or a silent end when the thread later settled. It now also looks on the events ThreadSettlementService treats as work ending (provider-thread, turn-item and subagent updates that end work, and cancelled background work). A sent watch whose run was passed by a later run, such as the wake the finished work starts, now ends instead of leaking, and reports Completed when that run was waiting on work. Idle-compaction runs no longer wake watching Tots with a Completed of their own. The new tests drive the real domain-event stream instead of calling observe directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
A Tot that launched a thread was woken with
Completed: <thread>when the thread's run ended but the thread still heldpendingBackgroundTaskswith awaited work (a background shell or delegated task). During the nightly repair this produced four spurious wakes, each a full context reload, while the work was still running.Change
watchedStateFromShellnow reads acompletedshell that still holds awaited background work aswaiting, usingbackgroundWorkHoldsCompletion— the same rulethreadStatusalready uses inOrchestratorMcpService.watchTransitiontherefore emits nocompletedevent at that moment; the watch survives to the real settle and reportsCompletedexactly once. Question, approval, failed, and ended reports are unchanged, and the tests pin that down.Remote followers in
TotWatchService.followare unchanged: the forwardedt3_thread_waitresult carries the run's status but no pending background tasks, so it cannot distinguish awaited work from a finished run. That limitation is recorded indocs/internals/tots.md.The
sent/watchReportsdelivery policy intotWatchReports.tsis untouched.Scope
Small regression fix for an obvious bug found during the nightly repair; no issue filed. Requested by Carson.
Verification
vp test run apps/server/src/tots/TotWatchService.test.ts apps/server/src/tots/totWatchTransitions.test.ts→ 2 files, 29 tests passed.Completed, with a second flush adding none; question then approval while awaited work holds → both reported, thenCompletedon settle; failed run with awaited work →Failed.TotWatchService.tsreverted toorigin/custom, the three new awaited-work cases fail (a spuriousCompletedis emitted and the finalCompletedis missing); they pass with the fix.vp run check:changed origin/custom→ pass format, lint, knip 1/2 and 2/2, graphql, typecheck (3 packages), tests (2 files, 22 passed).vp run check:changedcomparescustomagainst upstreammain, so it ran the whole fork's diff and hit 16 timeouts inapps/webbrowser tests. This branch changes noapps/webfile — its diff againstorigin/customis only the two Tot watch files and one docs line — so those tests run on code identical to untouchedcustomand are unrelated.Agent: OpenCode harness, model
opencode/deepseek-v4.1-flash-free.