Skip to content

feat(run-claude-cli): record per-leg token usage and rate-limit windows, warn near a limit - #889

Merged
kyle-sexton merged 2 commits into
mainfrom
feat/lane-usage-windows
Oct 25, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
feat/lane-usage-windows

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Refs: #885

Summary

The owner approved an early warning before a lane's subscription runs out (W7, 2026-10-25, from the Lane Funding work in melodic-software/claude-code-plugins). Today the launcher drops every rate_limit_event except rejected (classify.cjs limitStopFrom), and the lane-outcome record carries no token counts. So nothing warns before a stop, and no per-leg load figure reaches the record. This PR adds both, read from the credential-scanned log.

This covers the tokens item of #885. It does not cover that issue's durationMs or run-link items, so the issue stays open. #885 lists "usage percentages" as out of scope. The W7 decision on 2026-10-25 brings window utilization into the record, so this PR does that.

Fix

  • run-claude-cli writes rate_limits into each leg's scanned log record. For each documented window (five_hour, seven_day, seven_day_opus, seven_day_sonnet, overage) it holds the highest utilization seen during the leg, rounded to 2 decimals, plus the newest event's resets_at and status. A window whose events never carry a utilization has none recorded, never 0. The log already held token usage.
  • If any window has status allowed_warning or rejected, or utilization of 0.70 or more, the launcher writes one ::warning title=run-claude-cli usage:: annotation. It names the leg's secret (never its value), each qualifying window, its utilization, status and reset. The annotation is written after the ::stop-commands:: block ends and before a lane-class failure ends the step.
  • report-lane-outcome takes a new optional log-file input. It re-checks every value in the log against closed patterns, then adds usage (input, output, cacheRead, cacheCreation) and windows to the lane-outcome record. These values come from that log only, never from the execution file. Intake triage and pr-review-cli pass the input at all four call sites.
  • The record stays v: 1, because new fields are additive under docs/lane-outcome.md § Compatibility. The schema and doc now describe both fields. A record over 1,024 characters drops models first, then usage, then windows. No new legacy key=value tokens are added.

