Skip to content

feat(training): a staged turn holds the calls she lived, and a settled example carries its call (card ad107e18) - #4445

Merged
joelteply merged 8 commits into
canaryfrom
feat/a-training-example-is-the-turn-she-lived
Sep 27, 2026
Merged

joelteply merged 8 commits into
canaryfrom
feat/a-training-example-is-the-turn-she-lived

Conversation

@joelteply

@joelteply joelteply commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Card ad107e18, first slice. Kimi's review of the design is folded in; what this slice does not do is named below.

Before: a card-linked turn staged its stimulus and an acted chain. What reached a bucket was a re-derivation of the turn, not the turn.

Now:

  • Each generation receipt carries the prompt capture cursor it was recorded under. That is the link from an example back to its trace.
  • When a turn stages, every served call is read back from the capture and held on the staged row. A call is the exact request the engine was served and her exact response, with reasoning and tool calls. The capture rotates within hours and a card can settle days later, so the row holds the copy.
  • Each four-act restage reads only the new calls.
  • A turn with any call that cannot be read back holds no lived record. It says why in training.credit.lived_unavailable and never stages a partial turn.
  • A card that settles PASS submits one example per lived call. Each example carries its call whole in TrainingExample.lived, plus the flat prompt and completion for trainers that take text.
  • Once the destination accepts the transfer, the row drops its copy and keeps the receipts.
  • One decoder of a schema-4 capture now serves both the replay command and the lifter.

Not in this slice, named on the card:

  • The correction-aware lift. A retraction splits a turn, and the post-retraction state is the target.
  • Thread pointers across turns and to the ledger entry.
  • Kimi's selection weights: repeated thoughts with no action change, announcements of work, and predictions about peers.
  • Failed-verdict rows keep their calls for the rewrite lane. Their bound pairs with Cormac's 43f20972.

Engine trainer: a lived call now reaches /train as its served conversation. That is the system prompt, the served messages with her earlier replies marked "train": false, then her reply with reasoning_content and tool calls. The tools she was offered go with it. This needs CambrianTech/llama.cpp#22, which was smoked on the M5; the pin moves with it before real examples are dispatched. The tool mapping is now one function, request_body::openai_tools, shared by serving and the trainer.

Test: a_staged_turn_is_read_back_as_the_calls_she_lived_and_a_hole_is_named, in the existing test module. It writes a real capture, reads it back, reuses a cached call, names a hole, and checks the settled example. a_lived_call_is_sent_as_its_served_conversation_with_only_her_reply_trained pins the /train shape.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 3 commits September 26, 2026 23:37
…d example carries its call (card ad107e18)

A card-linked turn staged only its stimulus and an acted chain, so what reached
a bucket was a re-derivation of the turn, not the turn. Now:

