Repository navigation
fix(server): auto-settle sweep skips threads holding a queued user message - #48436
juliusmarminge wants to merge 2 commits into
Conversation
…essage Reproduces #48419: the sweep treats a failed thread holding a queued user message as a settlement candidate, while thread.auto-settle rejects it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ssage The sweep treated an old or failed-thread queued message as no obstacle, while thread.settle rejects any thread whose queue holds a message the user sent. The sweep then dispatched a doomed thread.auto-settle every minute. Settlement candidates now carry whether a queued run waits on a non-automatic message, using the same rule as thread.settle, and isAutoSettlementCandidate skips those threads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — The automatic settlement sweep now skips threads holding queued user messages, matching the existing settlement guard. This is a narrow filtering change with no new destructive behavior or changed product defaults. You can add or adjust custom eligibility rules. Learn more. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
The automated pipeline stopped on this pull request and will not merge it: the fix is written and reviewed, but proving it needs something no worker has:
It stays open for a person to finish or close. |
Every minute, the auto-settle sweep tried to settle threads that had a message the user sent waiting in their queue. The server always refused, so it logged a 'has a queued message' error each minute and the thread never settled. The sweep now skips those threads, using the same rule the settle command uses.
getSettlementCandidatesreportshasQueuedUserMessagewhen a queued run waits on a message that is not automatic (not one sent by an agent, a scheduled task, a notification or a delegated completion).isAutoSettlementCandidateskips threads with that flag set.Fixes #48419
Reproduction on main
Commit origin/main 9ba2879. Ran the real server from source:
T3CODE_DEV_SEED=0 node --import <clock-shift preload> apps/server/src/bin.ts serve --base-dir <scratch> --port 13919 --dev-url .... The preload only adds an offset from a file to Date.now / new Date(), so the clock could jump past the 7-day threshold. Default settings were used (sidebarAutoSettleAfterDays = 7). Added a scratch git repo as a project witht3 project add. Over the app's WS RPC (orchestration.dispatchCommand, the same client path the scenarios use), created a thread as a user on the built-inReplay (dev)provider (model bench-stream) and sent message 1 with start_immediately. While that run was streaming, sent a second user message with queue_after_active. Then killed the replay agent process (a child of my server, PID captured from the server's child list), so run 1 endedfailed. The DB then showed run 1 = failed and run 2 = queued with queueHeld=1, which is the reporter's state. Set the clock offset to +8 days. server.trace.ndjson then logged onethread.auto-settle(command id server:auto-settle::) per one-minute ThreadSettlementServiceV2.sweep, at 20:30:40, 20:31:40, 20:32:40 and 20:33:40 shifted time. Each one ended inOrchestratorDispatchError: Failed to dispatch orchestration command thread.settle ... Thread <id> has a queued message. Send it or remove it from the queue before settling.(Orchestrator.ts:4972). settledAt stayed null. Control run: the same setup with messages sent through thet3 threadCLI (an MCP sender, so the queued message counts as automatic) auto-settled successfully on the first sweep, so the loop only happens when a user-sent message is queued. Failing test on branch factory/repro-48419 (d75ee4d): apps/server/src/orchestration-v2/ProjectionSettlement.test.ts, 'sql: a failed thread holding a queued user message is not a settlement candidate'. It builds a failed run plus a held queued run for a user message, and isAutoSettlementCandidate returns true on main.Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/orchestration-v2/ProjectionSettlement.test.tsbefore the fix (with the repro test): 1 failed, 10 passedvp test run src/orchestration-v2/ProjectionSettlement.test.ts src/orchestration-v2/ThreadSettlementService.test.tsafter the fix: 68 passedvp run typecheck(apps/server): no errors (only existing suggestions)vp run check:changed: knip, graphql, typecheck (3 packages), test (4 files) all pass; the pre-commit fmt and lint also passedNot in this change
threadHasQueuedTurnStartstill ignores queued messages on failed threads and messages older than the grace period; it is also used by storageCleanup, so it was left unchanged.OrchestrationV2ThreadShell) has no queued-message field, soisAutoSettlementCandidaterun on a shell cannot see this obstacle; only the server sweep uses it.Who did the work
Run by the t3code factory in T3 Code.