Repository navigation
Fix per-leaf token capture: sum session branch instead of getSessionStats - #138
Merged
Merged
Conversation
…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]>
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]>
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.
Summary
Fixes the Phase-3 per-leaf token capture (added in #137), which silently recorded nothing.
realProduceSolvecalledsession.getSessionStats()to read cumulative usage after the solve. That method sumsmessage.usagenon-defensively, and on the pinned pi build it throws at runtime — the throw is swallowed by the best-efforttry/catch, socapture.usagestayed undefined andusagenever appeared on the solved result. In the costed pilot on OCP 4.20, patches captured fine butusage.jsonlcame 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 thatbudget-voter.ts:branchSpendalready uses successfully in this harness: iteratesessionManager.getBranch()and add usage only for entries that are assistant messages carrying ausagefield, keeping the per-field breakdown (input/output/cacheRead/cacheWrite) needed for cost pricing.sessionManageris already in scope; capture stays best-effort. One-file change (harness/src/run-leaf.ts, +13/-4).Validation
getSessionStatswith the expectedtokensshape, yetusage.jsonlwas empty → the non-defensive access threw.branchSpendis the proven-working pattern in the same codebase.:latest, a one-leaf re-pilot confirmsusage.jsonlpopulates and yields the per-leaf token cost. Items 1–2 from Authoritative-run readiness: leaf timeout, setup-reliable curve rep, per-leaf token capture #137 (transport-robust capture, status-exclusion + health tally) were already validated live — real haiku patches captured,health=5/6on the pilot.Assisted-By: Claude Code