Chat: the answer after a reply's last tool shows when its deltas didn't arrive (bugfix) #550
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #550"
general
weight: 0.35
Giton22
What and why
A reply that runs tools and then answers can lose that answer in Kyllene. The text before and between the tools shows, but the response after the last tool doesn't, when its
message.deltaframes never reach the app. This happens with a non-streaming provider, deltas that fall in a gap the replay ring can't fill, or a turn that ends while the chat is out of sight. The gateway sends that response again inmessage.completetext, but Kyllene threw it away.Fixes #546
Cause:
ChatReducer.kt:234(on master) istext = base.text.ifBlank { finalText }. It uses the completion text only when nothing streamed at all. Once any earlier segment has streamed, the final response frommessage.completeis dropped.Fix: follows what
message.completetextmeans in hermes-agent. From v0.22.0 to v0.23.4 it is the last model response, the text after the last tool (_turn_outcomeintui_gateway/prompt_turn.py; on the session authority, the settledresponse). Hermes Desktop merges it the same way, as the current response after the last tool row.ChatState.responseStartrecords where the running reply's current response begins. It is set attool.start, at a non-streamedmessage.interim, and when a reply opens. It is cleared when the turn ends.completeturn,withFinalResponsemerges the completion text into that current response:- Already streamed: stays as it is.
- Partly streamed: completed.
- Didn't stream: appended after the earlier segments, so it shows once.
-
response_previewed/response_reused: not added a second time.-
response_transformed: replaces what streamed of it.- A cumulative final that repeats the earlier segments: only the new part is added.
- With no known boundary (a reply rebuilt from history, or v0.22.0's shape with no segment stamps): still added only once, as the last paragraph.
interruptedorerrorkeep today's behaviour, because their text can be the whole reply kept so far.Gateway
No new or changed calls. It reads
message.completetextand theresponse_previewed/response_reused/response_transformedflags. Those flags are optional, and when they're missing the text is compared directly.How I tested it
Unit tests (
shared/core/src/commonTest/.../chat/)FinalReplyAfterToolsTest(new, 19 tests): the original repro (2 of its first 5 tests failed on master), plus reducer cases for:- streamed and interim segments followed by a final that came only in
message.complete- partly streamed, reused, previewed, transformed and cumulative finals
- a silence marker the delivery dropped
- the v0.22.0 shape with no segment stamps
- the authority shape: an empty completion keeps what streamed, and a final that didn't stream shows
- stopped and failed turns keep what streamed
- a turn with no tools that streamed nothing
- a reply rebuilt with no boundary
- a boundary past the end of the text is clamped
- captured v0.23.4 Bot Chat frames and rows
ChatSessionResumeTest(legacy,FakeTransport):-
aFinalWhoseDeltasFellInAGapTheRingCantFillStillShows-
aFinalMissedWhileOutOfSightShowsWhenTheTurnEnds: resync withevents.sincetruncated.ReplayGapTest.aFinalLostInTheGapShowsOnceWhenOurTurnEnds(authority,replay_gapthen a history reload): checks that the final shows exactly once, not twice.ChatSessiontests and the original repros. With the fix they all pass.:desktopApp:compileKotlinJvm, is green on the rebased branch. That includes 1616:shared:core:testAndroidHostTesttests with 0 failures.:shared:core:jvmTest(not CI) has one failure on Windows:LinuxClientCertificatesTest, a POSIX file-permission test. It is unrelated, and it fails on master on Windows too.On a device: version matrix
- Emulator, Kyllene Dev, Bot Chat on a named profile.
- A local test gateway with a fake model that writes text, runs a tool, writes more text, runs a second tool, then gives the final answer.
- A test-only proxy between the app and the gateway drops every
message.deltaafter the turn's 2nd tool (tool.complete, ortool.generatingon versions that send only that) and renumbersseq, so the app sees no gap. The final answer then arrives only inmessage.complete.| Hermes Agent | Mode | Build | Deltas dropped | Final after the last tool |
|---|---|---|---|---|
| v0.23.4 | legacy (dashboard) | master | 6 | missing (bug reproduced) |
| v0.23.4 | legacy (dashboard) | this PR | 6 | shows once; normal turn unchanged |
| v0.23.4 | session authority (
gateway run) | this PR | 6 | shows once; normal turn unchanged || v0.22.7 | session authority (
gateway run) | this PR | 6 | shows once; normal turn unchanged || v0.22.7 | legacy (dashboard) | this PR | 6 | shows once; normal turn unchanged |
| v0.22.3 | legacy (dashboard) | this PR | 6 | shows once; normal turn unchanged |
| v0.22.3 | session authority | — | — | not tested (see below) |
| v0.22.0 | legacy (dashboard) | this PR | 6 | shows once; normal turn unchanged |
- Before v0.22.6,
gateway runhas nowebapp:listener setting. It hosts its authority socket only on a random loopback port, with no bind or auth option, and the app couldn't sign in through it.- The authority path is covered by v0.22.7 and v0.23.4 on the device, and by the
ReplayGapTestand authority-shape reducer tests.Screenshots
No UI change. The answer just shows where it was missing. The device checks above used test-gateway data only.
Checklist
master, and the command under "Tests" in CONTRIBUTING.md passes./gradlew :desktopApp:compileKotlinJvm)🤖 Generated with Claude Code
Review follow-ups
Three commits after review. Each case below has a
FinalReplyAfterToolsTesttest that failed before:session.redirecthas the model answer again, so its final carries nothing. Shown on the emulator against a v0.23.4 dashboard, with/steersent after "FINAL answer after " streamed. Before: "the last tool." then the whole final again below the steer. After: "the last tool." only.message.start: these forget the response start, so nothing stale is replaced or carried.response_previewedfinal above a steer opens no second reply.Retest on the emulator (v0.23.4 legacy, this branch): with 6 final deltas dropped, the final shows once, and normal turns are unchanged. The CI command and
:desktopApp:compileKotlinJvmpass, with 1637 core tests and 0 failures.