Skip to content

Carry native message identity, phases and outcomes from the CLIs into the transcript (CF-1) - #282

Merged
BunsDev merged 7 commits into
mainfrom
cf1-contract
Oct 18, 2026
Merged

BunsDev merged 7 commits into
mainfrom
cf1-contract

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #274. Part of #273 (CF-1, the contract the other seven issues build on).

What changes

Backends reported a turn through untyped callbacks (delta, assistant, thinkingDelta, toolStart…) and the runner kept one streaming buffer. Now every backend reports assistant text, reasoning and tool work through one typed path, TurnSink.observe(observation). Each observation names the native item and part it belongs to. The runner stamps it with the Modex turn and attempt and folds it into transcript items with a pure projector, applyConversationEvent. Coding still runs only through codex app-server and claude -p; nothing here executes, replays or calls a provider.

  • Contract: apps/desktop/src/shared/conversation-events.ts holds the types, the projector, parseConversationEvent, the legacy adapter itemFacts and finalAnswerIndex. docs/conversation-events.md gives the exported signatures and the native mapping tables.
  • Identity: each item gets an origin with the Modex thread, turn (the user message) and attempt, plus an opaque runtime generation and the native thread/turn/item/part. Reused native ids never collide. Retry and the credit fallback are new attempts with no new user message.
  • Values: message phase (commentary, final, unspecified), reasoning representation (summary, provider-text, unavailable) and outcome (running, succeeded, failed, denied, interrupted, unknown). These are Modex design values, mapped from Codex 0.163.0 and Claude Code 2.1.302 native values; anything unmapped stays unspecified or unknown.
  • Adapters: Codex, Claude, the mock engine and the Images fixture (through LocalItems), sub-agents (AgentTracker) and account-bound Codex (one runtime per registration's app-server) all report through observe. The title generator reads it too.
  • Runner: one attempt per backend run, each with its own sink. A superseded attempt's sink is inert, every method of it. A repeated CLI event id (Claude's line uuid) applies once. attempt.end settles open work: interrupted after a stop, unknown otherwise; idle or a dropped connection never means success.
  • Legacy and compatibility: item fields are additive. Old transcripts load unchanged and read through itemFacts, with no invented provenance. The journal, journal-disabled mode, the phone's item projection and the Store client are unchanged. The only renderer changes are compatibility ones: a finished tool's label comes from its outcome, so an unknown never reads "Done"; a turn folds work up to its typed final answer, keeping the last-reply heuristic for untyped and legacy turns.

Behavior that changed on purpose

  • Interleaved messages stay separate. On 89c98f2 a delta after a tool start split a message into a fragment plus a duplicated copy.
  • A Codex reasoning summary is no longer joined with reasoning text; each representation is its own Thinking row.
  • A Codex commentary message that completes without streaming is now kept, labelled commentary. Before, it was dropped; no test pinned that.
  • A tool left open when the stream ends is unknown with no ok, instead of ok: false; it reads "Status unavailable", not "Failed" or "Done".
  • Codex web search reports no status, so its outcome is unknown rather than an inferred success.
  • An assistant item arrives with its first streamed text instead of empty then patched, and patches carry only changed fields.
  • Claude thinking text is summary only when the CLI says thinking_display: "summarized"; otherwise provider-text. Signature-only and redacted_thinking blocks are unavailable; signatures and redacted data are never read or stored.

Evidence

