fix(coding-agent): refuse sync dequeue/edit of a durable queued input (#4087)
Fixes #4087.
What changed
dequeueQueuedInput/editQueuedInputno longer change an input the pending-input store owns: when the copy is still queued they answerconflictand leave the queue, the record and the native queue untouched; a drained durable copy still answersalready_delivered. Change a durable copy through the store-backedchangeQueuedInputinstead.- The guard runs before the still-queued probe on purpose: the probe itself removes/replaces the native message, so a refused change checked after it would still lose or rewrite the copy. The guard reads the native queue non-destructively (
peekQueuedMessages). SessionPendingInputs.hasAdmitted(clientMessageId)exposes the sync read the guard needs. Inputs the store never admitted (no client id, or a restored input whose store never opened) keep the legacy sync answers.
Why
#4087 was filed against the pre-#3549 layout, so I re-derived it on current main: the held-copy accessors and the UncertainJournal fixture are gone, the L-c2 recovery-callback loop no longer exists, and the L-c1 edit-after-landed-reservation case is already refused by reduceMutation (covered by pending-input.test.ts). What is still live is the still-queued shape: a sync dequeue/edit mutated the queue without writing any record, the record stayed queued, and a reopen re-queued the input (restoreQueuedInput re-enqueues anything the record did not retire).
Evidence (RED -> GREEN)
- New
test/suite/regressions/4087-sync-change-durable-held-copy.test.ts: RED on unmodified code (sync dequeue answeredremoved, sync edit answerededited), GREEN after the fix — 3/3 passed. The first GREEN attempt caught a real second defect (the probe itself mutated the native queue), fixed by moving the guard before the probe; the tests then passed. - Neighbouring suites after the fix:
pending-input-session,pending-input-store,pending-input,pending-input-session-port,pending-input-delivery,1971-queued-input-dequeue-edit,3459-queued-input-expected-revision,3863-queued-person-input— 110 passed, 2 failed. The 2 failures are both inrpc-pending-inputs.test.tsand are environmental: the tests spawn the built CLI host and this checkout'sdist/is a stale partial build (dist/valid-cwd.jsmissing,ERR_MODULE_NOT_FOUND), unrelated to this diff. bun run check(lint, fmt, ratchet, pinned-deps, ts-imports, tsc --noEmit, browser smoke): exit 0, no type errors.
Notes
- The change fragment (
changes/unreleased/<this PR>.md) follows in a second commit once this PR has its number. - CLA: to be signed by the user (Chao Chen) if required for this repo.
Summary by cubic
Synchronous dequeue and edit could change a queued input without updating its durable record, causing it to reappear after a session reopened. They now return conflict and leave the queue untouched; change durable inputs through changeQueuedInput.
Inputs the store has not admitted retain the existing synchronous behavior, and drained inputs still return already_delivered.