Repository navigation
feat(cli): authorized stream reattachment for B4.run - #489
Merged
Merged
Conversation
The AG-UI handler ran runRegistry.begin before rechecking the concrete thread row, so on the create-race path a caller the recheck ultimately denies held the victim thread's run slot for the width of that recheck. Because the thread id is client-chosen on this endpoint, a denied caller could brick a concurrent authorized run on the same thread with a transient run_in_flight 409. Move the row authorization (and the implicit create, when the turn makes one) ahead of the run-slot claim, mirroring the Agent Protocol run handlers. Adds a deterministic concurrency regression test that blocks a denied caller's recheck mid-flight and asserts a concurrent authorized run still claims the slot. Also corrects a stale comment on the static module manifest's thread-access channel (it is emitted and validated, not inert). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…urrent main The 2026-08-09 provisional plan predated PR1/PR B landing; its line anchors and wire assertions were stale by construction. This re-draft pins every anchor to the current tree, corrects two stale-spec items (the interrupt value is already surfaced; the hub belongs beside runRegistry, not threadRouteMap), and structures the work as durable-path-first so each task is independently testable. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pull-based fan-out for AP reattachment: open()/publish()/close() on the producer side, attach() handing each subscriber a point-in-time digest snapshot plus a live tail via next(). Coalesces consecutive chunk frames and per-callId subagent.message frames, drops the digest whole on byte overflow, isolates per-subscriber queue overflow, and guards producers against writing into a replaced/closed entry (mirrors the run-registry identity guard). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Add the GET mirror of POST /threads/:id/runs/stream so a disconnected
client can reattach to a thread: one `event: state` snapshot frame
(status, values, parked interrupts) followed by an immediate
`done{output:null}` + jittered retry hint on the durable path (no live
turn in this process). Also wires the live-path branch against the
already-landed LiveTurnHub, though nothing calls hub.open yet, so every
attach in this PR is durable.
Gates identically to GET /pending_interrupts: thread lookup, thread-access
read gate (denial byte-identical to a genuine 404), route-identity
resolution, then middleware with method:"GET". Adds the ThreadOperation
member `thread.attach` to @dawn-ai/sdk so policies can distinguish it.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…oducers Wires hub.open/publish/close into handleApStreamRequest, handleResumeRequest, and the AG-UI handler, so GET /threads/:id/runs/stream actually tails a running turn instead of always falling back to the durable path. Each producer opens a live turn right after claiming the run slot (anchored on the latest checkpoint before its own route stream runs), publishes every non-terminal chunk, and closes with the same terminal chunk the primary client saw, unconditionally, in its finally — regardless of done, error, park, or cancel. The AG-UI handler taps the raw StreamChunk stream before AG-UI translation so an attacher sees AP-vocabulary frames. handler.close() now drains the hub too, fanning a terminal frame to any hanging viewer. Also completes handleApAttachRequest's live-path `values` read (left null by the prior PR): it now reads the checkpoint at the live turn's anchor, which races nothing since old checkpoints are immutable. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…thread-auth-94c180
The attach-endpoint documentation added to apps/web/content/docs/dev-server/agent-protocol.mdx changed that page's git-derived last-modified date, which the SEO manifest freshness gate (added to main after this branch was cut) checks against the checked-in manifest. Regenerated so the gate passes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
4 tasks done
…thread-auth-94c180
blove
temporarily deployed
to
vercel-preview
September 10, 2026 06:58 — with
GitHub Actions
Inactive
blove
enabled auto-merge (squash)
September 10, 2026 07:10
This branch was successfully deployed
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.
Adds read-only stream reattachment to B4.run through
GET /threads/{id}/runs/stream. A viewer receives the saved state and current turn snapshot, then follows live output without claiming a run slot or cancelling the producer. When no live turn exists in the process, the endpoint returns the durable snapshot and completes.Authorization covers the selected live route and every verified route that contributed to its checkpoint history. Checkpoint provenance is written by the framework saver and retains inherited owners; client metadata cannot replace it. Existing checkpoints without verified provenance return
409 thread_route_unknownon attachment, including descendants of that unknown history. Fresh threads establish verified lineage. AG-UI authorizes the thread row before claiming a run slot.The in-memory hub bounds digest size, viewer count, and per-viewer queues. Slow or disconnected viewers detach independently. Node streaming respects socket backpressure, and snapshots coalesce text using the runtime's actual event schema. AG-UI errors and cancellation retain their Agent Protocol terminal meaning for attached viewers.
Includes B4 documentation, patch changesets, and regressions for cross-route authorization races, inherited and unknown checkpoint history, forged provenance, disconnects, UTF-8 limits, backpressure, and terminal events. Build, typecheck, lint, docs, and focused runtime tests are checked locally; the existing CI validation and deployment lanes remain the merge gates. No publishing or workflow changes.
Follow-up #506 supplies
b4 threads tail. Live reattachment is process-local; durable snapshots use the configured checkpoint storage.