Skip to content

feat(parser): capture provider-recorded session lineage (CB-1 slice 1) - #1140

Merged
iamtoruk merged 1 commit into
mainfrom
feat/session-lineage-capture
Aug 25, 2026
Merged

iamtoruk merged 1 commit into
mainfrom
feat/session-lineage-capture

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

First slice of CB-1 from the approved Teams boundary spec: the lineage evidence the parsers already see stops being discarded.

  • Optional lineage on the parsed session model: { parentSessionId?, role: root|child, evidence: 'provider-recorded' } - strictly provider-recorded, no inference, absent when no evidence exists (never an 'unknown' value).
  • Claude: populated from the agent transcript's own provider-written parent reference (two-sided when the parent's toolUseResult.agentId survives, still valid one-sided when compaction dropped it).
  • Kimi Code: subagents nested under the parent session directory are provider-recorded children; the relationship now survives instead of being folded away silently.
  • Persisted through the session cache (round-trip tested); claude + kimicode parse versions bumped per repo convention for the one-time re-derive.
  • Money invariant pinned by test: all report totals byte-identical with lineage present vs absent - this PR adds metadata and changes no aggregation, folding, or display.

41 new tests; full suite 3705 green; tsc clean. Built by twin MiniMax-M3 builders with a MiniMax verifier comparison (winning candidate), validated independently. Wire fields and folding are later steps (CB-2/3); nothing here touches sync.

Baseline motivating this: docs/baselines in codeburn-teams - 5.1% of sessions carry direct lineage but 76% of 90-day spend.

Wire the SessionLineage field on SessionSummary and CachedFile. The
relationship is captured ONLY when a provider writes it on disk in a
durable form: a child file that names its parent (Claude's
transcript-internal sessionId on a sidechain; Kimi Code's state.json
agents[<id>].parentAgentId for any non-main agent), or a parent file
whose spawn / child manifest names the children (Claude's
agentSpawnLinks; Kimi Code's state.json agents map listing any non-main
entry). The brief forbids inference from time adjacency or directory
layout, so a parent whose only evidence is the child file living under
its directory does not yet qualify, and stays lineage-less.

Per provider:
- claude: child (parentSessionId present) or root (agentSpawnLinks
  non-empty). Captured at install time and through the append-merge in
  scanProjectDirs, where lineage is sticky and cached-first.
- kimicode: child (parentAgentId === 'main') or root (sibling non-main
  entry alongside the main agent). state.json is read by
  kimicodeLineageForSource, called from the per-provider install path.

Bump PROVIDER_PARSE_VERSIONS for both providers to session-lineage-capture-v1
so already-cached sessions gain the new field on the next cold parse
(env fingerprint change forces the re-parse; the field is purely
additive, no cost / token / call total moves).

Invariant: byte-identical report totals with and without the field.
The new parser-lineage-capture test asserts this on a Claude corpus
(parent + two children) and covers Claude two-sided linkage, Claude
one-sided (child file names parent while parent's spawn result was
compacted away), Kimi Code nested subagent (child and root variants),
no-evidence (no lineage field at all, not 'unknown'), and the cache
round-trip across a warm-disk reload.
@iamtoruk
iamtoruk merged commit d4ed055 into main Aug 25, 2026
15 checks passed
@iamtoruk
iamtoruk deleted the feat/session-lineage-capture branch August 25, 2026 12:31
iamtoruk added a commit that referenced this pull request Aug 25, 2026
CLI-only patch: cold-start input responsiveness (#1141, fixes #1139),
provider-recorded session lineage capture (#1140), disk-persisted
status snapshot with fail-closed save gate (#999), mise Spotlight
launch fix (#1138). Apps stay 0.9.21; payloads add-only, contract
holds.
iamtoruk added a commit that referenced this pull request Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant