Repository navigation
feat: Attribute a headless agent run to the session that started it - #1995
Conversation
…r its parent Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
Name the receiver of chainSessionLocked, the model test file, and the width of the hidden-TITLE test. Record that the gate format and vet steps pass on the base. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
Add parentSession to the session summary fields, and parentSession and parentProject to the event fields. The projects item now says that each label is the parentProject of the event when it has one. Part of rossoctl#1991. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
Attribution.ChainProc is the Proc.Key of the chain entry whose claim gave ChainSession. It is "" when ChainSession is "". Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
The pipeline context gets SetParent, with its own write-once flag, as SetProject has. Each session event gets ParentSession and ParentProject, and RollupProject gives the parent's project when the row has one. The event builders copy the two values from the context. The praxis gateway does not set them, so its list of unset fields names them. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
The shape guard on SessionEvent counts 38 fields now. ParentSession and ParentProject are timeline data, so the projection keeps them, and the projection test asserts it. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
The usage ring, the cost ledger and the session summary's projects now read SessionEvent.RollupProject. So a run that another session started counts under the project of that session. The session summary also carries parentSession: the first non-empty parent of the session's events. The store, its rekey and SummaryFold use one rule (applyParent), which keeps none on the default and pending buckets. session.json keeps the field, and a resumed session keeps the parent of its earlier history. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
The forward proxy sets the parent session and the parent project on the pipeline context. The parent applies when the chain session is not the row's own session. The parent project is computed one time for each connection. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
The sessions pane puts "↳ " in front of the title of a session that another session started. With no TITLE column, the SESSION cell has the mark. The mark width is in columns, not bytes. The session header adds " · started by <id>", with the parent id sanitised and cut to its first 8 runes, because the id comes from a client header. Part of rossoctl#1991. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
Fixes review: sessionEventWire.ParentSession and ParentProject refused a non-string value, so ingest, archive and agentop event decodes dropped the line Fixes review: SessionSummary.ParentSession refused a non-string value, so agentop's session list failed Fixes review: foldJSON.ParentSession refused a non-string value, so the archived fold of that session was lost Files: - cmd/agentop/tui/session_metadata.go - core/model/session.go - core/model/session_source_test.go - core/session/fold.go - core/session/fold_imported_test.go - core/session/history.go - core/session/summary.go Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 36 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
A headless run's live ledger rows have the parent's project. Its transcript turns have the run's own project. The importer matched a turn to a live row by minute and project, so it did not find the live row and counted the turn a second time. This occurs when the archive no longer holds the session but the ledger still holds its rows. The ledger row now also keeps the run's own project as ownProject, when the row has a parent project. It is part of the row key. The importer marks a live row under both projects. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
When A starts B and B starts C, the parentSession of C is A, not B. agentop showed "started by A" for C. The header now shows "under A", and the comments and docs/session-api.md say "topmost". The project item in the doc also says that group=project uses parentProject when it is set. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The parent attribution reuses the existing chainSessionLocked walk. agentRootIndexLocked stops at the shell between the two claude processes, so for the target case (claude -p started from a Claude Code session's Bash tool) the topmost claim is the parent's. The at.ChainSession == sid guard keeps a tool process on its own session. The pin is first-call-wins, like SetProject. Pending rows keep the parent after a rekey, and the history fold keeps the earliest value. I found nothing that blocks merge. There is one suggestion about extra ledger rows when the run and its parent share a project, and two small nits.
I checked:
- Decoder leniency (head vs base): the new
parentSession/parentProjectfields onSessionEvent,SessionSummaryandfoldJSONareLenientString. Probed on head:{"parentSession":5,"parentProject":{"a":1},"project":"x"}decodes with no error to empty parents and keepsproject.[1],trueandnullbehave the same.Row.OwnProjectis a plainstring, but the only thing that decodes it is the ledger's own day file, line by line, so it is not client input. - Importer double count (9c762b2): a live row with
OwnProjectnow also marks{minute, ownProject}. A transcript turn, keyed on its own project, therefore matches the live row. - agentop: the table truncates with
runewidth.Truncate, which counts columns, solipgloss.Width(mark)is the right budget. - Local runs:
go vet,go teston attribution, cost/..., forwardproxy, listener/internal/..., model, pipeline, session/... and sessionapi, andgo test ./...in cmd/agentop all pass, except failures that also happen onmainin this sandbox: Havana DST fixtures in cost/ledger and cost/usage, root-permission tests in session/archive, and 2 in the cmd/agentop root package.gofmt -lis clean.
Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (core attribution/forwardproxy/session/cost/model/pipeline, cmd/agentop), Rust (praxis filters list), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 12 commits, all signed-off: yes
CI status: passing so far; Go CI (core, agentop, cortex), Pre-commit and a few script tests were still pending when I reviewed
| Project: projectRowLabel(e.RollupProject()), | ||
| Counts: usage.Counts{Requests: 1}, | ||
| } | ||
| if e.ParentProject != "" { |
There was a problem hiding this comment.
suggestion: When a headless run is in the same repo as its parent, which is probably the common claude -p case, OwnProject ends up equal to Project. That row then gets a different key from the parent's own rows in the same minute: (p, "") vs (p, p). Totals stay right, but each such minute gets one more distinct row, and that counts against the 64-row maxLabelsPerMinute cap. The importer gains nothing from it either, because r.Project already matches. You could set OwnProject only when the two labels differ:
if own := projectRowLabel(e.Project); e.ParentProject != "" && own != r.Project {
r.OwnProject = own
}| // With no TITLE column, the SESSION cell has the mark. | ||
| mark, markW := "", 0 | ||
| // An imported session's title starts with "(*) ", and a session that another session | ||
| // started with "↳ ". Plain text, not dim: the table cuts a cell by its bytes, and a |
There was a problem hiding this comment.
nit: This block comment says "the table cuts a cell by its bytes", but the new line below says markW is "columns, not bytes", and table does truncate with runewidth.Truncate, which counts columns. I think the comment is about style escape bytes being cut, not about how width is measured. Could you reword it so the two comments don't seem to contradict each other?
| - **`parentSession`** — the topmost session above this session's agent, for a | ||
| headless run (for example `claude -p`) that another session's process | ||
| started. When A starts B and B starts C, it is A on C, not B. It is the first | ||
| non-empty `parentSession` of the session's events. Absent on `default` and on pending buckets. Rows recorded before this |
There was a problem hiding this comment.
nit: This line is much longer than the ~80-column wrap the rest of the list uses.
PR #1984 added a store argument to the eventually test helper and changed every caller that existed then. PR #1995 added parent_test.go on a base without #1984, so its two calls use the old signature. Each PR passed CI alone. After both merged, go vet on main fails: parent_test.go:146:24: not enough arguments in call to eventually Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
What changed
A
claude -prun that another session starts now goes into the project of the session that started it. agentop shows which session started the run.core/attribution:Attribution.ChainProcnames the process that holdsChainSession.Memo.ParentProjectmemoises the parent project once for each connection.core/pipeline,core/model: the context and each session event carryparentSessionandparentProject.SessionEvent.RollupProject()givesParentProjectwhen it is set, elseProject. A non-string value in the wire decodes as empty.core/listener/forwardproxy:parentForsets the parent on hydrated rows and on refusal rows. It sets no parent when the chain session is the row's own session, on the trusted path, or when process lookup is off.core/session,core/cost: the sessionProjects, the ledgerprojectcolumn and/v1/usage?group=projectuseRollupProject(). A ledger row with a parent project also keeps the run's own project asownProject, part of the row key. The transcript importer matches a turn to a live row on it, so it does not count a headless run's turn a second time. The session summary hasparentSession(the first non-empty value wins). The default bucket and pending buckets never get it.cmd/agentop: the sessions pane marks a child session with↳. The event screen header showsunder <first 8 runes of the parent id>, aftersanitizeLabel. The parent is the topmost session above the run: when A starts B and B starts C, C shows A.praxis/filters: the 2 new fields are inNOT_SET_IN_PRAXIS_MODE, next toproject.docs/session-api.md: describes the 2 fields.No rule in
core/attribution/process.gochanges. The session that a row goes into does not change. Only the project that the row rolls up to changes. There is no backfill of old data.How it was tested
The plan's gate passed on the tip of this branch:
go vetoncore,cmd/cortexandcmd/agentop, all withGOWORK=off.go test -raceon the changedcorepackages and on all ofcmd/agentop(shards with-race, and the sub-packages).gofmt -l core cmd/cortex cmd/agentopis empty.cargo fmt --checkandcargo test --locked -p cortex-praxis-filters. These passed with rustup's toolchain first inPATH.pre-commit runon the range.New tests cover the 5 review-focus cases in the plan. Examples: a tool process on the parent session gets no parent, pending rows get the parent and keep it after the rekey, and
ProjectOfruns once for each keep-alive connection.Size
core/pipeline/testdata/session-event.golden.json(2, written by-update).Review findings that were not fixed
All are minor.
out.ChainSession, i := …. The code usesvar i intand then=, because:=cannot assign to a struct field. The behavior is the same.core/sessionapi/summary_test.go,TestSummarizeEvent_DropsPayloadsKeepsTimelineFields: the new parent check is between the comment "// source is kept: ..." and the source check. The comment now labels the wrong check. Tests are not affected.parentForincore/listener/forwardproxy/identity.go: 2 branches have no test. (a)s.ProjectOf == nil || m == nilmust give the chain session with an empty project. (b) When no chain entry hasKey() == at.ChainProc, the project must be "" andProjectOfmust not run.Memo.ParentProjectincore/attribution/conn.go: it keeps one value for each connection. It does not record whichChainProcgave the value. IfChainProcchanges on one keep-alive connection, the later rows keep the first ancestor's project.Memo.Projecthas the same behavior, and plan Decision 4 asks for this shape.markWfromlen(mark)tolipgloss.Width(mark)incmd/agentop/tui/sessions_pane.go. A change back tolen()would make the budget 2 columns smaller, and no test would fail.TestSessionHeader_StartedBySanitisesdoes not prove the order "sanitise, then cut to 8 runes". The code uses that order.For a human after review
Needs: T1 to T5 merged and installed on a laptop.
claude -p --model haiku "say hi"in a temporary git directory (for example/private/tmp/parenttestaftergit init).curl -s localhost:47601/v1/sessions | jq '.[] | select(.parentSession != null) | {id, parentSession, projects}'. Expected: the child session hasparentSessionset to the parent's id andprojectsholds the parent's project./private/tmp/parenttest, and the sessions pane shows↳on the child. Its event screen header saysunder <first 8 of the parent id>.Part of #1991. The live check above closes it.
Assisted-By: Claude (Anthropic AI) noreply@anthropic.com