Repository navigation
Stream Codex replies into Leaf conversations - #476
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
The streaming path works end-to-end and the projection/browser split reads right. Two things I'd want settled before it lands; the first is inline.
A slow turn/start response re-sends the same feedback into the same turn. start_delivery waits START_TIMEOUT for the socket thread's answer, while _send restarts its own START_TIMEOUT on every intervening notification — so a turn/start whose response lags behind turn/started and the first deltas (the ordering notes/codex-integration.md says the buffering machinery exists for) times out the caller while the socket thread goes on to bind the turn normally. _recover_delivery then propagates that RuntimeError with the queue record still offering, so the adapter's retry loop re-offers it and calls start_delivery again: a second turn/start that App Server steers into the same active turn with an identical leaf_feedback output, _bind appending the delivery id twice, and no receipt for the batch in between. The queue fallback survives the same retry because host-codex.md tells the model to treat a repeated page-and-sequence pair as a retry — the direct path has no equivalent statement, and its duplicate arrives as a tool result rather than a pointer the model chooses to read. Either the caller's wait has to outlive the socket thread's, or the direct path needs that retry rule stated where the model reads it.
leaf-agent
left a comment
There was a problem hiding this comment.
The addressable: false projection is the right shape for the first finding — one field, read by the shared reaction-surface renderer, so a consumer that needs an event id opts out at the point it reads rather than each surface learning about the draft. I ran the two suites it touches: tests/test_render_conversations.py -k codex (3 passed, including the new no-strip-while-streaming / strip-after-commit pair) and tests/test_interact_session.py -k "app_server or codex" (43 passed).
The turn/start fix in the same commit trades the duplicate for a hang I can reproduce; that one's inline.
leaf-agent
left a comment
There was a problem hiding this comment.
c16d0ae closes the in-flight half of the hang: I confirmed the new test fails at cd152740 with _queue.Empty and passes here, and a socket error now tears the connection down and reconnects rather than continuing the loop on a socket that just failed. The other half is still open, and it's inline — an exception type _run doesn't enumerate exits the socket thread with available still set, and every later start_delivery blocks forever.
CI failed — test_leaf_started_codex_turn_streams_into_its_thread_and_commits is red on fb5b16b.
leaf-agent
left a comment
There was a problem hiding this comment.
test is red on fb5b16b5 — test_leaf_started_codex_turn_streams_into_its_thread_and_commits fails with assert 'codex-stream:leaf-turn' == '<reply id>'. I'm dismissing my approval on that; the fix is inline and I'm happy to push it.
The failure is the test reading the middle of _commit_stream_reply's transaction, not the observer change in fb5b16b5. That function appends the reply and clears the draft under one PageTransaction, and append_event writes the log line where clear_stream_reply writes status.json afterwards. The poll waits on events_model.read_events, which takes no lease, so it can return the instant the reply lands and before the draft is gone; page_state in tests/interact_support.py then builds full_state off an unlocked read and projects both, with the draft last. A reader never sees this — PageStateService.page_state keeps a PageTransaction across both files — so the window is the test's alone, and the poll needs to name the settled state rather than the one the page passes through.
Waiting on the draft's removal as well as the reply closes it, since the clear is the same transaction's last write. Delaying PageTransaction.clear_stream_reply by 300ms reproduces CI's assertion exactly on this head, and the inline version passes under that same delay; tests/test_interact_session.py -k "app_server or codex" stays at 45 passed.
The unlocked read in page_state is the more general version of this — every test that polls the log and then asserts on the projection can observe a tear the server cannot. That helper is outside this PR's diff, so it's a separate change if you want it.
Separately, fb5b16b5 itself does what the last thread asked: the new test fails at c16d0ae with the socket thread dead and available still set, and passes here.
Leaf comments currently reach Codex through a durable queue, but the reader cannot see the response until the agent explicitly writes back to Leaf. This adds an experimental App Server transport that starts an addressed Codex turn for single-conversation feedback, streams its public response into that Leaf thread, and commits the completed text as one durable reply.
The App Server client binds each Leaf delivery to an exact Codex task and turn, keeps activity separate from response text, handles reconnect and turn-start races, and falls back to the existing queue for mixed or unsupported deliveries. The browser projects the in-progress response as an ordinary thread message and preserves incomplete replies as labelled drafts rather than settling the reader's input.
leaf codex launchnow owns a private App Server and its interactive CLI client, whileleaf codex start <page>connects the page adapter to that server. The integration remains experimental. The operating contract and future directions are documented inskills/leaf/references/host-codex.mdandnotes/codex-integration.md.The complete CLI-to-App-Server-to-Leaf-browser path was smoke-tested with two consecutive Leaf-started turns, incremental rendering, durable completion, browser reload, server restart, and page re-vendoring. The repository suite passes with 953 tests.