Skip to content

feat: Attribute a headless agent run to the session that started it - #1995

Merged
huang195 merged 12 commits into
rossoctl:mainfrom
huang195:feat/parent-session-1991-pP1
Nov 19, 2026
Merged

huang195 merged 12 commits into
rossoctl:mainfrom
huang195:feat/parent-session-1991-pP1

Conversation

@huang195

@huang195 huang195 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What changed

A claude -p run 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.ChainProc names the process that holds ChainSession. Memo.ParentProject memoises the parent project once for each connection.
  • core/pipeline, core/model: the context and each session event carry parentSession and parentProject. SessionEvent.RollupProject() gives ParentProject when it is set, else Project. A non-string value in the wire decodes as empty.
  • core/listener/forwardproxy: parentFor sets 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 session Projects, the ledger project column and /v1/usage?group=project use RollupProject(). A ledger row with a parent project also keeps the run's own project as ownProject, 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 has parentSession (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 shows under <first 8 runes of the parent id>, after sanitizeLabel. 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 in NOT_SET_IN_PRAXIS_MODE, next to project.
  • docs/session-api.md: describes the 2 fields.

No rule in core/attribution/process.go changes. 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 vet on core, cmd/cortex and cmd/agentop, all with GOWORK=off.
  • go test -race on the changed core packages and on all of cmd/agentop (shards with -race, and the sub-packages).
  • gofmt -l core cmd/cortex cmd/agentop is empty.
  • cargo fmt --check and cargo test --locked -p cortex-praxis-filters. These passed with rustup's toolchain first in PATH.
  • pre-commit run on 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 ProjectOf runs once for each keep-alive connection.

Size

  • Counted: 875 lines (843 added, 32 removed).
  • Exempt: 219 lines. These are the plan document (217) and core/pipeline/testdata/session-event.golden.json (2, written by -update).

Review findings that were not fixed

All are minor.

  • T1: the plan's Step 3 shows out.ChainSession, i := …. The code uses var i int and then =, because := cannot assign to a struct field. The behavior is the same.
  • T2, 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.
  • T2: the field-count guard in the sessionapi summary test (36 to 38), with a projection assertion, is outside the plan. It is necessary.
  • T3, parentFor in core/listener/forwardproxy/identity.go: 2 branches have no test. (a) s.ProjectOf == nil || m == nil must give the chain session with an empty project. (b) When no chain entry has Key() == at.ChainProc, the project must be "" and ProjectOf must not run.
  • T3, Memo.ParentProject in core/attribution/conn.go: it keeps one value for each connection. It does not record which ChainProc gave the value. If ChainProc changes on one keep-alive connection, the later rows keep the first ancestor's project. Memo.Project has the same behavior, and plan Decision 4 asks for this shape.
  • T5: no test locks the change of markW from len(mark) to lipgloss.Width(mark) in cmd/agentop/tui/sessions_pane.go. A change back to len() would make the budget 2 columns smaller, and no test would fail.
  • T5: TestSessionHeader_StartedBySanitises does 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.

  1. Live check (issue Tests item 6). From a Claude Code session, run claude -p --model haiku "say hi" in a temporary git directory (for example /private/tmp/parenttest after git init).
  2. curl -s localhost:47601/v1/sessions | jq '.[] | select(.parentSession != null) | {id, parentSession, projects}'. Expected: the child session has parentSession set to the parent's id and projects holds the parent's project.
  3. In agentop: the agents pane shows no new project row for /private/tmp/parenttest, and the sessions pane shows ↳ on the child. Its event screen header says under <first 8 of the parent id>.
  4. Close Attribute a headless agent run to the session that started it #1991.

Part of #1991. The live check above closes it.

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

…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>
@huang195
huang195 requested a review from a team as a code owner November 19, 2026 14:51
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4bf3036a-4597-42f8-abc7-69ee4a0c8192
Commits

Reviewing files that changed from the base of the PR and between 9bf0739 and 8324af7.

Files selected for processing: 41

  • cmd/agentop/tui/app.go
  • cmd/agentop/tui/imported_test.go
  • cmd/agentop/tui/session_metadata.go
  • cmd/agentop/tui/sessions_context.go
  • cmd/agentop/tui/sessions_pane.go
  • cmd/agentop/tui/sessions_title_test.go
  • core/attribution/attribution.go
  • core/attribution/attribution_test.go
  • core/attribution/conn.go
  • core/attribution/process.go
  • core/cost/ledger/project_test.go
  • core/cost/ledger/row.go
  • core/cost/ledger/store.go
  • core/cost/ledger/writer.go
  • core/cost/usage/project_test.go
  • core/cost/usage/usage.go
  • core/listener/forwardproxy/identity.go
  • core/listener/forwardproxy/parent_test.go
  • core/listener/forwardproxy/websocket.go
  • core/listener/internal/sessionevent/sessionevent.go
  • core/listener/internal/sessionevent/sessionevent_test.go
  • core/model/session.go
  • core/model/session_source_test.go
  • core/model/session_wire_test.go
  • core/pipeline/attributed.go
  • core/pipeline/attributed_test.go
  • core/pipeline/context.go
  • core/pipeline/session_golden_test.go
  • core/pipeline/testdata/session-event.golden.json
  • core/session/fold.go
  • core/session/fold_imported_test.go
  • core/session/history.go
  • core/session/importer/importer.go
  • core/session/importer/importer_test.go
  • core/session/projects_test.go
  • core/session/store.go
  • core/session/summary.go
  • core/sessionapi/summary_test.go
  • docs/session-api.md
  • docs/superpowers/plans/2026-11-19-parent-session-1991.md
  • praxis/filters/src/record/line.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 19, 2026
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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/parentProject fields on SessionEvent, SessionSummary and foldJSON are LenientString. Probed on head: {"parentSession":5,"parentProject":{"a":1},"project":"x"} decodes with no error to empty parents and keeps project. [1], true and null behave the same. Row.OwnProject is a plain string, 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 OwnProject now 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, so lipgloss.Width(mark) is the right budget.
  • Local runs: go vet, go test on attribution, cost/..., forwardproxy, listener/internal/..., model, pipeline, session/... and sessionapi, and go test ./... in cmd/agentop all pass, except failures that also happen on main in 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 -l is 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 != "" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread docs/session-api.md
- **`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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This line is much longer than the ~80-column wrap the rest of the list uses.

@huang195
huang195 merged commit 0ac29b9 into rossoctl:main Nov 19, 2026
40 checks passed
@huang195
huang195 deleted the feat/parent-session-1991-pP1 branch November 19, 2026 15:38
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 19, 2026
huang195 added a commit that referenced this pull request Nov 19, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Attribute a headless agent run to the session that started it

2 participants