Skip to content

fix(server): auto-settle skips held queued user messages - #48435

Closed
TuanNancy wants to merge 1 commit into
pingdotgg:mainfrom
TuanNancy:fix/auto-settle-held-queued-message
Closed

TuanNancy wants to merge 1 commit into
pingdotgg:mainfrom
TuanNancy:fix/auto-settle-held-queued-message

Conversation

@TuanNancy

Copy link
Copy Markdown
Contributor

Problem

Fixes #48419.

ThreadSettlementService.sweep builds candidates from getSettlementCandidates. A thread can keep a user-created message held in its queue after the preceding run fails, but the orchestrator rejects thread.settle with:

Thread <id> has a queued message. Send it or remove it from the queue before settling.

The settlement query only inferred a queued turn from recent timestamps, so after the grace window the same idle thread stayed a candidate and the sweep kept dispatching thread.auto-settle. The issue's trace shows 24 rejections in about 40 minutes on one thread.

Fix

getSettlementCandidates now excludes a thread when it has a queued run whose user message is user-created and not an automatic wake (scheduled task, notification, or delegated completion). This mirrors the orchestrator's queuedMessageExists check. Automatic queued wakes still remain settlement candidates.

Verification

  • Added a regression test in apps/server/src/orchestration-v2/ProjectionSettlement.test.ts that creates a failed run plus a held user-created queued message, and an agent-created automatic queued message.
  • On the base commit the new test fails with expected true to be false (the held thread is a candidate). With the fix it passes and the automatic thread remains a candidate.
  • Full ProjectionSettlement.test.ts: 11/11 pass.
  • vp run check:changed: format, lint, knip, and typecheck pass. The changed-file test run also hits a pre-existing ProjectionStore.test.ts failure (statement.stat is not a function) that reproduces on a clean origin/main worktree, so it is unrelated to this change.

Model: DeepSeek V4.1 Flash 1017
Harness: OpenCode

The settlement sweep kept dispatching thread.auto-settle for threads whose queued user message the orchestrator refuses to settle, repeating the same failed command every minute. Exclude a thread with a held user-created queued message from the settlement candidates, matching the orchestrator's queuedMessageExists check; automatic wakes still settle.
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Dec 3, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 736f897

Macroscope's review found this PR approvable — The settlement sweep now skips threads containing queued user messages instead of repeatedly attempting settlement. This is a narrow query filter with no new data mutations or changes to product defaults.

You can add or adjust custom eligibility rules. Learn more.

@juliusmarminge

Copy link
Copy Markdown
Member

Thanks for this. #48436 makes the same change and is the one being kept.

Thanks for the work on #48435. The same fix is already covered more completely by #48436, which exposes the queued-user-message state on settlement candidates and applies the exclusion in isAutoSettlementCandidate at the sweep decision point.

That version also updates the existing automatic-queue fixture and adds a focused failed-run regression, so automatic wakes remain candidates while held user messages are skipped. Please keep the reproduction and regression coverage from this PR in mind, but #48436 is the better change to continue with.

Closing as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Idle threads with a held user message repeatedly fail auto-settle

2 participants