Verification

  • node --test .github/scripts/*.test.cjs: 709 pass, 0 fail.
  • node --test .github/actions/report-lane-outcome/*.test.cjs: 84 pass, 0 fail. node --test .github/actions/run-claude-cli/*.test.cjs: 75 pass, 0 fail. The new tests cover each window's max utilization and newest status, forged log values being dropped, schema validation, the worst-case 1,024-character drop order, the warning threshold (0.69 gives no warning, 0.70 warns), and the warning's position after the stop-commands block.
  • Mutants were killed: a 0.71 threshold, inverted max/min, and a swapped drop order each turned a test red. actionlint passes on both edited workflows, and markdownlint-cli2 passes on the doc.
  • Left out: a live run against a real subscription. Each rate_limit_info field is read in both forms, camelCase (rateLimitType, resetsAt, as in the TypeScript SDKRateLimitEvent) and snake_case (rate_limit_type, resets_at, as in the Python RateLimitInfo), with a test for each. Neither form has yet been seen in a real CI stream.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits October 25, 2026 17:34
…ws, warn near a limit

The launcher's credential-scanned log now records, per leg, each
subscription rate-limit window's highest utilization, newest reset and
last status from stream-json rate_limit_event messages, beside the token
usage it already kept. report-lane-outcome takes that log as a new
log-file input and adds usage and windows to the lane-outcome record,
read from the log only, never the execution file. A window at
allowed_warning or rejected, or at 0.70 utilization or more, writes one
warning annotation naming the leg's secret after the stop-commands block.

Fields are additive, so the record stays v1 (docs/lane-outcome.md,
Compatibility). Past 1,024 characters the record drops models, then
usage, then windows.

Co-authored-by: Claude Opus 5.5 <[email protected]>
… snake_case

python.md documents RateLimitInfo in snake_case (rate_limit_type,
resets_at) while the TypeScript reference and the existing reads use
camelCase, and no real CI stream has shown which the CLI emits. One
normalizer now reads each field in either form for both the window
record and the limit-stop reset, so a wrong guess no longer drops the
data silently. A test pins that a rejected window below 0.70 gets the
usage warning line.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 25, 2026 22:54
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-25T22:54:46.411482Z da31296 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 2m 9s —— View job


Security review complete

  • Gather context (diff, changed files, PR description)
  • Review report-lane-outcome changes (classify.cjs, action.yml) for credential/log handling
  • Review run-claude-cli changes (lane.cjs, action.yml) for warning annotation / secret exposure
  • Review workflow call-site changes (intake-triage.yml, pr-review-cli.yml)
  • Review schema/doc changes
  • Adversarial validation of candidate findings
  • Post final summary

No security issues found in this PR.

What was checked:

  • readLegLog (classify.cjs) re-validates every value it pulls from the credential-scanned JSONL log against closed patterns (fraction() for 0–1 utilization, Number.isSafeInteger for token counts, ISO_PATTERN for timestamps, and an explicit status/window allowlist) before it reaches the lane-outcome record, so a forged or tampered log line can only degrade to null fields, never inject an unexpected value.
  • The new ::warning usage:: annotation (lane.cjs) is built only from already-sanitized enum/numeric values (record.secret is the secret's name, derived from a KEBAB_PATTERN-validated role plus a fixed suffix — never the secret's value or free-form input) and is written only after the existing holdsCredential scan on the serialized log passes, and only after the ::stop-commands:: block has ended — so it can't carry a credential and can't be swallowed as a stop-command.
  • log-file flows from inputs.log-file into an env: var (LOG_FILE) consumed only as a fs path argument inside actions/github-script, never interpolated into a shell run: block, and at all three call sites (intake-triage.yml, pr-review-cli.yml) it's wired straight from the preceding run-claude-cli step's own output — not from any user/PR-controlled input.
  • Schema/doc changes (schemas/lane-outcome.v1.schema.json, docs/lane-outcome.md) are data-shape only, no executable surface.
  • No trusted-path files, instruction files, or plugin manifests are touched by this PR.

Actions hardening (trigger types, permissions:, pin integrity) is deferred to zizmor per lane scope; none of that surface changed here.

critical-findings: 0

claude-lane-summary: lane=claude-security-review sha=da31296c3e7d98c7db3aaed511ffd01fe78ba804 run=40242353031
· Branch

@claude

claude Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 4m 56s —— View job


Code review complete

  • Gather context (PR diff, CLAUDE.md, REVIEW.md, path-scoped rules)
  • Resolve closing issue (feat(lane-outcome): publish duration, tokens and run link per run #885) and its acceptance criteria
  • Review changed files for correctness, maintainability, test coverage
  • Check path-scoped rules (.claude/rules/pr-body-contract.md) and PR body contract
  • Adversarially verify candidate findings
  • Post inline comments and final summary

Summary

No findings survived review. Walked through classify.cjs's new limitInfo/rateLimitWindows/readLegLog (camelCase/snake_case normalization, max-utilization-but-newest-status/reset merge, re-validation against closed allowlists for window names/statuses, the models→usage→windows 1,024-char drop order), lane.cjs's usageWarning (threshold, secret-name-only, placement after ::stop-commands:: and before the lane-class throw, injection-safety of the annotation text since window/status/utilization/resetsAt all come from closed allowlists or numeric/epoch-derived values), the report-lane-outcome/action.yml wiring of the new log-file input, the two workflows' four call sites, and the schema/doc additions ($defs.tokens/$defs.window, the status-required window shape, the docs/lane-outcome.md § Compatibility additive-fields rule). Everything held up: no unreachable branches, no prototype-pollution surface on the forged-key test case, no inconsistency between the schema and the implementation's re-validation.

  • This is the code-review lane; a security lane (pr-review-security.yml) runs on this repo, so security-impact findings (e.g. the annotation-injection angle I checked) are out of scope here per REVIEW.md — noted only because the check came back clean, not as a finding.
  • Closing issue unread: no PR-context file was available in this run (.claude-lane/pr-context.md absent), so feat(lane-outcome): publish duration, tokens and run link per run #885's acceptance criteria could not be checked against the diff. The PR body states it covers only the tokens/usage-windows item of feat(lane-outcome): publish duration, tokens and run link per run #885 and leaves durationMs and the run-link item open, which is consistent with the diff's scope, but I could not verify feat(lane-outcome): publish duration, tokens and run link per run #885's own acceptance-criteria text.
  • PR body contract: compliant. Title is Conventional-Commits-shaped, body opens with Refs: #885, and ## Summary/## Fix/## Verification/## Related are all present (.claude/rules/pr-body-contract.md).
  • Tests: this lane's sandbox did not permit running node --test here, so the PR's "709/84/75 pass" verification claims are author-claimed and unverified by me, not independently confirmed.
  • No .claude-plugin/plugin.json or marketplace.json changed, so the manifest checklist does not apply (no manifest <field>: lines).
    · branch feat/lane-usage-windows

claude-lane-summary: lane=claude-review sha=da31296c3e7d98c7db3aaed511ffd01fe78ba804 run=40242353031

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 25, 2026
@github-actions

Copy link
Copy Markdown

claude-security-review has reviewed this pull request through da31296; a later push is reviewed from there.

Merged via the queue into main with commit e5167fc Oct 25, 2026
135 of 136 checks passed
@kyle-sexton
kyle-sexton deleted the feat/lane-usage-windows branch October 25, 2026 22:58
@github-actions

Copy link
Copy Markdown

claude-review has reviewed this pull request through da31296; a later push is reviewed from there.

kyle-sexton added a commit to melodic-software/standards that referenced this pull request Oct 26, 2026
… and pr-review-cli contracts (#880)

Refs: melodic-software/ci-workflows#889

## Summary

Registers the `intake-triage.yml` and `pr-review-cli.yml`
reusable-workflow
contracts at ci-workflows

[v0.65.11](https://github.com/melodic-software/ci-workflows/releases/tag/v0.65.11)
(`e5167fc29d948ab7d0923cf62f5ea9eeeef8e9e8`), so claude-code-plugins can
repin
its intake and review callers and pass runner-policy.

## Fix

- Copies the v0.65.10 `intake-triage` entry
(`@215cec5c362f953f8b6196effb04451696c3f970`)
and the v0.65.9 `pr-review-cli` entry
(`@4fbceb4b75ffd568dfa5db31de0d0e753c0c64e6`)
forward verbatim in `components/runner-policy/policy.json`. Past entries
stay.
- Adds the matching copy-forward test in `runner-policy.test.mjs` and a
  rollout line in the component README.
- v0.65.11
([ci-workflows#889](melodic-software/ci-workflows#889))
passes `log-file` to `report-lane-outcome`, which records per-leg token
usage
and rate-limit windows. In both workflows the diff adds only that
`with:`
  line: no input, secret or job permission changes.

## Verification

- `node --test components/runner-policy/runner-policy.test.mjs`: 353
pass, 0 fail.
- `node components/runner-policy/runner-policy.mjs --root <worktree>`:
Runner policy passed.
- Pre-commit biome and markdownlint: clean.

## Related

-
[melodic-software/ci-workflows#889](melodic-software/ci-workflows#889)
(released as v0.65.11)
- [#879](#879)
(v0.65.10 intake contract),
[#878](#878) (v0.65.9
review contract)
- Next: the standards sync into claude-code-plugins, then the lane
caller repin.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[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