Repository navigation
Retire a streaming reply placeholder when the log holds its answer - #947
Conversation
The conversation projection retired a provisional reply by the response address it was sent to, while every consumer keys the message on the delivery attempt it was reserved under. An answer that did not name that address left its own placeholder standing beside it, the two collided on one key, and the panel drew the empty draft. Retire on either identity, and report the page's own reading when the site gate finds a reply the container holds and the panel never drew.
leaf-agent
left a comment
There was a problem hiding this comment.
The attempt arm can't fire on any log the current writers produce, so the reproduction doesn't establish the mechanism behind run 35762205415.
DeliveryReply keeps one self.target = dict(target) for its whole life, built by delivery_reply_targets off the immutable delivery payload. replace() writes the placeholder with self.target["responds"]; _commit() appends the answer with for_event=self.target["responds"] and the same self.attempt. cmd_reply then writes that address unconditionally — {"responds": for_event} if for_event is not None else {"initiates": True} — so a delivery-bound answer always carries exactly the responds its own placeholder was written under, and event.get("responds") == live_reply.get("responds") already retired it. The receipt writer has the same shape: write_failure_receipt passes for_event=responds.
That closes the door the new arm is for. Two messages can only collide on one key by sharing an attempt; sharing an attempt means sharing a delivery; sharing a delivery means sharing responds. The one agent reply in the tree that carries an attempt and neither address is the one the new test appends by hand through events_model.append_event, around the append door — and skills/leaf/scripts/leaf/events.md states the contract as "agent responds or initiates". The test shows the projection would mis-draw that shape. Nothing writes it.
So the deployed page's empty agent bubble is still unexplained, and merging this would close the investigation on a state the tree can't reach. Either there's a writer I've missed, in which case naming it lands the change on evidence — or the mechanism waits on the next occurrence.
The diagnostic half doesn't wait on any of that, and is worth landing on its own: visibleReplyDebug now reports each message's mid, attempt and stream, which is what would name the state next time publish-site goes red. Split from the projection change it needs no mechanism to justify it, and it is what would supply the evidence the projection change is missing.
What I checked for a writer that names only the attempt
Every durable agent reply in the tree goes through cmd_reply, which has three callers outside tests/: DeliveryReply._commit (for_event=self.target["responds"]), worker/server.py's write_failure_receipt (for_event=responds), and the leaf reply CLI (--for or --initiates). The adapter's own path reaches the first of those — _end_turn → stream.finish(state, text) → _commit — and rebinding a delivery under a second turn re-reads the same immutable payload through delivery_stream_reply_target, so responds is stable across reconnection. The browser can't post either field: the reply browser contract in registry.json is "not": {"anyOf": [… {"required": ["responds"]}, {"required": ["initiates"]} …]}, and a browser attempt is client-generated rather than leaf-delivery-<digest>.
Test selection run locally: tests/test_render_conversations.py and tests/test_website_server.py, 159 passed with only test_the_adapter_takes_its_app_server_with_it_when_it_is_told_to_stop failing on this sandbox's missing AF_UNIX, as the description says. The three tests this PR touches or adds pass.
| undrawn_reply( | ||
| url, | ||
| page.evaluate("window.__leafVerifier.visibleReplyDebug"), | ||
| turn.state["reading"], |
There was a problem hiding this comment.
This reading was captured when await_turn first saw the answer; the DOM beside it is read up to 30 s later. A reading is an opaque content stamp, so the comparison can only say same or different — it can't say which side is behind. But the message reads inequality as one direction: "so the page never took the answer in". A page that took the answer in and then applied one more reading — the turn closing stamps the claim record, the session going back to listening rewrites status.json, and both are direct children page_reading stamps — reports a different stamp and gets the account for a page that never heard.
That is the failure this whole change exists to stop the gate making. Polling once more at the point of failure makes both sides current, so equality means the page is standing on a reading the answer is in:
| turn.state["reading"], | |
| read_agent_state(context, state_url, layer, release)["reading"], |
context, state_url, layer and release are all in scope here.
A deployed turn published its revision, replied, and went back to listening, and the reader's Threads panel showed one agent bubble with no words in it.
publish-sitefailed on run 35762205415 withreply never became visible in Threadswhile every server reading of that page held the answer. The conversation projection retires a streaming reply by the response address it was sent to, while every consumer keys the message on the delivery attempt it was reserved under — so an answer that does not name that address leaves its own placeholder standing beside it, the two collide on one key, and the draft is what gets drawn. The projection now retires the placeholder on either identity.tests/test_render_conversations.py::test_a_durable_answer_retires_the_placeholder_its_attempt_reservedreproduces the run's exact DOM — one user message with text, one agent message with none — on a local page in five seconds, and fails on the unchanged tree.The two identities
set_stream_replyreserves a provisional reply under a delivery attempt and addresses it to a response, and the durable answer names itself by either.browser_conversationappended the placeholder to its thread while no logged event carried itsresponds, and asked nothing about the attempt.readThreadRecordsthen keys every message onattempt ?? id, which is what the panel draws by, so both records arrive under one key and only one row survives.Retiring on either identity states the rule the two were expressing separately: the placeholder stands in for one delivery attempt sent to one response, and a logged event naming either is its answer.
skills/leaf/scripts/leaf/session-lifetime.mdcarries that sentence beside thestream.replyrow it belongs to.What I could not read is the failing page's own log — its container is gone, and leaf.page keys one per reader and release. So the mechanism here is established by reproduction rather than by reading that turn's reply event.
Why the gate could not say so
The failure arrived as a bare DOM snapshot, which fits three causes equally — a page that stopped asking, one whose read never landed, and one that took the answer in and drew nothing. The page already paints what separates them, so
undrawn_replynow reports the reading the page last applied against the reading the gate read the answer out of, the traffic ledger, and each message'sdata-mid,data-attemptanddata-stream-state. On this failure it would have printedmid=stream:… stream=active text=nobeside a matching reading, which names the cause in one line. This followsunpresented, added to the same file for the same reason on the presentation wait.What this does not settle
#925 is open against the other end of the same surface: it stops a completed delivery answer from losing its response address when the move is settled during the turn, which is one way an answer comes to name only its attempt. That PR keeps the address; this one makes the panel draw the answer whatever happened to the address. They touch different files and neither depends on the other.
The duplicate key itself stays silent — two messages sharing an attempt are still one row in
repeat. This change removes the producer of that state that the log can reach, so nothing here needs it to be loud, but it is not an invariant the projection states.Evidence from the failing run
The container's own records for event
b9150470(turn01a0ca49-fedb-7e23-8665-20e9623a6fed) name no fault:turn_delivery_boundat +0.3 s,fileChangecompleted at +19.5 s,turn_reply_first_text_publishedat +21.5 s,turn_stream_completedcompletedat +21.9 s, and noturn_reply_commit_failed. The gate's own polls agree —published at 22.8 s,replied at 25.1 s,answered at 25.1 s— and it then waited a further 30 s for the panel.The next deploy, run 35763376891, shows what a healthy page does with the same turn:
response visibleis the panel drawing the reply andrepliedis the gate's two-second poll noticing it, so on a healthy page the panel is painted a second before the gate knows to look. The failing run printed noresponse visibleline at all, which is why the wait is not the thing to widen.Verification
tests/test_render_conversations.pyandtests/test_website_server.pytogether: 192 passed, withtest_the_adapter_takes_its_app_server_with_it_when_it_is_told_to_stopfailing on this sandbox's missingAF_UNIXsupport, which it does on the unchanged tree too. All 34tests/runtime/cases and pre-commit pass.