Repository navigation
fix(agent): bind schedule origin to run context - #484
Merged
Merged
Conversation
jhrozek
force-pushed
the
fix/session-origin-run-context
branch
from
August 13, 2026 11:17
62b413e to
f275436
Compare
JAORMX
approved these changes
Aug 13, 2026
Two concurrent runs on a shared Engine could interleave between the OriginBinder's per-run bind and the Schedule tool's execution, so one session could stamp another session's id onto a schedule — and, via captureScheduleOwner, its owner principal too. Atomic access prevented the data race but not the mis-attribution. Bind the executing session id onto the cancellation-derived context in startRun, and have ScheduleTool.create read it there when it builds the ScheduleSpec. Both run-entry seams (Run and ResumeApproval) route through startRun, so normal runs and awaiting-approval resumes inherit identical attribution. The spec literal in create is the only site that assigns OriginSessionID, and scheduleArgs has no origin field, so neither model-supplied args nor a stale binding can supply one. An unbound context yields the empty id, which means no delivery rather than delivery to an arbitrary session. Remove the SessionOriginScheduleManager wrapper outright rather than keep it stateless. Once the binder state is gone it is a single field assignment behind ten delegating methods, and omitting it fails SILENTLY: an empty origin is also the legitimate originless posture, so a composition root that forgets to wrap is indistinguishable from one that does not. Stamping at the construction site cannot be forgotten, and composition passes the port.ScheduleManager straight through. withSessionOrigin is unexported and replaces no exported surface. An origin is acquired by running under Engine.Run; an out-of-band create is originless by design (ADR 0075 decision #1) and goes to the manager directly, as Service.CreateSchedule already does. Exporting later is Added (minor); un-exporting later would be breaking. Net: fourteen engine symbols removed, none added. The regression test forces the interleaving through a provider-blocking rendezvous rather than racing opportunistically, so it fails deterministically on the atomic-pointer implementation. Closes #482. See ADR 0104. Co-Authored-By: Claude Sonnet 5 <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: mecatl <[email protected]>
jhrozek
force-pushed
the
fix/session-origin-run-context
branch
from
August 13, 2026 13:14
094dfeb to
297287c
Compare
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.
Closes #482.
Schedule-origin attribution moves from mutable state on a shared wrapper to the run context, and the wrapper is deleted.
The bug
SessionOriginScheduleManagerheld the origin session id in a process-wideatomic.Pointer.startRunbound it;CreateScheduleread it later, when the model called theScheduletool. A sharedEngineis safe for concurrent use, so two runs interleave between those points and both creates read the last-bound id. Atomic access prevented the data race, not the mis-attribution — and viacaptureScheduleOwnerthe schedule then inherits the other session's owner principal.Present on
mainsince 447322e (2026-07-28) made the shared catalog carry the tool; introduced latent in 5154b49 (2026-07-27). Full archaeology in #482.The fix
startRunstamps the executing session id onto the cancellation-derived context via an unexportedwithSessionOrigin. Both run-entry seams (Run,ResumeApproval) route through it, so normal runs and awaiting-approval resumes attribute identically.ScheduleTool.createreads it when building theScheduleSpec— the single site that assignsOriginSessionID.scheduleArgshas no origin field, so nothing model-supplied has anywhere to enter. An unbound context yields the empty id: no delivery, never delivery to an arbitrary session.port.ScheduleManagerstraight through.Also fixes a second defect of the same class that #482 records:
assets.scheduleOriginBinderwas written by every per-session catalog assembly over one shared struct, so concurrentCreateSessioncalls raced a non-atomic interface field. The field is gone.Engine API (breaking, pre-v1)
Removes
agent.OriginBinder,agent.Deps.OriginBinder, andagent.SessionOriginScheduleManager(constructor + ten methods). Nothing is added — the exported surface net shrinks by fourteen symbols.engine/api/agent.txtregenerated,engine/CHANGELOG.mdclassified Changed perCOMPATIBILITY.mdwith the migration note (delete theDeps.OriginBinderassignment; pass the manager straight to the tool constructors).Nothing exported replaces it: an origin is acquired by running under
Engine.Run, and an out-of-band create is originless by design (ADR 0075 decision #1), which is what the REST/gRPC surface already does. An exported writer would let an embedder name any session as the origin, andvalidateScheduleOriginonly checks that the session exists, not that the caller owns it. ADR 0104 records that if it is ever exported, an ownership check must land first.Tests
TestScheduleTool_ConcurrentSharedEngineRunsDoNotCrossStampforces the interleaving with a provider-blocking rendezvous — run A parks inside the provider until run B has entered — so it fails deterministically on the atomic-pointer implementation rather than racing opportunistically. It bounds both rendezvous points and bails out silently if the test goroutine has already returned, so a catastrophic failure surfaces as a named error instead of a post-completion log panic.The three
TestFireDelivery_Scenario1_*tests now drive the tool directly. One arm changed meaning and is worth a reviewer's eye: the old "unbound context clears a pre-populated forged spec" case exercised the wrapper's overwrite, a seam that no longer exists, so it is now "an unbound tool create yields the empty origin". Narrower, but it is the property that actually exists —OriginSessionIDhas exactly one writer, andprotoToScheduleSpecnever maps the field from the wire.Docs
New ADR 0104 (supersedes ADR 0075's origin-binding mechanism only; the
OriginSessionIDcontract, delivery queue, turn-boundary drain, and note rendering all stand), with a forward pointer to ADR 0100 since that frozen record still names the removed binder.docs/architecture.md,IMPLEMENTATION-NOTES.md, and thecaptureScheduleOwnercomment describe the new mechanism. AC3.3 in the landedschedule-shared-catalogplan named the removed wiring while the test verifying it was reworded — the AC now states the mechanism change explicitly, with its observable claim andverify:line unchanged.Verification
task lint(0 issues across all seven module runs),task test(full suite, incl.apicheckand theengine/archlayering DAG),task docs:check --strict(0 broken links/anchors/orphans), andgo run ./cmd/mecademoprints a complete offline session. Rebased ontoorigin/main.Reviewed by a seven-agent panel across spec / standards / domain axes before this branch was finalised; every ship-blocker-class finding is addressed in this commit.
🤖 Generated with Claude Code