Base 89c98f280292b13fd9b1c7af1bf2fe65cd2fa0d1.

  • Fixtures: sanitized live captures under apps/desktop/test/fixtures/conversation/:

    • Claude Code 2.1.302 with Haiku 5.5: interleaved text, tools, allowed and denied commands, signature-only thinking
    • codex-cli 0.163.0 with gpt-6-astra: commentary, final answer, a declined command, a reasoning summary, empty reasoning, an interrupt
    • Codex's generated protocol enums
    • one synthetic Claude stream from the [Tracker] Native conversation fidelity: execution → transcript → recovery → Notes #273 session, labelled as synthetic, with summarized thinking text and redacted_thinking

    Fixtures say how those CLI versions behaved on 2026-10-18; they are not live-provider acceptance.

  • Red before green: 4d156e6 adds the fixture tests alone. On 89c98f2, 7 of 9 fail. Among them:

    • "Plan A.\n\nPlan B.\n\nraw step 1 raw step 2": a summary absorbed reasoning text.
    • "fresh answer STALE FROM ATTEMPT ONE": a credit-fallback attempt was written into by the first.

    The later tests were each seen failing before their fix:

    • the commentary message kept
    • summarized thinking
    • a status-less exit code
    • a repeated uuid (checked by switching the dedupe off in the build)
    • a stale attempt's notice

    The resume-handle assertion added beside that notice is covered by the same guard but was not seen failing on its own.

Checks run locally on macOS (Apple Silicon) with Node v24.18.1 and pnpm 10.34.5, at a load average of about 190–250 (other sessions were building and testing).

  • pnpm typecheck (main + renderer): passed.
  • pnpm test on 2fe9488: passed on a clean tree. First stage: 1,514 tests, 1,498 passed, 0 failed, 16 skipped (skips that already exist on main). Second stage: 21 of 21.
  • Focused e2e on 2fe9488, covering app, sources, agents, event-journal, approvals and store-demo: 28 of 28 passed. store-demo first failed its precondition, "The Store client is not built", and both of its tests passed after pnpm --filter @modex/store-desktop build.
  • The full e2e suite runs in the required unit + e2e (macOS) CI job on this PR.
  • CI on 2fe9488: unit + e2e (macOS) passed. The iPhone companion job failed at CompanionFlowTests.swift:334, where "Follow-up received: …" never appeared (job).
    • Cause: the paired-iPhone fixture apps/ios/ModexCompanion/Scripts/fixture.mjs is plain JavaScript, so typecheck missed that it still called the removed sink.assistant().
    • Fix, in 2773107: it now replies through LocalItems. A local probe confirmed the reply reaches the transcript, and a repo-wide search found no other untyped caller.
    • The guard refused to merge while that check failed.

Not covered here

  • Live-provider acceptance with current models. Turns through the real CLIs inside the app still need a human run.
  • Richer rendering of phases and representations (CF-4), interruption and request lifecycle (CF-2, CF-3), and storing or replaying conversation events (CF-6). parseConversationEvent and the deterministic projector are ready for CF-6, but events are not persisted yet.
  • provider-text rows render as Thinking rows, the same as summaries, until CF-4.

Real stream-json output from Claude Code 2.1.302 (claude -p, Haiku 5.5)
and app-server output from codex-cli 0.163.0: interleaved commentary and
tools, an allowed and a denied command, a reasoning summary, reasoning
with no text, and an interrupted turn. Plus the native enums from
`codex app-server generate-json-schema`. sanitize.mjs removes local
paths, account and inventory details and opaque thinking signatures.

Refs #274

Coven-Harness: Claude Code / claude-opus-5-5
The captures replay through the real CodexBackend and ClaudeBackend and
the runner. On 89c98f2 seven of the nine fail: assistant items carry no
phase, origin or outcome, reasoning has no representation, a summary
absorbs reasoning text ("Plan A.\n\nPlan B.\n\nraw step 1 raw step 2"),
open work at a dropped connection has no outcome, and a credit-fallback
retry lets the first attempt's sink write into the second
("fresh answer STALE FROM ATTEMPT ONE"). Split UTF-8/JSON lines and
repeated tokens already pass; they stay as regression guards.

Refs #274

