Skip to content

Make App Server final the canonical Leaf reply - #677

Merged
max-sixty merged 3 commits into
mainfrom
codex/app-server-stream-authority
Sep 13, 2026
Merged

max-sixty merged 3 commits into
mainfrom
codex/app-server-stream-authority

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

App Server turns currently have two possible writers for a plain Leaf reply: the native final-answer stream and an explicit reply operation. That makes destination routing and recovery ambiguous, and can make the user-visible draft disagree with the durable thread.

This change makes the App Server final answer authoritative for one delivery-bound reply. Leaf reserves the reply destination before provider execution, projects native final-answer updates through a small host-neutral DeliveryReply lifecycle, and commits the completed text through the existing canonical conversation writer. Version and request responses remain explicit, and harnesses without an observable stream retain the existing queue and reply operations.

The App Server adapter now treats the exact immutable delivery id in a provider item notification or resumed transcript as acceptance; a successful turn/start RPC alone is only an acknowledgement. While another turn is active, Leaf retains the pending delivery in its own durable queue and starts it directly once the task is idle instead of duplicating it into App Server's non-idempotent queue. The desktop and website adapters share the reply lifecycle and structured turn envelope while keeping their distinct process loops.

Delivery waiters have one lock-protected owner until reply binding succeeds or the client returns an explicit uncertainty. Queued and deferred entries only schedule that work, and disconnect cleanup cannot strand a caller or terminate the reconnect boundary.

The website's separate normal-reply endpoint, helper, token, and environment variable are removed. Structured startup-failure delivery remains. Timing logs now distinguish turn_start_acknowledged, turn_delivery_bound, first model activity, first visible reply text, and durable completion.

Verified with the full 1,058-test Python suite, Worker typecheck and 60 Worker tests, the complete pre-commit gate, an end-to-end local website-agent run, and independent Astra review including adversarial delivery interleavings. The final local profile acknowledged the request in 220 ms, showed Starting at 768 ms, entered model handling at 2.8 s, published at 13.3 s, displayed the first streamed reply text at 16.9 s, and committed it at 17.5 s.

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The App Server acceptance rule — bind only on the exact delivery id in the item stream, treat turn/start as an acknowledgement — is the right place to put that authority, and the slicing in _append_batch keeps the "one plain reply per turn" claim true at the envelope rather than at the writer. Two failure paths in the new reservation and deferral machinery don't unwind, though, and both are on the detached-adapter side where page state is durable.

I can push a commit for either if you'd like the mechanics rather than the decision.

Comment thread skills/leaf/scripts/leaf/codex.py Resolved
Comment thread skills/leaf/scripts/leaf/codex.py Resolved
@max-sixty
max-sixty merged commit 9efb5c0 into main Sep 13, 2026
19 checks passed
@max-sixty
max-sixty deleted the codex/app-server-stream-authority branch September 13, 2026 17:02
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