fix(turns): carry the asked question into a rebuilt prompt - #365
Open
haiderysfzi wants to merge 2 commits into
Open
haiderysfzi wants to merge 2 commits into
haiderysfzi wants to merge 2 commits into
Conversation
A <facility-needs-attention> question is stripped from the agent's message and kept only on the attention item, so a prompt rebuilt for an agent without a native session showed the human's reply with nothing it answered. Closes theam#344.
adrian-lorenzo
approved these changes
Sep 14, 2026
adrian-lorenzo
left a comment
Member
There was a problem hiding this comment.
Thanks for fixing this.
The change restores the missing context in #344, and the regression test covers the handoff well. I verified the fix and found no blocking issues.
Contributor
Author
Thanks for the review! Let me know if you'd like any changes before merge, or if there's a next issue to grab. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
A prompt rebuilt for an agent with no native session now carries the
<facility-needs-attention>question that the human's reply is answering. Thequestion is rendered against the agent message that asked it, so the transcript
reads question then answer.
Why
Closes #344.
agentOutcome(dispatcher.ts:669-674) strips the question out of the output, andcompleteTurnpersists only the stripped body, so the question survives on theattention item alone.
buildPromptbuilds its transcript purely fromstory_messages. An engine resuming its own native session still holds thequestion in context, which is why this is invisible on the common path. When the
reply goes to a different agent, the session lookup keys on
agentName + engine + model(dispatcher.ts:169-177), no session matches, and therebuilt prompt is all the agent gets:
No, continue.with nothing it answers.Two details are worth naming, because both are easy to get wrong.
Attention status is deliberately not filtered. Dispatch resolves the item as
repliedatdispatcher.ts:100-107, before the prompt is built, so anstatus === "open"filter would drop precisely the question being answered.The question is placed on the agent message only. Both the user and the agent
message of a turn carry that turn's
turnId(stories/service.ts:367), so keyingon
turnIdalone renders the question twice and once in the wrong place.Only
agent_waitingitems are rendered;queued_turn_dispatch_erroris anoperational failure rather than a question. Details are already redacted at write
time via
redactString, so nothing new is exposed.Verification
New integration test: a builder asks a question, the reply is routed to a
different agent, and the rebuilt prompt is asserted to contain the question, the
answer, the question exactly once, and in that order. It also asserts
nativeSessionIdis undefined, so the test fails rather than silently passing ifthe fresh-session premise ever stops holding.
Mutating
dispatcher.tson this branch, runningturn-dispatcher.integration.test.ts:status === "open"role === "agent"guard (question renders twice)Each mutation is caught only by the new test, so the assertion is load-bearing
rather than incidental. The middle row is the one the existing suite could never
have caught.
Full runs,
services/api, split across the databases the suite expects:facility_test(all but the e2e journey): 43 files passed, 407 tests.facility_ws(facility-012.e2e.integration.test.ts): 2/2, exit 0.pnpm verify: exit 0. Guards 2/2, audit clean against the ignore list.One pre-existing failure,
test/oauth.test.ts(500on dev login), is unrelatedand reproduces without this change. Same command, same freshly created database,
this branch stashed:
maingives 406 passed with that same single failure, thisbranch 407 with the same single failure. The delta is exactly the one added test.
Note for @Yeeway69
The reproducer in the issue asserts a sha256 of
dispatcher.tsto pin therevision, and the file has changed since
c14bc6d(inb2a9b47), so the scriptnow aborts on that assertion rather than running. The defect itself was untouched
by that commit and reproduces on current
main. Thanks for isolating the seam soprecisely, it made this a small change.