Repository navigation
Deduplicate member reply and failure notice delivery across steered follow-ups and part switches - #1682
Conversation
…ollow-ups and part switches When a member Bot turn was joined mid-turn by steered message_bot follow-ups and failed (e.g. INVALID_REQUEST with a request_id), turn/end called answerSender once for the primary request and once per joined request, pushing duplicate failure notices with the same request_id into the sender's nextTurn queue. In long conversations that switched parts (or reconciled ended/inflight turns on reload), reconcileEnded only checked the sender's current session log rather than earlier thread segments or the pair delivery ledger, and resumeAll did not inspect whether the session log or pair ledger already recorded a terminal turn before re-running. - Record failureRequestId on delivered pair-ledger entries and expose wasReplyDelivered / wasFailureRequestDelivered helpers in delivery.js - Add sameConversation in threads.js to compare sender conversation identity across thread part switches while keeping parallel openParts and rooms isolated - Make answerSender idempotent per (from, to, exchangeId), per (from, to, conversation, failureRequestId), and per turn/end pass, while settling open works on suppressed duplicates so parent handoffs never hang - Check the pair delivery ledger and earlier thread segments in reconcileEnded and check terminal session logs + pair ledger in resumeAll before re-delivering or re-running
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06f63c9cc9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const parent = rt.closeWork?.(exchangeId, name, text) | ||
| if (parent !== undefined) rt.takenWork?.(parent, exchangeId) |
There was a problem hiding this comment.
Preserve continuation delivery for distinct parent works
When the same caller conversation sends requests for two different parent works into a member's running turn, a failure suppresses the second reply even though the first reply carries only the first parent's work. Here, closeWork records the second parent's result and takenWork removes its outstanding child, but neither schedules a continuation. In turns.js, that continuation normally comes from consuming the reply carrying source.work; consequently, the second parent can remain held indefinitely without answering its upstream requester. Restrict suppression to requests sharing the primary parent, or explicitly schedule settlement of every distinct suppressed parent instead of marking its result taken without a delivery.
Useful? React with 👍 / 👎.
… resume Prevent distinct parent works from stalling when steered into the same failed turn, and fix restart reconciliation for continuation turns: - Scope in-memory and ledger failure deduplication in answerSender by parent work and require the primary child to still be pending in parent.open before coalescing a second child's failure. - Settle steered child requests from distinct parent works in reconcileEnded as well. - In resumeAll, resolve role=reply continuation triggers via rt.workOf(trigger) and the upstream asker rather than the child reply's exchangeId and senderSessionId. - Clear stale child parent pointers in dropWork. Fixes #1319.
Keep task handoffs intact while recovering already-ended turns. Restore full attachment-backed results when reconciling delivered replies.
Recovery reads the original attachment, but delivery may add a warning only to its preview. Restore that prefix without duplicating the preview.
Do not finalize a recovered task until its queued input can reach that task rather than the foreground chat.
Fei2411
left a comment
There was a problem hiding this comment.
Code Reaper review (comments only) — head 61b5fbe
Verdict: close to ready. One P2 recovery gap worth fixing in this PR (or explicitly deferring to a follow-up issue); everything else checks out.
Conflict resolution with dev (merge 2a367e75): both sides kept. delivery.js keeps #1892's taskId/imOrigin and background-task headers alongside failureRequestId and durable dedupe; threads.js keeps task-aware lookup, part switching and successor routing (sameConversation uses the task-aware lookup); resume.js keeps task routing, replay destinations, keepTaskSessions and restart task reconciliation next to the new terminal-log settlement. Nothing from #1892 dropped. Earlier merges 276d8711, e4d6f606 had no conflict edits in these files.
P2 — completed-turn recovery can strand a steered request (ds-bot/src/host/resume.js ~453–475, 597–599)
Joined (steered) requests are enumerated only in the error/aborted branch. For a completed terminal turn/end, resumeAll now settles the primary request and skips resumeTurn, but never requeues or settles requests the turn joined.
Scenario: A sends B req-1 and req-2 (independent parents p1/p2); B consumes both, turn/end completed reaches disk, host stops before the live handler defers req-2. After restart, req-1 is settled, req-2 stays open with nothing to run it. Reproduced by switching the existing restart fixture's failed turn to completed:
caller replies: [ 'req-1' ]
member followups: []
req-2 still open: true
parent-2 open: [ 'req-2' ]
Caveat: dev's reconcileEnded has the same gap for successful joined requests, but this PR's new shortcut is what reaches it on cold restart. Suggested fix: in the completed branch, defer/requeue joined requests the same way turns.js does on live completion, plus a test.
Other checks: in-memory guards are capped (1,000) and per-runtime; failure suppression is scoped by conversation and live parent work; late replies after abandonWork still go through. Earlier Codex/Devin Review findings (parent-scoped continuations, attachment full text + warnings, unread task replies on restart) are addressed with tests.
Local: npm test 3505 pass / 0 fail / 4 skipped; build-client --check clean; npm run lint passes.
Overlaps (open PRs touching turns/delivery/threads/resume): #1855, #1817, #1201, #1074, #780 all conflict textually; none is the same fix (#780 changes deferred-message payloads, not reply/failure idempotency). This PR is green and mergeable, so it should land first and those rebase onto it.
Agent: Devin (Cognition)
|
Code Reaper’s completed-turn steering finding is tracked in #1946. The successful-turn recovery gap also exists in |
Fixed on current head 61b5fbe. Distinct parent works each receive a continuation; live and restart regression tests pass. The review thread is resolved and the current Devin Review has no findings.
Fei2411
left a comment
There was a problem hiding this comment.
Code Reaper re-review (comments only) — head 61b5fbe
Verdict: pass. Ready for lulu.
The head is the same commit I reviewed before, so my earlier findings still hold. The merge with dev kept both sides, including #1892's task handoffs. The earlier review findings are fixed, and tests, --check and lint pass. The one P2 (recovery after a restart can strand a steered request when the turn it joined had already completed, in resume.js) is now tracked in #1946. The same gap already exists in dev's reconcileEnded, so deferring it is reasonable. CI on this head is green and the PR merges cleanly.
Land order: this PR first. #1855, #1817, #1201, #1074 and #780 conflict with it as text, so they need to be updated on top of it.
Agent: Devin (Cognition)
Issue
Fixes #1319
What changed / 改了什么
request_id(turns.js,delivery.js,threads.js): When a member Bot turn was joined mid-turn by steeredmessage_botfollow-ups (entry.joined) and ended with a model error carrying arequestId(such asINVALID_REQUEST),turn/endpreviously invokedanswerSenderfor both the primary request and every joined request. That queued multiple identical[Reply from ...]failure notices with the samerequest_idinto the caller'snextTurnqueue, causing the Main Bot to receive the same failure again on its next turn after already acting on the first notice.answerSendernow deduplicates failure notices by(fromId, toId, conversation, failureRequestId)(and perturn/endpass) while settling open works for suppressed duplicates so parent handoff accounting (work.open/takenWork) never hangs.turns.js,delivery.js,resume.js,threads.js):answerSendernow checks both an in-memory delivery set and the durablepairBookledger (wasReplyDelivered(fromId, toId, exchangeId)) before queueing a reply, while still allowing late replies afterabandonWork(work.abandoned && !work.lateReplySent) when no reply was previously delivered.reconcileEndedpreviously only checkedlogOf(where)(the recipient's current active part). In long conversations (500+messages) where the Main Bot switched parts (moveOn/pushThreadPart) after receiving a reply or failure notice in an earlier part,answeredInmissed the earlier delivery and re-delivered the reply verbatim.reconcileEndednow checkswasReplyDelivered, the target part, and earlier segments of the recipient's thread.resumeAllnow checks whether the session log already recorded a terminalturn/end(completed,error, or non-disposedaborted) or whether the reply is already inpairBookbefore callingresumeTurn, preventing already-finished turns from being re-executed on reload.devafter feat(bot-tasks): auto-move busy foreground to background and spawn peer tasks (#783) #1892, preserving task routing. On restart, pending replies stay with their background task, and recovered attachment-backed replies include the full answer and any delivery warning.Changelog
Bots no longer repeat the same delivery failure in one conversation; unread replies still reach the right background task after a restart.
How I checked it / 怎么验证的
npm test(3,505 passed, 4 skipped)node scripts/build-client.mjs --checknpm run lintMock bench smoke test (56 steps)
Leak scan
Added
ds-bot/test/delivery-dedup.test.jscovering:INVALID_REQUEST(request_id) deliver only one failure notice to the caller conversation and settle open works cleanly.openPartsstill notify each independent conversation once perrequest_id.answerSenderidempotency perexchangeIdand perfailure.requestId, while preserving late replies afterabandonWork.reconcileEndedacross recipient part switches (pushThreadPart) does not re-deliver replies orrequest_idfailures already delivered in an earlier part.resumeAllsettles already-ended turns from disk without re-running the model or duplicating replies.Checklist / 检查
Co-authored-by.Agent: Devin (Cognition)
Link to Devin session: https://app.devin.ai/sessions/23347c537bbb4ec18f2f91c0e5076d7f
Link to Bot: https://app.devin.ai/org/feizhululu/bots/66f2a751b4f84ea6896e40b044f19644
Open in Devin Desktop: https://app.devin.ai/desktop/session/23347c537bbb4ec18f2f91c0e5076d7f?variant=devin