Repository navigation
Make App Server final the canonical Leaf reply - #677
Merged
Merged
Conversation
# Conflicts: # skills/leaf/scripts/leaf/codex.py
leaf-agent
reviewed
Sep 13, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
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.
leaf-agent
approved these changes
Sep 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
DeliveryReplylifecycle, 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/startRPC 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.