Repository navigation
feat(ledger): record the creating session on session/opened - #11472
Conversation
|
Intent: Make the append-only session ledger carry the one lineage fact it can carry today: a session that another session created through session_create names its creator on its own session/opened entry (parent {slot, sid?}), so a tree of sessions can later be folded from the log instead of from in-memory state. |
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS A resumed-after-restart child appends a second WatchThe re-attach path re-announces the header ( [DESIGN-REVIEWED] 8328ed9 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsBased on my validation, the discovery pass correctly found no grounded candidates. I independently verified the paths where a defect would live:
I could not ground any behavioural defect or rule violation, and I found nothing new to add in Step 2. No findings. [OPUS-REVIEWED] 8328ed9 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The What this change shipsInventory (8 items) — 8 justifiedIntent: Record in each session's append-only crew log which session created it, so the session tree can be read from the logs alone after a restart — ADDITION.
The field has zero readers today by declaration; the reader is tracked in linked issue #11484, and delaying the writer would leave a permanent, unbackfillable hole in every ledger written meanwhile — derived, not speculative. The transcript/ [FIRST-PRINCIPLES-REVIEWED] 8328ed9 |
|
CI note (not a finding on this diff): the two red backend shards, Backend Tests (3.12, 2) and Backend Tests (Windows) (3), fail on the same two tests, test/test_fargate_launch_engine.py::test_engine_satisfies_the_launch_engine_protocol and ::test_signin_handle_has_every_signin_handle_protocol_member (FargateLaunchEngine.begin_signin lacks the login_target keyword the LaunchEngine protocol grew). Both fail identically on main at the merge-base; this PR touches neither file. Coverage Gate fails closed on the shard failure. Fixes are open as #11422 / #11426 / #11432 / #11442; this branch will be rebased once one lands, which re-runs CI. |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
6d3707d to
545405e
Compare
|
545405e to
3d71406
Compare
3d71406 to
0d0bcdc
Compare
|
self-added: yes
|
0d0bcdc to
354b402
Compare
|
Two more shards went red after the comment above, and both are also main-side.
That accounts for all five test reds: #11634 on two shards, #11635 on one, #10964 on one, and one |
e7784f3 to
e6585e0
Compare
|
|
|
CI note (head e6585e0):
The earlier six |
|
CI note (head e6585e0): The same 10 fail on a clean detached checkout of #11632 has landed, so the |
e6585e0 to
f3549e6
Compare
A session another session made through session_create writes parent {slot, sid?} on its session/opened entry: the creator's key from the slot's _created_by and the creator's live ACP session id read at the child's first turn. Recorded on the child because that is the one side that knows both halves; absent on a person's own tab, a fork and a spawn_run subagent, so a fold can tell no creator from creator unknown. The field is declared in the entry-type registry in the same change (parent.slot required, parent.sid optional, undeclared members refused).
f3549e6 to
8328ed9
Compare
|
|
|
|
… the System page A session opened through session_create records its creator on its own session/opened entry (#11472). This adds the reader. crew_log/tree.py folds the first entry of every session log into slot -> parent edges: an orphan and a cycle degrade to root, any opened entry carrying a parent wins and one without never retracts it, the oldest log's word stands. A cached scanner reads one bounded head per log and re-reads only a replaced or removed segment. /api/sessions/memory carries `parent` per session row (slot, sid, the creator's live key, whether the sid resolves to a log), and the System page Sessions table nests a created session under its running creator the way it nests a task, to any depth. Closes #11484
Problem / Motivation
The append-only session ledger (the "crew log") records what a session did, but not who made it. A worker session that a conductor opened through
session_createwrites asession/openedentry identical to a tab a person opened by hand. Nothing in any ledger says "this session exists because that session asked for it", so no tree of sessions can be folded from the log. The only record of that edge today is_created_byon the in-memory slot and the transcript's metadata line, neither of which is the ledger.Why it matters
Session control now lets one session create and drive others, and crew mode will lean on that. A conductor's fan-out is invisible in the record that is supposed to be the source of truth: a reader cannot answer "which sessions did this one spawn" from the ledgers, the System page cannot be made a projection of the log, and a session tree would have to be assembled from a second, in-memory source that is gone after a restart.
What changed (motivation → approach → change)
A reader can now tell from the ledgers alone which session opened which. A created session names its creator in its own
session/openedentry.session/opened.dataon asession_createchildagent, slot, model, cwd, owner, resumedparent {slot, sid?}parentkey at allcrew_log/entry_types.py)parentundeclared, so a caller could not write itparent.slotrequired,parent.sidoptional, other members refusedThe edge is written on the child, because the child is the one side that holds both halves.
session_create(dashboard/session_control.py) stamps three facts on the new slot at mint, before any turn: the creator's key (_created_by), the creator's ACP session id read off the live caller handle (_created_by_sid), and an in-memory witness that this gateway process did the stamping (_lineage_minted). At the child's first turn the chat runner (dashboard/chat_runner.py,_ledger_lineage) passes the two ids to the emitter'son_session_opened(crew_log/emit.py) asparent_slot/parent_sidonly when the witness is set; nothing is looked up live. The sid and the witness are never written to the transcript: that file is editable by an agent's file tools, and the crew log is fenced from those tools precisely so nothing in it can be forged as gateway-authored, socreated_byread back from transcript metadata after a restart still serves the ownership boundary but is never promoted to lineage (dashboard/chat_persistence.py). A child whose gateway restarted between mint and its first turn writes noparent. The creator can never write this edge itself: the child's ACP session id -- the log's unit id -- does not exist yet whensession_createruns, which is the same blocker the emitter spec already records forsubagent/*.The sid is frozen at mint rather than read at the child's first turn because a creator slot can be closed and replaced in between; a live read would cite the replacement's ledger in an entry that is never rewritten. The id is backend-authored, so it is bounded where it is retained:
MAX_ACP_SESSION_ID_LEN(kiro_crew/validation.py, a leaf both the ACP layer and application code may import without crossing the agent-SDK boundary) is the one constant for every store of a backend session id -- the native-child rosters inacp/runtime.pyandacp/session_handle.pynow name it instead of literals -- and an id past it is dropped at mint, never truncated; the sid is optional, so absent is a legal record.flowchart LR subgraph before [Before] P0["creator ledger"]:::ctx C0["child ledger<br/>session/opened"]:::ctx end subgraph after [After] P1["creator ledger<br/>(sid)"]:::ctx C1["child ledger<br/>session/opened<br/>parent {slot, sid}"]:::added C1 - "slot, sid" --> P1 end classDef added fill:#DCFCE7,stroke:#16A34A classDef changed fill:#FEF3C7,stroke:#D97706 classDef removed fill:#FEE2E2,stroke:#DC2626,stroke-dasharray:4 3 classDef ctx fill:#E0F2FE,stroke:#0284C7 linkStyle 0 stroke:#16A34A,stroke-width:2pxLegend: green = added after this PR, blue = unchanged, shown for context.
The child's entry now points at the session that made it, with the id the creator had at mint; the creator's file is untouched.
sidis a citation, not the tree key. A slot outlives its ACP session, so the creator's id names the unit that was live when the child was made; a fold that builds the tree keys it byslot.sidis omitted rather than written empty when the creator had no live handle at mint, and the wholeparentobject is omitted when nobody created the session, so a reader can tell "no creator" from "creator unknown". The three specs (crew-log-core.md,crew-log-emitter.md,session-control.md) state the field, the side it is written from, and why.No projection or UI is built here: the System page tree is the next PR, folded from this field.
Tests
test/test_crew_log_types.py: the canonicalsession/openedexample carriesparent, so the registry suite checks its nested shape; two refusal cases lock inparentwithoutslot(data.parent.slot) and an undeclared member (data.parent.creator).test/test_crew_log_emit.py: five tests -- a created session records{slot, sid}; a creator with no sid is recorded byslotalone; a session nobody created has noparentkey; asidwith noslotnames no creator; a re-attach (resumed=True) writes the creator again.test/test_session_control.py:create_sessionfreezes the caller's ACP session id on the child and sets the mint witness, and the birth metadata carriescreated_bybut never the sid; the frozen value does not follow a replaced creator handle (the mutation guard for the live-read defect); an id pastMAX_ACP_SESSION_ID_LENis dropped at mint; a slot nobody minted in this process has no witness; and_ledger_lineageyields the creator only for a witnessed mint -- restored or hand-set attribution yields nothing, a witnessed mint without a handle yields the slot alone.test/test_member_session_control.py: the recent-session restore path restorescreated_bybut ignores acreated_by_sidfound in the metadata line and leaves the witness unset; a save -> rehydrate round trip through the real serializer writescreated_byand never the sid or the witness.Manual verification
N/A - unit coverage sufficient. The runtime change is one call site passing two slot attributes through;
state.get_slotreturnsNonefor an absent creator andsession_id_ofreturns""for a missing handle, both of which the emitter tests cover as the no-sid and no-parent branches.Related Issues
Part of #11484, which tracks the reader of this field: the session-tree projection and the System page Sessions tab. This PR closes nothing on merge.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)