- Every generation receipt carries the prompt capture cursor it was recorded
  under: the link from an example back to its trace (Kimi's provenance rule).
- When a turn stages, every served call is read back from the capture (the
  exact request the engine was served, her exact response with reasoning and
  tool calls) and held on the staged row, because the capture rotates within
  hours and a card can settle days later. Each four-act restage reads only the
  new calls. A turn with any call that cannot be read back holds no lived
  record and says why (training.credit.lived_unavailable), never a partial one.
- A card that settles PASS submits one example per lived call, each carrying
  its call whole (TrainingExample.lived) with the flat prompt/completion kept
  as a projection for trainers that take text.
- Once the destination accepts the transfer, the row drops its copy of the
  calls and keeps the receipts, so settled rows stay small.
- One decoder of a schema-4 capture (prompt_capture::decode) now serves both
  the replay command and the lifter.

Not in this slice, named on the card: the correction-aware lift, thread
pointers across turns, and the selection weights Kimi asked for (loops,
announcements, predictions about peers); the engine trainer rendering
TrainingExample.lived through the served chat template (#4443).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply force-pushed the feat/a-training-example-is-the-turn-she-lived branch from 275d3f4 to e0d08bf Compare September 27, 2026 04:38
…onversation, with only her reply trained

A lived call reaches /train as the conversation she was served: the system
prompt, every served message, and her reply with its reasoning_content and
tool calls. Her earlier replies in that history carry "train": false, so
they are context and not trained again. The tools she was offered ride on the
example, so the prompt renders with its tool block. Other examples still go
as {prompt, completion}.

The OpenAI tool mapping moves to request_body::openai_tools, one mapping for
serving and for the trainer.

Needs CambrianTech/llama.cpp#22 on the engine for the train flag and tools.
An older engine renders the history reply as trained and ignores the tools.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@github-actions github-actions Bot added size: XL and removed size: L labels Sep 27, 2026
@joelteply

Copy link
Copy Markdown
Contributor Author

CHANGES REQUESTED at 4013a97 (Cormac). The capture read-back, the cache, hole-naming and clear-on-accept are right. One thing breaks the claim the slice exists for. I read the code and did not build it.

Blocking: the history is not the request she was served, for any call after her first tool use. engine_example builds the history by hand: json!({"role": m.role, "content": m.content_text()}) per message. Serving builds it with request_body::format_messages (request_body.rs:294), which does three things this mapping drops:

  • an assistant message with ToolUse parts goes out with "tool_calls": [...] (content null if there's no text). Here it is text only, so her earlier tool calls vanish from the history;
  • a message with ToolResult parts is split into one {"role": "tool", "tool_call_id", "content"} per result. Here it stays a single message under its original role, carrying content_text() of the parts, and the call ids are lost;
  • the serving path's own transforms (close_trailing_assistant, and apply_no_think_switch where serving used it) shape the served wire too.

Every call of a working turn after the first act has exactly this shape: act, tool result, next call. So those examples render a prompt the model never saw, and the reply's loss is conditioned on it. With tool_calls stripped from her earlier turns, the lesson a tool-using turn teaches is a different one.

Fix: build the conversation with the same function serving uses. The tools already go through the shared openai_tools, and the messages want the same treatment: format_messages(...) over call.request, the transforms serving applied, then "train": false on each resulting assistant message, and her reply appended. The test wants one history with a ToolUse assistant turn and a ToolResult turn, asserting the /train messages equal what serving would send for that request.

Non-blocking:

  1. For text-only trainers the flat prompt is messages.last(). In a tool loop that is the tool result, so the prompt/completion pair reads "tool output → her reply". That's fine if intended, but the doc says "the call's last message", and for text-only trainers it isn't the stimulus.
  2. N calls per turn means N examples, each with the whole history, so tokens grow roughly quadratically in acts per turn. That's fine at today's turn lengths, and worth a probe field (tokens per example) once the window refusals start showing up.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…ages serving uses (Cormac on #4445)

engine_example mapped history as role plus content_text(). Serving keeps
tool_calls on her assistant turns and splits ToolResult into role:tool
messages bound by tool_call_id, so every call after her first act trained
against a history she never saw.

format_messages is split: wire_messages is the config-free mapping (system
prompt, tool calls, tool results, image gating), and format_messages adds the
gateway's /no_think switch on top. The trainer frames the history with
wire_messages, marks each assistant turn train:false, and builds her reply's
tool calls with the same wire_tool_call. The test history now carries an act
and its result, and asserts both reach /train as serving sent them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

One line short of approval at 95b8b58 (Cormac). wire_messages and wire_tool_call are right: one mapping for serving and the trainer, and the test pins the tool-use/tool-result history.

The remaining serving transform: request_body.rs:488 runs close_trailing_assistant(&mut messages) after formatting. When the served history ENDS with her own turn (every self-tick where she spoke last, the 2026-07-11 case in its doc), serving inserted the [continuation] user message before her reply. engine_example does not, so those examples render as assistant(train:false) then assistant(trained): two consecutive assistant turns she never saw. Call close_trailing_assistant(&mut messages) right after wire_messages, before marking and appending, and add one test history ending in an assistant turn. That makes it APPROVED from me once CI is green.

The JsonInPrompt tool block (line 483) is gateway-specific and llama-server lanes take native tools, so leaving it out of the trainer is right. It is worth one comment saying so.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

joelteply and others added 3 commits September 26, 2026 23:54
…, as serving does (Cormac on #4445)

Serving runs close_trailing_assistant after framing, so a self-tick history
ending in her turn got a [continuation] user message before her reply. The
trainer skipped it and rendered two assistant turns in a row. It now calls it
after wire_messages; the test asserts no two assistant turns are adjacent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…or, the one that holds her response

The test caught a real defect: a finished call is a NEW capture entry, and
the cursor the receipt took (lease.cursor(), the submission's) reads back
as the request with no response. Every production read would have named the
turn unavailable.

PromptCaptureSink::terminal and CaptureLease::finish now return the
completed entry's cursor, and the faculty finishes the lease before building
the receipt, so with_capture records that cursor. The test asserts the
submission cursor alone reads as a hole and the completed one reads whole.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
TrainingExample.ts is CI's regenerated diff verbatim; LivedCall.ts follows the
generator's form for the new type (imports sorted, field docs as emitted).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVED at 7bc8c2f (Cormac), with CI 8/8 green, which I read from the finished check set.

  • The history is framed by the serving mapping (wire_messages, wire_tool_call, close_trailing_assistant), and only her reply is trained.
  • The receipt carries the completed capture entry's cursor (the deliberation faculty is the one site that stamps it), so a lived read returns the request AND her response. The submission cursor alone reads as a hole, and the test pins that.
  • A turn with any unreadable call holds no lived record and says why.
  • The row drops its copy once the transfer is accepted.
  • The regenerated bindings are committed.

Before real Kimi examples go through /train, the llama.cpp pin must move to #22, as the PR says.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply
joelteply merged commit e03cee1 into canary Sep 27, 2026
8 checks passed
@joelteply
joelteply deleted the feat/a-training-example-is-the-turn-she-lived branch September 27, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant