Repository navigation
fix: derive session lineage and child usage from records - #320
Merged
Merged
Conversation
xxchan
force-pushed
the
fix/session-graph-records
branch
from
October 10, 2026 08:03
4cb61ab to
452b6c9
Compare
This was referenced Oct 10, 2026
This was referenced Oct 10, 2026
Merged
xxchan
added a commit
that referenced
this pull request
Oct 10, 2026
Release OAR and CLI 0.54.0. This PR changes only the two package version fields. **Added: session lineage is in the records** (#312, #320) - New event `session_linked { parent, child, via: "tool_call" }`, carried by the native frame that names the relationship: codex collaboration items, ACP lineage notifications (grok) and OpenCode v2 child attribution. A host that folds the records now gets the same session graph and the same `usage().withChildren` as a live `Session`. - `graphOf(records)` is exported (root, observe and browser entries). `Session.graph()` is the same fold, kept as each record is appended. A live graph starts with its root id; `graphOf` learns the root from its first record. An edge reported many times is in the graph once. - `usageOf(records, sessionId)` derives lineage from the records by default and still takes an explicit graph. Old records without `session_linked` have no edges and no `withChildren`. - grok child ledgers stay native-only, as before: the root's prompt ledger already includes a foreground child's spend. A background child's spend (grok's default) and the root turn grok runs after it are not in `usage()` yet (#325). **Added: a tool phase says when claude is still writing its arguments** (#314, #317) - `RunningPhase` `{ tool, callId }` gains `writing?: true` while a call's arguments stream (`tool_call_input_delta`); the complete input or the call's result clears it. - `phaseLabel(phase, runtimeId?)` names the action when given the runtime: "Preparing command", "Preparing file edit", "Running command", "Reading file". MCP and unclassified tools read "Writing <name> arguments" and "Running <name>". Without `runtimeId` it reads "Running <tool>" as before, or "Writing <tool> arguments". - `toolActionLabel` takes a `"writing"` state. **Added: page fetches and subagent calls are classified** (#321, #322) - New `ToolActionKind` `fetch`: claude `WebFetch` and cursor `webFetch`, worded "Fetching page" and "fetched 2 pages". They were `web`, worded as web searches. `web` now means a web search only. - New `ToolActionKind` `subagent`: claude `Agent` (and its alias `Task`, under which a call is recorded as `Task`) and opencode `subagent`, worded "Running subagent" and "ran 2 subagents", with the subagent's task (`description`) as `detail` and `description`. **Fixed** - `groupToolActivity` no longer parses every call's input on each grouping: a call's kind depends only on its runtime and tool name (#318, #319). A host that groups a live turn on every record pays far less: 400 calls went from 2,160 ms to about 300 ms. - pi: the model catalog's `providers()[].configured` is true from the start for a provider with a key or login in `auth.json`, not only after `refresh()` (#291, #323). An environment key still counts only after `refresh()`. As in pi itself, `configured` means the provider has an entry, not that its key works. **Behavior changes** - New event kind `session_linked`, and new `ToolActionKind`s `fetch` and `subagent`. Hosts with an exhaustive `switch` or `Record` need the new cases. - Counts that grouped page fetches under `web` now show them as `fetch`; claude `Agent`/`Task` and opencode `subagent` calls count as `subagent`, not `other`. - An incremental `SessionView` checkpoint must keep `sessionGraph` and `usageBySession`; replay the raw records when upgrading an older checkpoint. - Adapter authors: put the event `kernel.link(edge)` returns in the source frame's events. `kernel.node()` is removed. Validation: every PR passed all 17 checks on its final head. #317 differed from its CI tree only in the version fields from the 0.53.0 release, and #320's merged tree equals its CI tree. #319, #323 and #322 each merged after typecheck, lint and the full test suite passed locally on top of the PRs merged before them, and each merged tree equals that verified tree. Lookout verified each with no account: #320 against real codex 0.162.0 and grok 1.0.50 with a mock provider and OpenCode v2 2.0.26 on a free model (the live graph equals `graphOf` of the records after every one of 222 records, and replayed usage equals live); #317 and #322 against the real claude CLI 2.1.292 with a mock provider, including `WebFetch`, `Agent` and `Task`; #319 with identical groups to 0.53.0 on recordings of 1,487 and 4,917 records; #323 with temporary `auth.json` files and the network blocked. After this PR passes CI and merges, tag its exact squash commit as `v0.54.0` to trigger npm trusted publishing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
xxchan
added a commit
that referenced
this pull request
Oct 10, 2026
Grok starts a root follow-up after a background subagent finishes, without an ACP `session/prompt` reply. Its usage was therefore omitted. Count the independent `subagent-completed-*` root terminal ledger once per native event id, using the same accumulator as ordinary prompt replies so later replies retain it. Duplicate native frames remain available. Opening history stays native-only. Track notification arrival against the matching successful `session/new`, `session/resume` or `session/load` answer on the decoded wire, before the SDK can delay notification callbacks. Remember historical identities, including explicit replay reports, so late duplicates cannot become new bills. The messages and their recorded native payloads are unchanged. Child accounting remains partial. The native probe demonstrates that `will_wake: true` can accompany either an inclusive or exclusive parent ledger; source inspection also rules out inferring inclusion from completion-notification order. Keep child ledgers native-only and document the remaining late-child undercount instead of risking double counting. Evidence and a repeatable probe: [Grok background usage report](https://github.com/botiverse/oar/blob/3805905b653afb0ad609eb0d4d107edf65341ef4/experiments/grok-background-usage-2026-10-10.md). Includes three recorded completion orders, duplicate delivery and JSON replay, opening-history regressions, ownership and partial-ledger boundaries. All provider calls use isolated local mocks; no account or quota. Validation passed: `CI=1 pnpm run check` (1,622 tests plus mock behavior) and build on the final code, based on main `e5793f9`. Claude/Codex/Pi/Pi Durable behavior suites passed; Pi was rechecked after incorporating the new main changes. Nine applicable Grok vendor tests and the three-scenario native Grok 1.0.50 probe passed after the wire-boundary revision. Twenty-seven regressions cover accounting and opening boundaries. The first callback-based gate failed on repeat; the report records why it was replaced with wire-order tracking. Fixes #325 under the agreed scope: count independent root follow-ups and document the child ledger gap. This is a separate follow-up to #320, outside the 0.54.0 release batch. --------- Co-authored-by: Otter <[email protected]>
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.
Replaying a session's records lost the native parent/child graph, so hosts such as Ferry could not reproduce
Session.usage().withChildren. Lineage now travels on the native frame that establishes it, and live queries and replay use the same graph and token folds.session_linked { parent, child, via: "tool_call" }for Codex collaboration items, ACP lineage notifications and OpenCode v2 child attribution.graphOf(records)is exported through the observe, root and browser entries. The kernel updates the same graph fold as each record is appended, using a Set for node ids;graph()returns the retained value without rescanning the log. Repeated facts retain their original frames but produce one edge.usageOf(records, sessionId), retaining its explicit graph override. SessionView keeps every session's latest totals, so reports before lineage, nested descendants and repeated cumulative figures contribute exactly once. Unrelated session ids never imply a child, and the usage cursor includes the frame that establishes relevant lineage even when another session reports it.withChildren. Grok's root ledger already includes child spend: its child ledgers remain native-only and are not added again. Correct the contrary SessionUsage comment and attribution spec, linked to the existing Grok evidence and regression.Host impact: exhaustive event switches need a
session_linkedcase. Incremental SessionView checkpoints must retainsessionGraphandusageBySessionwith its nested Maps; replay raw records when upgrading checkpoints. The existing rootusageByAgentandusageTotalfields remain available. Adapter authors put the event returned bykernel.link(edge)in the source frame; out-of-bandkernel.node()is removed. The live graph still starts with the known root id.graphOf([])stays empty and learns the root from its first recorded appearance; this initial seed is the only information supplied outside the records.Validation: full check (1,590 tests) and build on main aa8f5e3, including #313, #315 and #317; all five behavior backends; 35 Codex native tests. Added regressions cover JSON persistence, live/replay equality after each append, synchronous source-frame observation, incremental and flat-event views, graph and checkpoint immutability, late edges, repeated reports, nested/shared descendants, cycles, unknown totals and explicit graph overrides. Codex's actual Session path, recorded Grok wire shapes and the OpenCode v2 child fixture all verify replay against live results. All runtime tests use scripted providers, with no real-account quota.
Closes #312.