Repository navigation
perf: collapse per-request authority round trips and add load harness - #268
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR combines proxy admission reads, reduces request copying, and adds live and local load-testing commands. Example: A warmed Anthropic inference request uses a principal-owned proxy key.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep open: the optimization has clear value, but reusing provider state captured before body upload introduces a kill-switch and budget-enforcement regression. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe Worker authenticates incoming inference requests, selects provider credentials, reserves budgets, dispatches upstream, and publishes usage. flowchart LR
Client --> Worker
Worker --> AdmissionAuthority
AdmissionAuthority --> RequestIdentity
RequestIdentity --> ProviderPreparation
ProviderPreparation --> BudgetLedger
BudgetLedger --> ProviderDispatch
ProviderDispatch --> UsageAccounting
Technical reviewBest possible solution: Retain combined admission while checking provider enablement and budget limits after request-body consumption. Do we have a high-confidence way to reproduce the issue? The source establishes the failing sequence: capture an enabled, unmetered Anthropic connection, hold the Messages body open, disable the provider or set its budget to zero, then finish the upload; no target code was executed during this review. Is this the best way to solve the issue? Combining authority reads and avoiding deep copies are appropriate optimizations, provided they preserve the existing provider-enforcement point after body parsing. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6e265875a714. Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: Provider authority captured before upload can outlive an operator's disable or budget change. EvidenceSecurity concerns:
What I checked:
Likely related people:
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 11, 2026, 11:26 PM ET / October 12, 2026, 03:26 UTC. |
Summary
Production measurements showed every authenticated request paying ~70–85 ms per sequential call to the global
ACCESS_CONTROLauthority, with five calls per inference and four per catalog read. That added ~270 ms to a catalog read and ~530–650 ms to time-to-first-token versus direct Anthropic, and capped authenticated throughput at ~100 req/s (98 rps at concurrency 100, 102 rps at 200, p99 9.8 s), all with zero errors./admission/resolve): credential, policy, owner, connections and grant-pool membership/runtime state in one authority invocation, with the same migration fences, revocation/generation checks and error outcomes as the single-purpose resolvers. The Worker still verifies the secret digest in constant time; nothing authorization-related is cached across requests. Selection stays a separate atomic call (counter now viaRETURNING)./v1/models//v1/catalog: 4 (or 3+N) → 1. Key inspection, usage, pool: 2–3 → 1.structuredClonethe whole prompt/tool tree (256 KiB transform: 55.85 → 0.167 ms per 1,000 calls).pnpm loadtest(live, key from a 0600 file, latency/TTFB/lane/failover/stream-abort stats) andpnpm loadtest:local(workerd + fake Anthropic upstream, 7-grant subscription pool mirroring production). Findings and traces indocs/hot-path-performance.md.Verification
pnpm check,pnpm worker:e2e; 1,253 Worker tests incl. 30 admission parity tests (revoked/stale/invalid keys, disabled policies/users, absent owners/connections, model denial, unavailable pools, environment fallback, migration races, wrong-secret short-circuit).Local workerd has no network between Worker and Durable Objects, so it understates the edge gain; production before/after numbers follow the deploy.
Remaining (design, not in this PR)
Global singleton still serializes selection writes and admission for all tenants; per-grant credential owners serialize materialization; budget ledgers are shared. See
docs/hot-path-performance.mdranked findings 1–4, 6–7.