Coven-Harness: Claude Code / claude-opus-5-5
shared/conversation-events.ts defines typed observations named by
native identity (runtime generation, native thread/turn/item/part),
Modex turn/attempt identity, message phase, reasoning representation
and execution outcome, plus applyConversationEvent, a pure, serializable
fold. Native ids are scoped so reuse never collides; events apply only
to the turn's current running attempt; duplicates at or below an
attempt's cursor change nothing; repeated text is never deduplicated.
itemFacts reads items saved before the contract without inventing
provenance. Transcript items gain optional origin/phase/outcome/
reasoning fields.

The projector tests pass; the adapter and runner tests still fail.

Refs #274

Coven-Harness: Claude Code / claude-opus-5-5
TurnSink loses delta/assistant/thinking*/tool* for observe(), and the
runner folds each stamped observation into items with the projector.

- Codex: native thread/turn/item ids, phase from MessagePhase, summary
  parts by summaryIndex and reasoning text by contentIndex as separate
  items, tool outcomes from native status (declined = denied), one
  runtime generation per app-server (so per account registration and
  per stale-auth restart). An unstreamed commentary message is now kept,
  labelled commentary, instead of dropped.
- Claude: blocks named by message id and stream index (the k-th block
  of a message id is stream block k), line uuid as the event source,
  thinking text a summary only when thinking_display is "summarized",
  signature-only and redacted thinking unavailable and never read, a
  tool_result error denied only when Modex refused that tool_use_id.
  Messages without ids (older CLIs) are named at ingress.
- Mock, Images fixture and scripted tests: LocalItems assigns ids at
  ingress. Agents report tool observations. Titles read observe().
- Runner: one attempt per backend run (Retry, credit fallback), each
  with its own sink; a superseded attempt's sink is inert in every
  method; a repeated CLI event id applies once; attempt.end settles open
  work as interrupted after a stop, otherwise unknown; a stale running
  item from an earlier process loads as unknown.

Review notes from the #273 tracker session on #274 are covered by tests,
on its synthetic Claude stream (imported, labelled synthetic) among them.

Refs #274

Coven-Harness: Claude Code / claude-opus-5-5
A finished tool's label comes from its outcome (Done, Failed, Denied,
Stopped, Status unavailable), so unknown work never reads "Done"; items
saved before outcomes keep their old labels. A turn folds its work up to
its typed final answer; turns without typed phases keep the last-reply
heuristic. Compatibility only: richer rendering is CF-4.

Refs #274

Coven-Harness: Claude Code / claude-opus-5-5
docs/conversation-events.md gives the exported signatures, the
projector's rules, the runner's attempts, and the Codex 0.163.0 and
Claude Code 2.1.302 mapping tables, for the issues that build on it.

Refs #274

Coven-Harness: Claude Code / claude-opus-5-5
@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modex Ready Ready Preview Oct 18, 2026 7:38am UTC

Request Review

@BunsDev BunsDev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review from the #273 tracker session, at head 2fe9488. I read the runner, contract, Claude adapter and renderer diffs, and ran nothing on this branch. Two findings with a renderer-compatibility cost, then notes. Nothing here blocks the contract shape.

1. Tools still open when an attempt ends now read as succeeded on older clients. okFor("unknown") and okFor("interrupted") return undefined (shared/conversation-events.ts:248), and attempt.end uses it for tools still running (:353).

  • On 89c98f2 the runner's finally set ok: false on those tools.
  • A renderer from before this PR reads ok, not outcome. It shows ok: undefined as Done, and its isWork (item.ok !== false) folds the tool away with completed work.
  • So a paired desktop on an older build (Store client or desktop host pairing during a version skew) now shows an interrupted or unknown tool as quietly successful. Before this PR it showed as failed and stayed visible.
  • The tracker's done list asks that unsupported clients keep a safe readable fallback.

Suggestion: keep ok: false as the legacy fallback for unknown and interrupted. The new renderer reads outcome, so its "Status unavailable" / "Stopped" labels are unaffected, and old readers never see a success that did not happen. slot()'s restart path (runner.ts:196) has the same okFor("unknown").

