Skip to content

feat(logs): record the Anthropic pool account tag on each attempt - #8520

Merged
lidge-jun merged 2 commits into
devfrom
codex/8383-anthropic-account-tag-r2
Nov 11, 2026
Merged

lidge-jun merged 2 commits into
devfrom
codex/8383-anthropic-account-tag-r2

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

Request-log rows for the Anthropic OAuth pool carried no account attribution field (#8383, part 1). stampOAuthAccountLabel skips anthropic on purpose, because formatAnthropicProviderForLog folds the account into the logged provider (anthropic-p2e22d0). A consumer reading accountLogLabel therefore saw almost no Anthropic attribution and had to parse the provider suffix.

Each Anthropic pool attempt and row now records accountTag, the p-label already in that provider name (anthropic-p2e22d0 → p2e22d0). No new identifier is introduced, and accountLogLabel and the per-account usage summaries from #2699 are unchanged.

  • Where it is set: sealRequestAttemptIdentity sets the tag from the attempt's frozen provider. This covers the native Messages and translated Responses paths, plus anthropic2, without touching dispatch.
  • Failover: a failover attempt is sealed with the replacement account's provider, so it carries that account's tag.
  • The row: its tag comes from the row's own provider. Combo rows get none.
  • Validation: writes to usage.jsonl, reads back, and request-log hydration keep only p plus six lowercase hex digits. Attempt hydration previously copied attempt fields unchecked and now validates this one.

Owner decisions on the rest of #8383: part 2 (hashed session and worker keys that link requests) is declined, and part 3 (binding lifecycle events) is not scheduled. This PR implements part 1 only.

One limitation: a translated request with the pool turned off logs plain anthropic with no suffix, so it has no tag. A test pins this down. Tagging it would need a new identifier, which the owner decision excludes.

Closes #8383

Verification

  • Failing-first: bun test tests/usage/request-log-anthropic-account-tag.test.ts with src/ at dev gave 1 pass, 18 fail (for example Expected: "pba037e" Received: undefined for the native and translated attempt tags). With the change it gives 19 pass. The cases drive real requests through handleClaudeMessages and handleResponses:
    • a single attempt and a 429 failover on each path;
    • the persistence round trip and hydration;
    • 12 malformed values, all dropped;
    • identical summarizeUsage output with and without the tag;
    • no store account id, email or credential in rows.
  • After merging dev (the PR diff is byte-identical, same git patch-id), on the request-log and usage suites, native Messages OAuth, layout, ratchet and Lab boundary: 271 pass, 0 fail. src/server/request-log.ts stays at 1,998 lines.
  • bun run typecheck, bun run structure:check and bun run privacy:scan: pass.
  • test:changed (run by the implementing lane alongside another worktree's suite): 36,621 pass, 99 fail across 26 files, none of which touch request logging or usage. Each was rerun alone: 19 fail the same way on dev (launcher and update subprocess timeouts, config_busy, link end to end, catalog and others), 6 passed on a rerun as timing flakes, and client-connect passed alone.
  • NOT RUN: full bun run test; lint:gui (no gui/ change); macOS/Windows CI (manual dev batch only).

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

cpa added 2 commits November 11, 2026 10:44
Anthropic pool attempts carried no account attribution field: the pool folds
the account into the logged provider (anthropic-p<hex6>) and
stampOAuthAccountLabel skips it, so accountLogLabel consumers saw nothing.

Each request-log attempt and row now carries accountTag, the p-label already
in the provider suffix (no new identifier). It is derived from the attempt's
frozen provider in sealRequestAttemptIdentity, so on the native Messages and
translated Responses paths a failover attempt carries the replacement
account's tag. usage.jsonl normalization and request-log hydration keep only
p<hex6> values. accountLogLabel and per-account summaries are unchanged.

Refs #8383
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 11, 2026 02:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T02:27:26.043884Z df1712c PR opened
ℹ️ 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.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment

  • Value: Anthropic pool usage can now be attributed per account from the usage ledger, with the same opaque label the provider name already carried ([Feature]: Privacy-safe account label, session key and worker key on every attempt, plus session-binding end reasons #8383 part 1). Part 2 (hashed session and worker keys that link requests) was declined by the owner; part 3 is not scheduled.
  • UX change scope: one optional accountTag field on Anthropic pool request-log rows and attempts (/api/logs, usage.jsonl). There are no GUI, CLI or summary changes, and accountLogLabel and the per-account summaries from [Feature]: persist per-account usage for OAuth providers (xai/cursor), not only Codex main/pN labels #2699 are untouched.
  • Regression evidence: older rows hydrate without the field. summarizeUsage gives identical output with and without it (tested). Hydration now validates the attempt field it previously copied unchecked. Request-log, usage, native Messages OAuth and guard suites: 271 pass, 0 fail on the merged tree.
  • Privacy: the value is a re-exposure of the p-label already in the logged provider string (a six-hex prefix of an unsalted SHA-256 of the account id). Only /^p[a-f0-9]{6}$/ survives write, read and hydration, so no email, account id or credential can be stored through it.
  • Review: fresh independent review APPROVE on df1712c. Two low follow-ups are not addressed here:
    • anthropicAccountTag checks only the provider string's shape, so a custom provider literally keyed anthropic-p<hex6> would get a tag.
    • accountTag is also the name of an unrelated, salted cache-diagnostic field; a doc note distinguishing the two would help readers.
  • Windows impact: none; no path or process handling changed.
  • NOT RUN: full bun run test (the implementing lane's test:changed failures were each rerun alone and either reproduced on dev or passed on rerun); macOS/Windows CI (manual dev batch only).
  • Reviewed head = merge head: df1712c.

@lidge-jun
lidge-jun merged commit 8cec4d0 into dev Nov 11, 2026
29 of 30 checks passed
@lidge-jun
lidge-jun deleted the codex/8383-anthropic-account-tag-r2 branch November 11, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Privacy-safe account label, session key and worker key on every attempt, plus session-binding end reasons

1 participant