Skip to content

fix(usage): a leg refused before any send does not make the row unreported - #7336

Closed
vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
vadymhimself:fix/usage-status-physical-attempts
Closed

vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
vadymhimself:fix/usage-status-physical-attempts

Conversation

@vadymhimself

@vadymhimself vadymhimself commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A multi-attempt row takes its usage status from aggregateAttemptUsage, where any usage-less attempt marks the whole row unreported. A combo leg the gateway refused locally (input admission in core-combo.ts, a local pool cooldown) never reached upstream and carries no usage, so a combo that then served the turn on its next leg with fully reported usage was still logged as unreported.
  • The status now ignores usage-less attempts that never sent (sendCount === 0) or were answered locally (locallyAnswered), the same "spent nothing" rule summary.ts already prices by (spentNothing). An attempt that was sent and reported nothing still leaves the row unreported, and an attempt that carries usage always counts. Token totals are unchanged (those legs carry no usage).
  • Only src/server/request-log.ts changes (+6/-4).

Verification

  • New test a combo leg refused before any send does not make the served row unreported in tests/usage/request-log-attempt-identity.test.ts, run before the src change: 1 fail ("status": "unreported" where "reported" was expected). It also pins that a sent leg with no usage still yields unreported. The existing folds partial and unsupported attempt measurement honestly test in tests/usage/request-log.test.ts built its "unreported 503" attempt without a send; it now notes the send, which is the case it describes. After: bun test tests/usage/ -> 1184 pass, 0 fail.
  • bun x tsc --noEmit -> exit 0. bun scripts/file-size-ratchet.ts -> passed.
  • bun run test:changed (Bun 1.4.3 via OCX_TEST_RUNNER_BUN, OCX_TEST_MAIN_TIMEOUT_MS=2400000 on a loaded machine) -> 16943 pass, 34 skip, 3 fail across 692 files. Two failures stalled for about 1060 s in a machine-wide pause and pass alone (responses-devin-401-replay, claude-desktop-first-party: 69 pass, 0 fail). The third, tests/cli/cli-connect-readiness.test.ts "a rejected preferred runtime falls back without rewriting the saved selection", also fails on an unmodified upstream/dev 8640c2f checkout on this machine (local-environment dependent) and is unrelated to usage logging.
  • Full bun run test was not run locally: test:changed already covered the changed module's import graph; the remainder is left to CI.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (No docs change needed: request-log usage status only.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (No secrets or auth behaviour touched.)

Source: carried from the vadymhimself fork build (physicalUsageAttempts in aggregateAttemptUsage, commit 8fb1bbb), re-authored smaller: no new helper, the filter applies to the status only, and an attempt that carries usage is never dropped. The fork's finalized-attempt overwrite guard is not carried (no reproducible caller path on current dev), and its cache-read fix is a separate PR.

🤖 Generated with Claude Code

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Usage summaries now reflect reported usage even when other attempts were refused before sending or answered locally.
    • When no attempts qualify for usage reporting, the summary is marked as unreported. A sent attempt without usage data also remains unreported.

…orted

A multi-attempt row takes its usage status from aggregateAttemptUsage, which
let any usage-less attempt mark the whole row "unreported". A combo leg the
gateway refused locally (input admission, a local cooldown) never reached
upstream and carries no usage, so a combo that then served the turn on its
next leg with fully reported usage was still logged as unreported.

The status now ignores usage-less attempts that never sent or were answered
locally -- the same "spent nothing" rule summary.ts already prices by. An
attempt that was sent and reported nothing still leaves the row unreported.

The existing "folds partial and unsupported" test built its unreported 503
without a send; it now notes the send, which is the case it describes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request has been marked Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers notified: @lidge-jun @Ingwannu

@github-actions
github-actions Bot marked this pull request as draft October 18, 2026 19:42
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cdc96935-6fd4-4993-9a1f-e029ad8bd315
📥 Commits

Reviewing files that changed from the base of the PR and between 8640c2f and 6828e68.

📒 Files selected for processing: 3
  • src/server/request-log.ts
  • tests/usage/request-log-attempt-identity.test.ts
  • tests/usage/request-log.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

aggregateAttemptUsage now excludes usage-less attempts that were not sent or were answered locally. Tests cover how unsent and sent attempts without usage data affect aggregate status and totals.

Changes: Attempt usage aggregation

Layer / File(s) Summary
Filter attempts for aggregate usage status
src/server/request-log.ts, tests/usage/request-log-attempt-identity.test.ts, tests/usage/request-log.test.ts
The aggregate status checks now apply to attempts with usage data or a non-local send. Tests verify that an unsent refused attempt does not alter reported usage, and that a sent attempt without usage produces an unreported status.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 6828e

No actionable merge-blocking risk is established for this usage-status change; it is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: a usage-less leg refused before any send no longer makes the aggregate row unreported. This matches the implementation and tests.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Ingwannu

Copy link
Copy Markdown
Owner

Intake/scoped review at 6828e68fe0ae26606a3759b5046bd25863fe744e.

The measured-attempt filter excludes a usage-less unsent/local leg while retaining a physically sent leg with missing usage as unreported. Keep the explicit send-count negative control and unsupported/estimated status precedence. This is a scoped static accounting review; named current-head CI is still needed.

Current-head functional workflows are awaiting fork approval; that is pending execution, not a passing test result. No local suite was run for this branch in this intake. No workflow approval, new scan, live configuration change or merge was performed. Required review/readiness gates remain in force.

@lidge-jun

Copy link
Copy Markdown
Owner

Landed on dev as part of the dispatch/usage/failover bundle #7389 (squash bddd61f), with Co-authored-by credit. Adaptations are listed in #7389 (ratchet move for #7323/#7373; the Kiro hop is now fenced to the adapter the failed leg actually resolved). Closing as absorbed. Thank you!

@lidge-jun lidge-jun closed this Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants