Skip to content

bt-daemon: let translators save and restore their state - #289

Merged
Stephen Belanger (Qard) merged 2 commits into
mainfrom
design/translator-state
Nov 16, 2026
Merged

Stephen Belanger (Qard) merged 2 commits into
mainfrom
design/translator-state

Conversation

@Qard

Copy link
Copy Markdown
Collaborator

First of a stack that splits #276. This PR only covers translators and doesn't change storage or delivery.

Changes

  • TranslatorState. AgentTranslator now requires a TranslatorState trait with save_state/restore_state. A blanket impl covers any Serialize + DeserializeOwned type, so each translator derives serde on its state instead of writing a codec by hand. Wrappers (ConfiguredTranslator, turn lineage, OpenCode's v1/v2 dispatch) forward to the translator they wrap.
  • Saved state. A translator's saved state is whatever it still needs from events it has already consumed in order to translate later ones, such as open spans and transcript offsets. The storage PR later in the stack persists this so it doesn't have to replay events that have already been translated.
  • SinkFields. Row fields the wire JSON leaves out (late_merge_key, late_merge_version, turn_span_id, is_turn) survive a save and restore through a shared SinkFields codec. The existing stored-SpanOp codec uses it too, and its JSON shape is unchanged.
  • Exact floats. serde_json has float_roundtrip on, so restored state is exactly what was saved.
  • OpenCode v2 parts. OpenCode v2 message parts that the translator doesn't model are kept as raw JSON instead of failing deserialization.

Tests

  • Round-trip. For every agent's native stream, the new every_agent_resumes_from_saved_state_at_every_native_boundary saves state after each event, restores it into a fresh translator, and requires the output to match an uninterrupted run exactly.
  • OpenCode v2 stream. The shared native streams now include an OpenCode v2 session, which the existing recovery-equivalence test also covers.
  • OpenCode v2 tests. These save and restore state during each run.
  • Suite. 734 passed and 14 ignored. Clippy is clean with all features and with default features, and cargo fmt --check passes. The suite ran with one known failure, and after the fix the three affected tests passed: the recovery test's coverage list needed a dedupe for OpenCode's second stream.

🤖 Generated with Claude Code

Every translator is now serializable, and AgentTranslator requires a new
TranslatorState trait with a blanket implementation for serde types. A
translator's saved state is everything it still needs from events it has
consumed to translate later ones, so a later pipeline can persist it
instead of replaying those events.

Sink-only row fields that wire JSON omits are preserved through a shared
SinkFields codec, which the stored SpanOp codec now also uses. serde_json
round-trips floats exactly so restored state matches what was saved.
OpenCode v2 message parts the translator does not model are kept as raw
JSON rather than rejected.

A test resumes every agent's native stream from saved state after each
event and requires output identical to an uninterrupted run; the shared
native streams now include an OpenCode v2 session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T17:47:35.253727Z 38c585b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Stephen Belanger (Qard) added a commit that referenced this pull request Nov 16, 2026
This branch already contained its own translator-state and import changes,
so conflicts take this branch's side. Keeps #289's save-and-restore test
for every agent alongside this branch's recovery tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match the crate's convention: derives name Serialize and Deserialize
through a use serde import rather than serde:: paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Qard
Stephen Belanger (Qard) merged commit fb6e55e into main Nov 16, 2026
29 checks passed
@Qard
Stephen Belanger (Qard) deleted the design/translator-state branch November 16, 2026 14:57
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.

2 participants