Skip to content

Fix per-leaf token capture: sum session branch instead of getSessionStats - #138

Merged
pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/token-capture-branchspend
Jul 17, 2026
Merged

pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/token-capture-branchspend

Conversation

@pdettori

Copy link
Copy Markdown
Member

Summary

Fixes the Phase-3 per-leaf token capture (added in #137), which silently recorded nothing.

realProduceSolve called session.getSessionStats() to read cumulative usage after the solve. That method sums message.usage non-defensively, and on the pinned pi build it throws at runtime — the throw is swallowed by the best-effort try/catch, so capture.usage stayed undefined and usage never appeared on the solved result. In the costed pilot on OCP 4.20, patches captured fine but usage.jsonl came back empty (empty, not zero-valued — which is what ruled out a zero return and pointed at a throw).

Fix

Replace getSessionStats() with the same defensive branch sum that budget-voter.ts:branchSpend already uses successfully in this harness: iterate sessionManager.getBranch() and add usage only for entries that are assistant messages carrying a usage field, keeping the per-field breakdown (input/output/cacheRead/cacheWrite) needed for cost pricing. sessionManager is already in scope; capture stays best-effort. One-file change (harness/src/run-leaf.ts, +13/-4).

Validation

Assisted-By: Claude Code

…tats

The Phase-3 token capture (PR rossoctl#137) called session.getSessionStats() to read
cumulative usage, but that method accesses message.usage non-defensively and
throws at runtime on the pinned pi build — swallowed by the best-effort
try/catch, so usage was silently never captured (usage.jsonl empty in the
costed pilot, though patches captured fine).

Replace it with the same defensive branch-sum that budget-voter.ts:branchSpend
already uses successfully in this harness: iterate sessionManager.getBranch()
and sum usage only for entries that are assistant messages with a usage field,
keeping the per-field breakdown (input/output/cacheRead/cacheWrite) needed for
cost pricing. sessionManager is already in scope. Still best-effort.

Surfaced by the authoritative-run costed pilot on OCP 4.20.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori merged commit d0b2cea into rossoctl:main Jul 17, 2026
10 checks passed
@pdettori
pdettori deleted the fix/token-capture-branchspend branch July 17, 2026 01:44
webchang added a commit to webchang/moca that referenced this pull request Nov 23, 2026
…octl#338)

CodeQL on PR C (rossoctl#137 js/polynomial-redos, rossoctl#138 and rossoctl#139
js/file-access-to-http, relay-release.ts:62/65/67):

- The listener's base URL loses its trailing slashes in a loop
  (releaseUrl), not with /\/+$/, which backtracks on many slashes.
- The release URL and bearer now travel as the control plane's other
  secrets do: configFromEnv reads them into the config
  (CpConfig.relayRelease, every profile, with the same boot checks), and
  the request that needs them builds the releaser from deps.config
  (releaserOf), as the operator inference token reaches its upstream.
  Before, depsFromEnv built a releaser that closed over values read from
  withCredentials' merged env, whose dynamic property writes of file data
  CodeQL counts as tainting every value read from it, the URL included.
  deps.relayRelease stays as the test seam.

A local CodeQL 2.27.5 run (security-extended, as CI) over the control
plane reports the three alerts at the previous head and none here.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
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