Skip to content

refactor(auto-routing-benchmark): mint benchmark tokens as an internal bot - #8092

Merged
iscekic merged 19 commits into
mainfrom
refactor/benchmark-internal-bot-token
Oct 19, 2026
Merged

iscekic merged 19 commits into
mainfrom
refactor/benchmark-internal-bot-token

Conversation

@iscekic

@iscekic iscekic commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The decider benchmark now runs as the internal bot user bot-internal-benchmark. It mints that user's token from POST /api/internal/bot-token, added in #8088. It no longer mints a token for a personal user, so it stops sharing that user's per-user gateway limit.

  • fetchBenchmarkUserToken (services/auto-routing-benchmark/src/benchmark-token.ts) calls ${KILO_WEB_API_BASE_URL}/api/internal/bot-token. It authenticates with a new Secrets Store binding, BOT_TOKEN_MINT_SECRET (secret name BOT_TOKEN_MINT_SECRET, in the same store as the other bindings), and sends { userId, organizationId }. organizationId is now a required parameter.
  • Every caller uses the bot identity: decider jobs in run.ts, /admin/debug-cli, and the executable model catalog (executable-models.ts), which the queue drain, run initialization, subscriptions and profile refresh use. The catalog always reads the org catalog, because the identity always has an org.
  • INTERNAL_API_SECRET_PROD stays where other routes still need it: admin auth, production-profile, and grader usage.
  • worker-configuration.d.ts was regenerated with pnpm types.
  • DEFAULT_BENCHMARK_USER_ID is now bot-internal-benchmark. The default org is unchanged.
  • Override handling: a saved benchmarkUserId override that is not a bot-internal-* user now makes resolveBenchmarkIdentity throw a BenchmarkIdentityError. It does not silently fall back to the default. Starting a run, a queue drain and /admin/debug-cli return a 400 before anything is claimed. The MCP catalog mint, which shares the same identity, returns the error as a 502.
  • Org is mandatory: resolveBenchmarkIdentity always supplies an org. A decider job whose run row has no org snapshot, such as an old row, now refuses to mint a token. Before, it sent the request without an org. A chunk whose cases are all recorded still finishes, because it needs no mint. An uninitialized run row without an org fails at initialization, the same way as a row without a user.
  • Deleted apps/web/src/app/api/internal/auto-routing-benchmark/token/ (route and test). With it went the now-unused benchmark resource-token family (BENCHMARK_RESOURCE_TOKENS_ENABLED) and its doc and test entries. Updated the README and the token-issuance policy map.
  • Token lifetime drops from 6 h to 1 h. Each queue message mints its own token, and the token is held only for that message's CLI calls.