2. toolFoldsAsWork folds unknown outcomes away (shared/tool-summary.ts:33).

  • #277's acceptance asks that unresolved work stay visible when successful work collapses.
  • An unknown tool is unresolved by definition: the stream ended before it reported.
  • I think this is paired with mapping every Codex webSearch to unknown. Those would otherwise never fold.

I'd untangle the two:

  • A webSearch item/completed with no error is the provider's own completion signal for an item type that has no status field, so it maps to succeeded; one with an error maps to failed.
  • unknown then stays visible.

If you'd rather keep web search at unknown, I'd still not fold unknown, and say in #277 that CF-4 decides how status-less items fold.

Notes, all fine as is:

  • ${uuid}#${part} keeps one CLI line from collapsing two observations (claude.ts:261). Good.
  • An attempt's sink stays active until the next beginAttempt, but the projector applies events only to the current running attempt, so a late event between attempt.end and the fallback's start is inert. Worth one test if there isn't one.
  • runOn's catch ends the attempt as failed on a thrown backend error. When the throw comes after work has started, unknown would be the more accurate claim. Minor.
  • The iPhone shows a checkmark for every finished tool and ignores ok (CompanionViews.swift:769). That predates this PR; I'll note it for CF-6 (#279).

Once you've decided on 1 and 2, I'll build CF-4's semantic slice on finalAnswerIndex / itemFacts as exported here.

@github-code-quality

github-code-quality Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: TypeScript

TypeScript / code-coverage-agent

main 89c98f2 cf1-contract 2773107 +/-
62% 62% 0%
View coverage of the 10 most impacted files.
File main 89c98f2 cf1-contract 2773107 +/-
apps/desktop/sr...kends/claude.ts 97% 97% 0%
apps/desktop/sr...ngine/runner.ts 99% 99% 0%
apps/desktop/sr...ackends/mock.ts 95% 95% 0%
apps/desktop/sr...ngine/titles.ts 96% 96% 0%
apps/desktop/sr...kends/agents.ts 100% 100% 0%
apps/desktop/sr...ckends/types.ts 100% 100% 0%
apps/desktop/sr...tool-summary.ts 100% 100% 0%
apps/desktop/sr...ckends/codex.ts 95% 96% +1%
apps/desktop/sr.../local-items.ts 0% 96% +96%
apps/desktop/sr...ation-events.ts 0% 99% +99%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 18, 2026 08:04 UTC

The paired-iPhone fixture is plain JavaScript, so typecheck missed that
its scripted backend still called the removed sink.assistant(); every
reply failed and the "Follow-up received" assertion timed out in the
iPhone companion job. It now replies through LocalItems like the other
scripted backends. A repo-wide search found no other untyped caller.

Refs #274

Coven-Harness: Claude Code / claude-opus-5-5
@BunsDev
BunsDev merged commit 7780093 into main Oct 18, 2026
13 checks passed
@BunsDev
BunsDev deleted the cf1-contract branch October 18, 2026 08:05
BunsDev added a commit that referenced this pull request Oct 18, 2026
Coven-Harness: Claude Code / claude-opus-5-5
BunsDev added a commit that referenced this pull request Oct 18, 2026
CF-1 replaced TurnSink's delta, assistant, tool and thinking calls with
observe(observation) and scopes every sink to its attempt. CF-2's
additions sit on that contract unchanged:
- the approval withdrawal signal;
- TurnResult.stop;
- the approval item's withdrawn reason;
- Stop, drain and escalation in runTurn.

ClaudeBackend's line handler, which CF-2 had moved into onLine, now
makes CF-1's observations: the session id, the per-line uuid source,
and native refs scoped to the process's runtime.

The CF-2 runner case that expected Stop's leftover tool row to read
failed now sees CF-1's interrupted outcome with ok absent. The next
commit settles that row from the CLI's own rejection.

Refs #275, #274

