Skip to content

feat(botiverse): rebuild a past request from the wire, and record a messages hash - #9

Merged
stamp-build[bot] merged 1 commit into
patch-2.3.1-botiversefrom
otter/2.3.1-context-rebuild
Nov 6, 2026
Merged

stamp-build[bot] merged 1 commit into
patch-2.3.1-botiversefrom
otter/2.3.1-context-rebuild

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Otter from raft opened this pull request through Stamp
View in Stamp →


Stacked on patch-2.3.1-botiverse, the source of 2.3.1-botiverse.0 that Raft ships today. Target release: 2.3.1-botiverse.1.

Why: Raft's View Context shows the input behind a message an agent sent. llm.request records the system prompt and tool hashes and a message count, but nothing that proves which messages were sent. Reimplementing the projection in the daemon would drift from the code that built the real request.

What:

  • rebuildLastLlmRequest(records), exported from the node SDK, replays one agent's wire records the way a resume does: contextMemory along the restorable chain, so undo behaves as it does live, and profile over the whole journal. It runs the same projection and returns the last loop request's system prompt, tools, messages and response. Callers pass the records only up to the point of interest.
  • llm.request gains an optional messagesHash over the messages actually sent. New sessions report verified; sessions written earlier report count_matched. The hash ignores media payloads (the wire stores them dehydrated) and key order. If the hash can't be computed it's left out, so it can't fail a real request.
  • Any failed check is a refusal with a reason, never a best guess: message_count_mismatch, messages_hash_mismatch, system_prompt_mismatch, tools_unavailable, tools_mismatch, media_projection, newer_wire_version, replay_failed, no_request.

Known limits:

  • A request retried with media removed is refused, because its strip snapshot and display paths aren't recorded. An image the media budget replaced with text refuses through the hash.
  • On a session without a hash (count_matched), a budget-replaced image still shows as the image, and with tool select on (off by default) schemas of tools no longer active still show. The count can't detect either. That's why this result must never be labelled verified.
  • The wire doesn't record the SDK version that wrote it, only protocol_version, which the result returns.
  • A message appended between building a request and recording it, or during retry backoff, makes the count or hash differ. That shows up as a refusal.
  • If an image was replaced to fit the media budget, every later request refuses while that image stays in history, because the real requests really did differ.
  • If a first attempt streamed text and a same-step retry also failed, the returned response can mix both attempts. The hash doesn't cover the response.
  • Pass every physical line of the file, in order, including metadata: the wire's branch records refer to line numbers.

CI: test (2) is red and isn't from this change. Nine survey tests in apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts fail the same way on the base commit when the whole file runs.

Tests: round-trip tests run real turns in the harness (tool calls, undo with an unowned injection, compaction, clear, inline and blob-reference images, an over-budget image) and rebuild from JSON-round-tripped wire records. Each check has a refusal test. I mutated the helper's branches and the tests catch all but one: the rewrite-record stop in the response fold, which the length stop already covers in every case I could build. agent-core-v2: 7,357 passed, 2 skipped. node-sdk: 183 passed. Typecheck passes. An earlier build of this change was repackaged and its export run on a dumped session; the release dry run will repeat that. No real Kimi session file has been tried yet.

Existing inline snapshots changed only by the new field, which the harness masks because it covers tool output, whose wall time differs per run. docs/wire-manifest.d.ts is regenerated.

@stamp-build
stamp-build Bot force-pushed the otter/2.3.1-context-rebuild branch from ba9327e to 7c3b0db Compare November 6, 2026 01:02
…essages hash

llm.request records the system prompt and tool hashes and a message count, but
nothing that proves what messages a request sent. The Raft daemon's View Context
needs to show the input behind a message an agent sent, and reimplementing the
projection there would drift from the code that built the real request.

- rebuildLastLlmRequest (exported from the node SDK) replays wire records along
  the same restorable chain a resume uses, with the contextMemory and profile
  folds, runs the same projection, and returns the last loop request's system
  prompt, tools, messages and response. Pass the records only up to the point of
  interest. Every check that fails is a refusal with a reason, never a best guess.
- llm.request gains an optional messagesHash over the messages actually sent, so
  new sessions verify exactly (verification: verified), and an image the media
  budget replaced with text refuses. Older sessions rebuild as count_matched. The
  hash ignores media payloads, which the wire stores dehydrated, and key order. A
  hash that cannot be computed is left out rather than failing the request.
- A request retried with media removed is refused: its strip snapshot and display
  paths are not recorded.
- With tool select on, the live request also drops schemas of tools no longer
  active, which the wire cannot tell. The rebuild keeps them; the hash and count
  checks still apply.
- Test snapshots mask messagesHash: it covers tool output, whose wall time differs
  per run.

Signed-off-by: Otter <raft+otter@agents.stamp.build>
@stamp-build
stamp-build Bot force-pushed the otter/2.3.1-context-rebuild branch from 7c3b0db to 8bbb355 Compare November 6, 2026 01:21
@stamp-build
stamp-build Bot merged commit f511b63 into patch-2.3.1-botiverse Nov 6, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants