Repository navigation
fix: hand a message back as a pointer, not the body again - #780
neotechnet wants to merge 1 commit into
Conversation
A message that lands while a Bot is mid-work is delivered twice: the running turn reads it at its next step, then turn/end hands it back so the Bot can answer it in a turn of its own. Both hand-back loops re-sent the whole text (request.text in the joined loop, result.text in the later loop), and both of those come from a user/message event the model has already been shown in that Session. So the model read one message twice, under one exchangeId, with nothing anywhere to catch it. The hand-back keeps its identity: same exchangeId, same role, same sender, still deferred, so the sender still gets its answer and the ledger still records one send. It now carries a one-line pointer instead of the body. deliver takes a new handedBack flag and stamps source.handedBack on the delivery. exchangeText is the one reader that needs to tell the two apart, so it skips a delivery marked handedBack when it reads a message back from the Session for the exchanges dialog, which still shows the real text. test/handback.test.js covers a joined request, a reply handed back for other work, one body across the steer and the hand-back together, and a message to an idle Bot left untouched. Three of its four cases fail on the unpatched tree. Five existing assertions in test/bot-messages.test.js and test/group-work.test.js compared a hand-back against the full body; they now compare it against the pointer. The "name with brackets" case no longer had a body to check, so it proves what still holds: the bracketed sender name leaves a well-formed header. Co-Authored-By: Claude Code <noreply@anthropic.com>
Codex Review SummaryThis 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: c428983761
ℹ️ 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".
| toId: rt.selfOf(id), | ||
| sessionId: id, | ||
| text: request.text, | ||
| text: HANDED_BACK, |
There was a problem hiding this comment.
Preserve request bodies across Session switches
When a joined request crosses a Session switch, the destination Session is not guaranteed to contain its body: parts.js clips handoff history, and its job.bare recovery explicitly carries no previous messages (parts.js:894). In that recovery path, the full request enters the new Session only through handoffSource().joined metadata, which claimTrigger() restores for routing but never adds to model-visible content. Replacing request.text here therefore removes the delivery that previously supplied the pending instructions, leaving the answering turn with a false claim that they are above in this Session. Keep the stored body, or supply a concrete old-part lookup anchor, when the original delivery is absent from the destination context.
AGENTS.md reference: AGENTS.md:L14-L14
Useful? React with 👍 / 👎.
|
Field data in support of this change, from a real install (ds-bot 0.2.7 in
The counts come from |
|
One more data point on the cost, from a different angle: this hand-back is also how a single slow turn becomes four extra turns. In today's run (DS Bot 0.3.1, DSH Desktop, Windows), a member turn was wrongly marked So besides the duplicated body, the hand-back multiplies turns after a false |
There was a problem hiding this comment.
REQUEST_CHANGES — use the pointer only when the original body is actually present in the answering Session.
The handback/bot-message suites pass (44 tests), but I reproduced the missing-body case with the turn-host fixture: start a fresh part from a handoff source carrying a pending request only in joined metadata, as bare recovery does, then finish the resumed turn. The pending request is handed back as the generic pointer, so its actual instructions never reach the fresh model context. parts.js explicitly omits earlier messages for job.bare, and claimTrigger restores metadata for routing, not model-visible content. Preserve/replay the body across that boundary, or deliver a specific usable old-part reference; add a bare-recovery regression.
This is also still targeted at main. Unless this is explicitly being released as a hotfix, retarget to dev and merge current dev; the reviewed tree conflicts in delivery, turns and bot-message tests. Recheck the deferred-pointer path alongside #1682 so durable dedup does not suppress the continuation.
| toId: rt.selfOf(id), | ||
| sessionId: id, | ||
| text: request.text, | ||
| text: HANDED_BACK, |
There was a problem hiding this comment.
[P2] Retain the request body when joined work crosses a part switch. handoffSource().joined carries pending instructions into the fresh part as source metadata, but claimTrigger only restores it for routing. In bare recovery (parts.js, readLines), no previous message body is carried into model-visible content. A reproduced handoff with joined: [{info, text: 'Build the unique pending report with chart Z.'}] therefore sends only this pointer at turn end; the quoted instruction is never given to that model. Gate the pointer on the original context still being present, otherwise replay the stored body or provide an exact recoverable old-part anchor.
There was a problem hiding this comment.
New integration point since the last review: #1751 is now on dev. It hides internal delegated-work continuation turns while leaving user-facing answers visible. When porting the pointer behavior to dev, please preserve that distinction and use #1751’s visibility regression when checking the deferred-result path.
|
Thanks for the PR! A few blocking issues prevent merging as-is:
If you'd like to continue this, please retarget |
What happens
A message that arrives while a Bot is mid-work is delivered twice: once as a steer the
running turn reads at its next step, and again in full when that turn ends, so the Bot can
answer it in a turn of its own. The second delivery repeats the whole body, so the model
reads one message twice.
Root cause
Both hand-backs re-send the message text they were given:
src/host/turns.js(thejoinedloop at the end ofturn/end) deliverstext: request.textsrc/host/turns.js(thelaterloop, parked results) deliverstext: result.textBoth
request.textandresult.textcome from auser/messageevent the model hasalready been shown in that Session. Nothing catches it:
delivermints a freshexchangeIdwhen the caller does not pass one, and adeferreddelivery deliberatelyskips the ledger write, so there is no check anywhere for "this exchange is already in
this Session".
Measured on a real session before the change: one sender send, one ledger record, two
user/messageevents carrying the sameexchangeIdunder two different inbox item ids,the second 51 characters longer than the first. The 51 characters are the header
annotation; the body is byte-identical.
The change
The first showing is kept. The hand-back keeps its identity (same
exchangeId, samerole, same sender, stilldeferred) and carries a one-line pointer instead of the body:delivertakes a newhandedBackflag and stampssource.handedBack = trueon thedelivery, so anything that needs to tell a pointer from the message itself can. The one
place that does is
exchangeText, which reads a message back from the Session for theexchanges dialog: it now skips a delivery marked
handedBack, so the dialog still showsthe real text rather than the pointer.
Nothing else moves: the trigger, the ordering, the sender, the ledger shape, the Session
schema and the chat UI are unchanged. Every message still gets answered.
Test
test/handback.test.jsis new and was written before the change. On the unpatched treethree of its four cases fail, each on the body being re-sent; the fourth (a message to an
idle Bot, which was never read mid-turn) passes before and after, as it should.
Two existing tests asserted the old behaviour and were updated to the pointer: the four
sites in
test/bot-messages.test.jsand one intest/group-work.test.jsthat compared ahand-back against the full body. One of them, "a request from a name with brackets keeps
its body when replayed", no longer had a body to check, so it now proves what still holds:
the bracketed sender name leaves a well-formed header and the hand-back carries the
pointer.
Trade-off
The model answers from what it read earlier in the same Session rather than re-reading the
body. That is the intended path (the text is still above it, and the header names the
sender), but it is a behaviour change for a model that was relying on the second copy, so
it is worth watching the first few hand-backs after release.
joined[].textis now unused by the relay. It is left in place deliberately: the partswitch carries
joinedacross a handoff and the field is part of that payload, soremoving it is a separate change.