Coven-Harness: Claude Code / claude-opus-5-5
BunsDev added a commit that referenced this pull request Oct 18, 2026
event-journal.md gains how typed items travel, merge and replay, how
work left running at a restart is settled for every client, and what the
phone receives; conversation-events.md records the CF-6 half that rests
on #274. Status moves the merged CF-1 (#282) and CF-4 (#284) entries and
this change into one "On main, unreleased" entry.

Refs #279

Coven-Harness: Claude Code / claude-opus-5-5
BunsDev added a commit that referenced this pull request Oct 18, 2026
… phone (CF-6, first half) (#285)

* Share the captured-stream test helpers between test files

The fixture loader and the Codex and Claude stream players move from
conversation-events.test.ts to test/conversation-fixtures.ts, so the
journal tests can replay the same captures without re-running those
tests. No behaviour changes.

Refs #279

Coven-Harness: Claude Code / claude-opus-5-5

* Replay journal items as upserts and give the phone typed items

replayItems appended an item event even when that item was already
there, so a frame delivered twice doubled the item and left a stale
copy; it now upserts by id as the renderer and phone do. A typed Codex
capture converges across the runner, the saved snapshot, journal
replay, a duplicated replay and the phone's full and delta snapshots.
The phone gets phase, outcome and reasoning; a phone that reads only
title and status sees how a finished tool that did not succeed ended in
its title ("· Denied", "· Failed", "· Stopped", "· Status unavailable").

Refs #279

Coven-Harness: Claude Code / claude-opus-5-5

* Settle work a dead process left running in the snapshot and the journal

The runner already read a running item from an earlier process as
unknown (and a running agent as status unavailable), but only in
memory: the saved transcript kept "running", and a paired desktop or
phone resuming from the journal kept a spinner forever. Loading a
thread now saves the settled items once and sends them as item updates,
so the journal and every client agree. Nothing is run again. Old
transcripts and journals load, replay and project unchanged.

Refs #279

Coven-Harness: Claude Code / claude-opus-5-5

* Document typed conversation state in the event journal

event-journal.md gains how typed items travel, merge and replay, how
work left running at a restart is settled for every client, and what the
phone receives; conversation-events.md records the CF-6 half that rests
on #274. Status moves the merged CF-1 (#282) and CF-4 (#284) entries and
this change into one "On main, unreleased" entry.

Refs #279

Coven-Harness: Claude Code / claude-opus-5-5
BunsDev added a commit that referenced this pull request Oct 18, 2026
Val decided on #290. The signed v0.2.0 tag passed release run 39100984341 on
2026-10-18. It covered signing, notarization and stapling, the packaged E2E
suite, all three signed native updater scenarios and the Windows and Linux
installers. The entry still listed the packaged E2E and the updater scenarios as
remaining. It now records the run and the draft's assets. What is left: the
download checks, publication, the banner upgrade on the release Mac and the
Companion build 7 upload.

The entry also said the release ships everything under "On main, unreleased".
That stopped being true when the conversation-fidelity slices from #282 landed
after the tag. It now says the tag is on 01b1b8a (#272) and that those slices
are not in it. Every item it lists is in the tag.

Coven-Harness: Claude Code / claude-opus-5-5
BunsDev added a commit that referenced this pull request Oct 19, 2026
Since #284, a tool whose outcome is unknown stays in view when its turn
finishes. codexOutcome (from #282) read every Codex web search as
unknown, because codex-cli 0.163.0's webSearch item has neither a status
nor an error field, so every search stayed unfolded in every finished
Codex turn. A web search's item/completed is the only report it makes,
so a completed search is now succeeded. Unknown keeps meaning work that
never reported. The contract doc's mapping table says so.

Part of #277; follows #282 and #284.

Coven-Harness: Claude Code / claude-opus-5-5

This branch was successfully deployed

1 active deployment
Preview — 2773107d Deployed Oct 18, 2026 by vercel[bot]
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.

[P1][CF-1] Preserve native turn/item identity, message phases, and execution outcomes end to end

1 participant