Verification

  • services/auto-routing-benchmark: typecheck, oxlint and the full vitest suite pass. The new tests check the mint request (URL, dedicated secret, { userId, organizationId } body), that no token is minted for a run without an org, the 400 from /admin/debug-cli, and that run initialization fails a row without an org.
  • packages/auto-routing-contracts: typecheck and vitest pass, including a test that non-bot overrides are rejected (a human id, a per-org product bot, a lookalike prefix).
  • services/auto-routing: typecheck passes.
  • apps/web: typecheck passes. Jest passes for src/app/api/internal/** (including the MCP catalog mint and its new non-bot test) and src/lib/bot-users.

Deploy order

  1. Create bot-internal-benchmark in the benchmark org from the admin Internal Bot Users page (from feat(admin): internal bot users with short-lived token minting #8088). Give it credits.
  2. Provision BOT_TOKEN_MINT_SECRET with one value in two places: the web environment and Secrets Store secret BOT_TOKEN_MINT_SECRET. Leave INTERNAL_BOT_RESOURCE_TOKENS_ENABLED unset, which keeps the legacy token shape. Before you set it, test a modern minted token against /api/profile and the organization models endpoint.
  3. Clear any saved benchmarkUserId override in the benchmark config, or set it to bot-internal-benchmark. A non-bot override blocks new runs and the MCP catalog mint once this ships.
  4. Pause the benchmark queues, then let every running decider run finish, or fail it from the admin panel. A run row written before this change holds the old non-bot user, and the new mint refuses that user. Do not merge while such a run still has chunks queued.
  5. Merge.
  6. Wait for the web deploy and the auto-routing-benchmark worker deploy to finish.
  7. Resume the queues.

@kilo-code-bot

kilo-code-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The port onto main's benchmark-token helper fixes the stale-import typecheck break and makes every mint org-scoped, but pre-deploy run rows that snapshot a non-bot user id still cannot mint and will fail their queued chunks.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
services/auto-routing-benchmark/src/run.ts 1731 Pre-deploy benchmark_runs rows keep the old non-bot user id; /api/internal/bot-token rejects them with 403, so in-flight runs with unfinished chunks fail and dead-letter once the queues resume. The deploy gate in the PR body mitigates this operationally, but the code path is unchanged.
Files Reviewed (10 files)
  • docs/token-issuance-policy.md - 0 issues
  • services/auto-routing-benchmark/src/admin.test.ts - 0 issues
  • services/auto-routing-benchmark/src/admin.ts - 0 issues
  • services/auto-routing-benchmark/src/benchmark-token.ts - 0 issues
  • services/auto-routing-benchmark/src/executable-models.test.ts - 0 issues
  • services/auto-routing-benchmark/src/executable-models.ts - 0 issues
  • services/auto-routing-benchmark/src/run-dead-letter.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run-process-job.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run.ts - 1 issue (carried)
  • services/auto-routing-benchmark/src/scheduler-initialization.test.ts - 0 issues

Fix these issues in Kilo Cloud

Previous Review Summaries (3 snapshots, latest commit 44bf33c)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 44bf33c)

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

The merge of main kept the pre-#7937 benchmark run.ts/admin.ts while taking main's newer platform-models.ts/db.ts, leaving imports of non-existent exports so the auto-routing-benchmark worker no longer typechecks; pre-deploy run rows still cannot mint a bot token.

Overview

Severity Count
CRITICAL 2
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
services/auto-routing-benchmark/src/run.ts 100 fetchPlatformRegistryEntries, concreteAliasPair, and collapsePendingOwnerAliasRows are no longer exported after the main merge, so the worker fails typecheck and loses #7937's alias/subscription behavior.
services/auto-routing-benchmark/src/admin.ts 66 mapProfileStatusesToRequestedModels is not exported; the merge also dropped the /admin/profiles/subscriptions and registry-refresh routes from main.

WARNING

File Line Issue
services/auto-routing-benchmark/src/run.ts 1650 Pre-deploy benchmark_runs rows snapshot the old non-bot user id; the new bot-token mint 403s them, so in-flight runs with unfinished chunks dead-letter after the queues resume. The documented deploy gate mitigates this operationally but the code path still fails.
Files Reviewed (19 files)
  • ENVIRONMENT.md - 0 issues
  • apps/web/src/app/api/internal/auto-routing-benchmark/token/route.test.ts - 0 issues (deleted)
  • apps/web/src/app/api/internal/auto-routing-benchmark/token/route.ts - 0 issues (deleted)
  • apps/web/src/app/api/internal/mcp-catalog/token/route.test.ts - 0 issues
  • apps/web/src/app/api/internal/mcp-catalog/token/route.ts - 0 issues
  • docs/token-issuance-policy.md - 0 issues
  • packages/auto-routing-contracts/src/benchmark.ts - 0 issues
  • packages/auto-routing-contracts/src/contracts.test.ts - 0 issues
  • packages/web-shared/src/lib/config.server.resource-tokens.test.ts - 0 issues
  • packages/web-shared/src/lib/config.server.ts - 0 issues
  • services/auto-routing-benchmark/README.md - 0 issues
  • services/auto-routing-benchmark/src/admin.test.ts - 0 issues
  • services/auto-routing-benchmark/src/admin.ts - 1 issue
  • services/auto-routing-benchmark/src/profile-runs.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run-process-job.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run-redelivery.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run.ts - 2 issues
  • services/auto-routing-benchmark/worker-configuration.d.ts - 0 issues
  • services/auto-routing-benchmark/wrangler.jsonc - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit 02468fa)

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

The incremental fix correctly reports a non-bot identity override as HTTP 400 and makes the missing-org check lazy; the remaining blocker is that pre-deploy run rows still snapshot a non-bot user, plus two stale lines in the token policy doc.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
services/auto-routing-benchmark/src/run.ts 1650 Pre-deploy benchmark_runs rows snapshot the old non-bot user id; the new bot-token mint 403s them, so in-flight runs with unfinished chunks dead-letter after the queues resume and lose already-paid work.

SUGGESTION

File Line Issue
docs/token-issuance-policy.md 113 Confirmed tokenSource values still list auto-routing-benchmark, whose only emitter this PR deletes, and omit internal-bot.
docs/token-issuance-policy.md 127 "benchmark tokens six hours" is now false; decider tokens come from the one-hour internal-bot mint.
Files Reviewed (7 files)
  • packages/auto-routing-contracts/src/benchmark.ts - 0 issues
  • packages/auto-routing-contracts/src/contracts.test.ts - 0 issues
  • apps/web/src/app/api/internal/mcp-catalog/token/route.ts - 0 issues
  • services/auto-routing-benchmark/src/admin.ts - 0 issues
  • services/auto-routing-benchmark/src/admin.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run.ts - 1 issue (carried)
  • docs/token-issuance-policy.md - 2 issues (carried)

Fix these issues in Kilo Cloud

Previous review (commit 4c42072)

Status: 6 Issues Found | Recommendation: Address before merge

Executive Summary

The refactor is internally consistent, but in-flight decider runs snapshot a non-bot user id that the new mint rejects, so they will dead-letter after the deploy resumes the queues; admin error status and two stale policy-doc lines are also worth fixing.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 5
Issue Details (click to expand)

WARNING

File Line Issue
services/auto-routing-benchmark/src/run.ts 1634 Pre-deploy benchmark_runs rows snapshot the old default UUID (or a saved override); the new bot-token mint 403s them, so in-flight runs with unfinished chunks dead-letter after the queues resume and lose already-paid work.

SUGGESTION

File Line Issue
services/auto-routing-benchmark/src/run.ts 1558 The org guard runs before casesToRun is computed, so a redelivered chunk whose results are already recorded now fails instead of finishing when a legacy row has a null org snapshot.
packages/auto-routing-contracts/src/benchmark.ts 217 Plain Error from resolveBenchmarkIdentity is not mapped to 400 by the admin start-run handler and is uncaught in /admin/debug-cli, so a config problem surfaces as HTTP 500.
packages/auto-routing-contracts/src/benchmark.ts 131 INTERNAL_BOT_USER_ID_PREFIX duplicates apps/web/src/lib/bot-users/types.ts; the mint and the identity resolver can drift.
docs/token-issuance-policy.md 113 Confirmed tokenSource values still list auto-routing-benchmark, whose only emitter this PR deletes, and omit internal-bot.
docs/token-issuance-policy.md 127 "benchmark tokens six hours" is now false; decider tokens come from the one-hour internal-bot mint.
Files Reviewed (18 files)
  • ENVIRONMENT.md - 0 issues
  • apps/web/src/app/api/internal/auto-routing-benchmark/token/route.test.ts (deleted) - 0 issues
  • apps/web/src/app/api/internal/auto-routing-benchmark/token/route.ts (deleted) - 0 issues
  • apps/web/src/app/api/internal/mcp-catalog/token/route.test.ts - 0 issues
  • apps/web/src/app/api/internal/mcp-catalog/token/route.ts - 0 issues
  • docs/token-issuance-policy.md - 2 issues
  • packages/auto-routing-contracts/src/benchmark.ts - 2 issues
  • packages/auto-routing-contracts/src/contracts.test.ts - 0 issues
  • packages/web-shared/src/lib/config.server.resource-tokens.test.ts - 0 issues
  • packages/web-shared/src/lib/config.server.ts - 0 issues
  • services/auto-routing-benchmark/README.md - 0 issues
  • services/auto-routing-benchmark/src/admin.test.ts - 0 issues
  • services/auto-routing-benchmark/src/profile-runs.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run-process-job.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run-redelivery.test.ts - 0 issues
  • services/auto-routing-benchmark/src/run.ts - 2 issues
  • services/auto-routing-benchmark/worker-configuration.d.ts - 0 issues
  • services/auto-routing-benchmark/wrangler.jsonc - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 137.2K · Output: 33.1K · Cached: 4.8M

Review guidance: REVIEW.md from base branch main

Base automatically changed from feat/internal-bot-users to main October 19, 2026 16:37
…ternal-bot-token

# Conflicts:
#	ENVIRONMENT.md
#	apps/web/src/routers/admin/internal-bot-users-router.ts
#	docs/token-issuance-policy.md
#	packages/web-shared/src/lib/config.server.resource-tokens.test.ts
#	packages/web-shared/src/lib/config.server.ts
…in's benchmark-token helper

Main moved fetchBenchmarkUserToken into benchmark-token.ts and added the executable model catalog as a caller, so a merge left run.ts and admin.ts with stale code. Rebuild the PR on main's structure: every mint goes to /api/internal/bot-token with BOT_TOKEN_MINT_SECRET and a required org, the catalog always uses the org scope, and a legacy run row without an org fails at initialization instead of minting.
@iscekic
iscekic added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit d26988c Oct 19, 2026
59 checks passed
@iscekic
iscekic deleted the refactor/benchmark-internal-bot-token branch October 19, 2026 23:09
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.

2 participants