Skip to content

[STALE: REBASE FROM NEW FORK] usage line: add time to first token, hashed account and 429/retry/fallover flags - #45

Open
vadymhimself wants to merge 2 commits into
release/2.65.0-vadymhimself.15from
gauge/usage-line-ttft
Open

vadymhimself wants to merge 2 commits into
release/2.65.0-vadymhimself.15from
gauge/usage-line-ttft

Conversation

@vadymhimself

@vadymhimself vadymhimself commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Adds time to first token, a hashed serving account and three 0/1 flags to the existing per-request [usage] log line, so a slow or failed reply can be traced from the gateway log alone.

New fields, appended after ms= (existing fields and order unchanged):

  • ttft= ms from request start to the first non-empty output (firstOutputMs), - when absent
  • acct= first 8 hex of an HMAC-SHA256 of the serving account's log label, keyed with a random per-process key that is never written anywhere (labels are guessable, so a plain hash could be reversed); - when absent
  • r429= 1 when any attempt (or the final status) was a 429
  • retry= 1 when the request was sent upstream more than once or an attempt recovered
  • fallover= 1 when combo execution moved to another target or attempts used more than one account

Still no message text, bodies, headers, key values, account labels in clear or emails. Still written only when OPENCODEX_AGENTRADAR=1, and never throws. src/server/request-log.ts is unchanged (file-size ratchet).

Eval added/updated: tests/lib/request-summary-line.test.ts
Cache/quota impact: none. Log text only; no change to retries, routing, account choice or what is sent upstream.

🤖 Generated with Claude Code

…lover flags

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vadymhimself

Copy link
Copy Markdown
Collaborator Author

Security review (Mars): GREEN on the code at 30ecfd0 (gateway logging; the status waits for fork CI)

  • Log text only: the one source change is src/lib/usage-line-log.ts, which adds pure string builders and extra fields on the existing usage line. There is no await, no I/O, and no change to routing, retry, fallover, model, account, timeout, cache or bodies. request-log.ts is untouched. The line still runs only on our gateways, inside the existing try/catch.
  • Fields: ttft goes through count(), and the 429, retry and fallover flags are fixed 0 or 1. acct is the first 8 hex of sha256 of the account label. The labels are already random or hashed pseudonyms (p/o/k plus hex, or main), never an email or a raw key, so an unkeyed hash reveals nothing new. Upstream error text and codes are not read, and the test checks that planted prompt and email text never appears.
  • Quota guardrail: the "Cache/quota impact: none" line is in the body and holds, since there is no new upstream call or retry.
  • Tests: the new request-summary-line.test.ts is registered in both layout files, and the 4 old exact lines are extended.

Non-blocking: retry=1 also fires when spend.sends is above 1, which can include combo children, so read that flag as "more than one send".

The fork CI has 0 runs at this head. The independent-qa status follows once it is green, including tsc.

…ain hash

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vadymhimself

Copy link
Copy Markdown
Collaborator Author

Security review (Mars): GREEN on the code at 91ca01f (replaces my read at 30ecfd0; the status waits for fork CI)

The delta from 30ecfd0 is two files. acct= is now the first 8 hex of HMAC-SHA256 of the account label, under ACCOUNT_TAG_KEY = randomBytes(32), made once per process and never written or logged. Labels are guessable (a provider plus a short hex suffix), so this closes the brute-force reversal a plain short hash allowed. The tag is stable within one process and changes on restart, which is enough for tracing a slow reply. key= still hashes the random key-record id. The new test checks the tag is 8 hex, stable for one label, different across labels, and never the plain sha256.

Everything else from my 30ecfd0 read stands: log text only, nothing on the request path, and the "Cache/quota impact: none" line holds.

@vadymhimself vadymhimself changed the title usage line: add time to first token, hashed account and 429/retry/fallover flags [STALE: REBASE FROM NEW FORK] usage line: add time to first token, hashed account and 429/retry/fallover flags Nov 18, 2026
@vadymhimself

Copy link
Copy Markdown
Collaborator Author

This PR is based on the superseded 2.65 gateway line. Rebuild the change from port/ar-on-upstream-2026-11-18 (upstream-derived 2.100 AR overlay, PR #46): #46 . Do not rebase onto or merge the old release line. Preserve the new gateway quota/cache gate and re-run the affected regressions. The candidate is not deployed; do not publish or replace a running gateway without explicit approval.

This branch has not been deployed

No deployments
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