Skip to content

feat(persona): Lane D — bump turn-frame replay record to v2 with response_prompt - #1412

Merged
joelteply merged 1 commit into
canaryfrom
feat/lane-d-replay-record-response-prompt
May 18, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/lane-d-replay-record-response-prompt

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Lane D — atomic slice

Bumps PersonaTurnFrameReplayRecord from v1 → v2, adding the inference-input prompt so replay reproduces the EXACT prompt that fed inference, not a re-derivation from drained messages.

What changed

  • PERSONA_TURN_FRAME_REPLAY_SCHEMA_VERSION: 1 → 2 (with docstring on forward/backwards compat semantics)
  • response_prompt: Option<ResponsePrompt> field added with #[serde(default, skip_serializing_if = "Option::is_none")] — old v1 records on disk deserialize cleanly (None); None values omit the field on the wire (no schema noise)
  • PersonaTurnFrame::replay_record() populates response_prompt: self.response_prompt() so prod records carry the prompt that actually went into inference

Tests

persona::turn_frame test count: 9 → 12 passing

New tests:

  • v1_replay_record_without_response_prompt_deserializes_cleanly — forward-compat: old v1 records on disk load with response_prompt=None
  • v2_replay_record_populates_response_prompt_for_non_empty_frame — new behavior: replay_record bundles the prompt
  • v2_serialization_omits_response_prompt_when_none — wire shape: None omits the field

Existing replay_record_captures_raw_frame_and_derived_outputs updated to expect schemaVersion=2 and assert responsePrompt present.

Why this matters

Satisfies "FROM PROD not POC": production replay records now carry the full inference input. A replay can drive the SAME inference call the live persona made — not "what would have been derived from the drained messages."

This is the next atomic slice in Lane D (CBAR persona runtime frame). Backwards-compatible with all v1 records already on disk. Forward-compatible with the upcoming persona/turn-execute command that will chain drain → response_prompt → inference/llm/request.

🤖 Generated with Claude Code

…onse_prompt

Adds the inference-input prompt to PersonaTurnFrameReplayRecord, so
replay can reproduce the EXACT prompt that fed inference (not a
re-derivation from drained messages). Schema bumped 1 -> 2.

  - PERSONA_TURN_FRAME_REPLAY_SCHEMA_VERSION: 1 -> 2 with docstring on
    forward/backwards compat semantics
  - response_prompt: Option<ResponsePrompt> field added with
    #[serde(default, skip_serializing_if = "Option::is_none")] so:
      * v1 records on disk deserialize cleanly (None)
      * None values omit the field on the wire (no schema noise)
  - PersonaTurnFrame::replay_record() populates response_prompt =
    self.response_prompt() so prod records carry the prompt that
    actually went into inference

Tests (+3, total persona::turn_frame now 12):
  - v1_replay_record_without_response_prompt_deserializes_cleanly
    (forward-compat: old records on disk load as None)
  - v2_replay_record_populates_response_prompt_for_non_empty_frame
    (new behavior: replay_record bundles the prompt)
  - v2_serialization_omits_response_prompt_when_none
    (wire shape: None omits the field via skip_serializing_if)
  - Existing replay_record_captures_raw_frame_and_derived_outputs
    updated to expect schemaVersion=2 and assert responsePrompt present

This satisfies Joel's "FROM PROD not POC" framing: production replay
records now carry the full inference input, not just the
post-consolidation seed, so a replay can drive the SAME inference call
the live persona made.

Lane D advancement per ALPHA-GAP-ANALYSIS — keeps shipping the
CBAR-substrate persona turn frame in atomic slices, each one
backwards-compatible with prior records.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply

Copy link
Copy Markdown
Contributor Author

Codex validation on PR head:\n- cargo test --manifest-path src/workers/continuum-core/Cargo.toml persona::turn_frame --lib --features metal,accelerate\n- result: 12/12 passed\n\nThis is the correct Lane D prerequisite for #1409 turn-execute; merging to canary.

@joelteply
joelteply merged commit 8922ad3 into canary May 18, 2026
3 checks passed
@joelteply
joelteply deleted the feat/lane-d-replay-record-response-prompt branch May 18, 2026 18:42
joelteply added a commit that referenced this pull request May 18, 2026
…mpt -> inference (#1409) (#1415)

* feat(persona): Lane D — Rust persona/turn-execute chains drain -> prompt -> inference (#1409)

Adds the `persona/turn-execute` command in CognitionModule that
executes a full persona turn in ONE Rust hop:

  drain inbox
    -> wrap in PersonaTurnFrame
    -> derive ResponsePrompt (lazy)
    -> build InferenceRequest (prompt_text path)
    -> dispatch `inference/llm/request` via the global
       command_executor (routes to InferenceLlmModule registered
       in PR-5 #1404)
    -> bundle replayRecord + inferenceResponse
    -> persist replay record (v2 schema with response_prompt
       captured from #1412)

Files changed:

* src/persona/turn_frame.rs: new `ResponsePrompt::to_prompt_text`
  helper that flattens system_prompt + chat messages into a single
  deterministic plain-text prompt for adapter-based engines
  (LlamaCppAdapter, cloud adapters). Format:
    "<system>\n\nrole: content\nrole: content\n..."
  Empty system_prompt produces no leading paragraph; lowercase
  role matches the on-the-wire PromptRole serde format.

* src/modules/cognition.rs: new `persona/turn-execute` command.
  Inputs:
    - persona_id (required)
    - window_ms (default 80), max_items (default 16)
    - composition_artifact_id (default Uuid::nil())
    - max_tokens (default 512), max_duration_ms (default 10_000)
  Returns:
    { "replayRecord": PersonaTurnFrameReplayRecord | null,
      "inferenceResponse": InferenceResponse | null }
  Empty drain returns the null pair (no-op, not Err). Missing
  persona returns typed Err per Joel's never-swallow rule.

Tests (+9, all green):

* persona::turn_frame (6 new, total 18):
  - to_prompt_text_renders_each_message_as_role_colon_content
  - to_prompt_text_prepends_system_prompt_when_present
  - to_prompt_text_skips_empty_system_prompt
  - to_prompt_text_handles_mixed_roles_in_order
  - to_prompt_text_handles_no_messages
  - to_prompt_text_empty_prompt_returns_empty_string

* modules::cognition::turn_execute_tests (3 new):
  - turn_execute_persona_not_found_returns_typed_error
  - turn_execute_empty_drain_returns_null_bundle
  - turn_execute_bad_max_items_returns_typed_error

The dispatch-success path (drain -> dispatch -> inference response)
runs through `command_executor::executor()` which is only
initialized at runtime startup (ipc/mod.rs). Tests that exercise
the executor live in the integration suite; unit-tests here cover
the param-parse + short-circuit + persona-not-found paths.

Builds atop #1412 (v2 schema with response_prompt) and #1404
(InferenceLlmModule runtime registration). Closes alpha card
#1409.

Why one command: the TS persona loop previously executed each
stage with its own IPC round-trip (drain, then build prompt,
then call inference) — 3 round-trips per turn, prompt-building
lived in TS. Lane D pulls all three into the substrate so
(a) the prompt is built in Rust where the turn-frame lives,
(b) the production replay record carries the exact prompt that
fed inference, (c) the persona turn becomes one observable unit
on the bus.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(persona,#1409): force turn-execute through Rust registry (#1417)

* fix(persona,#1409): force turn-execute through Rust registry

* fix(runtime,#1409): use unlimited concurrency contract for cognition

---------

Co-authored-by: Test <[email protected]>

---------

Co-authored-by: Test <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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