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.

@vadymhimself

Copy link
Copy Markdown
Collaborator Author

main is now the stable upstream-derived AgentRadar gateway line: 2.100.0-vadymhimself.2, merged via #47 (merge commit ad594a0778). Its tree is identical to the tested candidate 6a14467972, and it shares history with upstream lidge-jun/opencodex dev at 6bae884cbc.

Trial evidence: before the merge the build ran 30.5 h on the laptop gateway and 24 h on the personal Mac Mini gateway, both with OPENCODEX_AGENTRADAR=1. Neither restarted and neither left unresolved spend. The Mini served 11,138 requests with 2 5xx; the old build had 303 502s over the prior day. The remaining non-2xx were exhausted provider quota, not gateway faults. The fork's GitHub Actions has not run since Nov 18, so there is no CI result. Run checks locally.

For new work:

  • Branch from main. Do not target release/2.65.0-vadymhimself.*.
  • Check FORK-DELTA.md first; many old-line fixes are already carried or upstream-equivalent.
  • If a behavior is still missing, re-cut it as a small, single-concern change on main.

Before opening a PR, use pinned Bun 1.4.4 with an isolated HOME/OPENCODEX_HOME, synthetic credentials and loopback providers (never live accounts):

  • bun run test:gateway-quota (29-file AR gateway gate)
  • affected suites: bun scripts/test.ts --changed=main
  • bun run typecheck, bun run structure:check, bun run privacy:scan, git diff --check

Hosted-only behavior needs OPENCODEX_AGENTRADAR=1 set inside the test; without it the branch behaves like upstream. Register new test files in scripts/test-layout/layout-agentradar.json.

For this PR: the usage line and refusal-shape log are carried (src/lib/usage-line-log.ts, src/lib/upstream-refusal-log.ts). TTFT, hashed account and 429/retry/failover flags would be new: re-cut on main and extend tests/lib/call-usage-line-log.test.ts.

🤖 Generated with Claude Code

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