Skip to content

fix(auto-routing-benchmark): send long-context cases with their workspace snapshot - #7817

Closed
iscekic wants to merge 5 commits into
mainfrom
fix/auto-routing-long-context-prompts
Closed

iscekic wants to merge 5 commits into
mainfrom
fix/auto-routing-long-context-prompts

Conversation

@iscekic

@iscekic iscekic commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The production decider runner never materialized long-context cases, so they ran without their workspace snapshot. The offline sweep and candidate screen already materialize them. The runner also passed every prompt as a kilo run argument, which the CLI rewrites.

  • deciderCliPrompt() in cli-runner.ts is the one function that builds a case's prompt; it materializes long-context cases with materializeLongContext.
  • container/server.mjs writes the prompt to the CLI's stdin and no longer passes it as an argument:
    • A materialized 160k-token case is about 640 KB; Linux caps one argument at 128 KiB (MAX_ARG_STRLEN, E2BIG).
    • The CLI's buildRunMessage (packages/opencode/src/kilocode/cli/cmd/run-message.ts:8-11) wraps an argument containing a space in double quotes and backslash-escapes inner quotes, so every case so far reached the model in that rewritten form. The CLI is unchanged; benchmark prompts stop using argv.
    • With no positional message, kilo run reads stdin to EOF and sends it verbatim (loadInput → readPipedStdin({ bound: false }) → resolveRunInput("", piped) in packages/opencode/src/cli/cmd/run.ts, present in v7.8.12, the CLI the image installs). The npm kilo wrapper spawns the binary with stdio: "inherit", so stdin passes through.
  • BENCHMARK_ENGINE_VERSION is unchanged, by decision. Instead, a targeted re-measure replaces only the results the old transport damaged:
    • Every case_results, pending_decider_outputs and scheduler_executions row records prompt_revision (old rows: 1, new: 2, PROMPT_TRANSPORT_REVISION in src/prompt-transport.ts). A container result recovered after its caller died is stamped with the revision the paid call was opened under, so output a previous deploy produced is re-measured instead of trusted.
    • The drain reserves batch space for queued re-measures ahead of the pending backlog, so a queued repair starts on the next drain.
    • argvAffectedCases(router) is the affected set: every long-context case, plus efficient cases whose prompt has an inner " and whose check is exact, contains_all or regex. Frontier inner-quote cases join behind REMEASURE_FRONTIER_INNER_QUOTE_CASES (off).
    • POST /admin/registry/remeasure-prompt-transport ({router?, action: dry-run | request | cancel}): the dry run writes nothing and reports affected pairs, results and projected spend (measured cost of each affected result, plus snapshot prompt tokens at the catalog prompt price); request queues the pairs in a new profile_remeasures table; cancel removes unclaimed rows.
    • The normal drain claims queued pairs after pending ones. The profile stays ready on its previous run, so the platform table, owner tables and status keep serving. The run copies the previous run's results except the affected old-revision rows, so only those cases are scheduled under the existing caps. On completion the profile's run_id moves to the new run and the table republishes; a failed run, dead lane or orphaned claim keeps the previous measurement.
    • Prior-case reuse no longer copies affected old-revision rows into any new run.
  • README: container section documents the stdin transport; a runbook covers dry run, queue, verify and stop.

Rollout

The re-measure is an operator step after the whole stack is merged and deployed (#7784, #7793, #7790, #7791, #7809, #7808, #7817); the migration applies on deploy. Run the dry run first and queue only after reviewing the projected spend.

Verification

  • Benchmark worker typecheck, full test suite and lint pass on a work VM; oxfmt clean.
  • Re-measure tests on real D1 SQLite: the affected set; reuse skips exactly the affected old-revision rows; a re-measure schedules only affected cases while the profile stays ready on its old run and the platform count is unchanged; settle moves provenance; failure, dead lane and release keep or return the claim; owner-only pairs use the owner queue; cancel spares claimed rows; the dry run writes nothing and projects spend; the frontier flag widens the set.
  • Tests: the runner sends the materialized prompt for an efficient and a frontier long-context case and the raw prompt for an ordinary case; the container passes an ordinary case with spaces and double quotes and a long-context case over 128 KiB to the CLI's stdin byte for byte and keeps them out of argv.
  • Container smoke on the VM: the built image running server.mjs with a kilo stand-in received a 655,398-byte prompt on stdin with identical byte length and SHA-256; spawning the same prompt as an argument fails with E2BIG.

Risks

  • Until the operator runs the re-measure, ready pairs keep their old-transport scores for the affected cases.
  • The affected-set predicate decides what is re-measured; a damaged case outside it keeps its old score.
  • The 180-second case timeout is unchanged; a 160k-token prefill is the largest case it must cover.

@iscekic iscekic self-assigned this Oct 17, 2026
@kilo-code-bot

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

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The only change since the prior review is a documentation-only README note, and the documented recovery behavior matches the implementation (acceptContainerCaseResult reads getPaidCasePromptRevision from scheduler_executions.prompt_revision and savePendingDeciderOutput stores it, defaulting to 1), so no new findings.

Files Reviewed (1 file)
  • services/auto-routing-benchmark/README.md - 0 issues (documents that a container result recovered after its caller died is stamped with the revision the paid call was opened under; matches src/run.ts:1193/1210, src/scheduler.ts:796, and src/db.ts:686)
Previous Review Summaries (4 snapshots, latest commit 862d23c)

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

Previous review (commit 862d23c)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change resolves both prior findings: the recovered container output is now stamped with the paid call's ledgered prompt_revision (scheduler_executions.prompt_revision, written in beginPaidCase, read in acceptContainerCaseResult), and the dry-run planner prices each long-context snapshot once instead of per result row.

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0
Files Reviewed (10 files)
  • services/auto-routing-benchmark/migrations/0023_furry_mandroid.sql - 0 issues (adds scheduler_executions.prompt_revision NOT NULL DEFAULT 1; valid SQLite ADD COLUMN, renames the same-PR migration)
  • services/auto-routing-benchmark/migrations/meta/0023_snapshot.json - 0 issues (generated)
  • services/auto-routing-benchmark/migrations/meta/_journal.json - 0 issues (generated)
  • services/auto-routing-benchmark/src/db-schema.ts - 0 issues
  • services/auto-routing-benchmark/src/remeasure.ts - 0 issues (prior snapshot-per-row suggestion fixed)
  • services/auto-routing-benchmark/src/run.ts - 0 issues (prior recovered-output revision warning fixed; drain reservation keeps pending rows for the next cycle)
  • services/auto-routing-benchmark/src/scheduler.ts - 0 issues (insert bind order matches the column list; null-vs-present ledger check preserves the old admission semantics)
  • 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/scheduler.test.ts - 0 issues

Previous review (commit ce7a817)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

The new re-measure path resolves the earlier engine-identity concern by re-measuring argv-affected cases without a version bump; two narrower issues remain — a recovered container output is stamped with the current transport revision, and the dry-run planner re-materializes each long-context snapshot once per result row.

Overview

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

WARNING

File Line Issue
services/auto-routing-benchmark/src/db.ts 686 savePendingDeciderOutput defaults prompt_revision to the deploy's PROMPT_TRANSPORT_REVISION. The recovery caller acceptContainerCaseResult (src/run.ts:1193) saves a container output without a revision, so an output produced by a revision-1 worker's container but recovered after deploy is stored as revision 2, and planPromptTransportRemeasure (source.prompt_revision < 2) then never re-measures that affected case.

SUGGESTION

File Line Issue
services/auto-routing-benchmark/src/remeasure.ts 123 snapshotPromptTokens is called per result row inside the planner loop and calls materializeLongContext, regenerating a ~640 KB snapshot (pair × long-context case × rep) in one admin request. Cache a Map<caseId, tokenCount> for the affected cases once before the loop.
Files Reviewed (16 files)
  • services/auto-routing-benchmark/src/prompt-transport.ts - 0 issues
  • services/auto-routing-benchmark/src/remeasure.ts - 1 issue
  • services/auto-routing-benchmark/src/admin.ts - 0 issues
  • services/auto-routing-benchmark/src/db.ts - 1 issue
  • services/auto-routing-benchmark/src/db-schema.ts - 0 issues
  • services/auto-routing-benchmark/src/run.ts - 0 issues
  • services/auto-routing-benchmark/migrations/0023_dashing_king_cobra.sql - 0 issues
  • services/auto-routing-benchmark/README.md - 0 issues
  • services/auto-routing-benchmark/src/remeasure.test.ts - 0 issues
  • services/auto-routing-benchmark/src/admin.test.ts - 0 issues
  • services/auto-routing-benchmark/src/prior-case-reuse-sql.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.test.ts - 0 issues
  • services/auto-routing-benchmark/migrations/meta/_journal.json - 0 issues (generated)
  • services/auto-routing-benchmark/migrations/meta/0023_snapshot.json - 0 issues (generated)

Note: the previously reported engine-identity WARNING is not carried forward — the new profile_remeasures claim/settle path re-measures the argv-affected cases under the unchanged identity, so those rows no longer keep their broken no-snapshot measurements indefinitely.

Previous review (commit 4e029d1)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The incremental commit only retitles a test, clarifies a doc comment, and adds a container test proving prompts reach kilo run byte-for-byte on stdin; the previously reported engine-identity concern remains unresolved.

Overview

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

WARNING

File Line Issue
services/auto-routing-benchmark/src/cli-runner.ts 87 Execution inputs change without an engine-identity bump. The prompt is now materialized with the long-context snapshot and moved from argv to stdin, but BENCHMARK_ENGINE_VERSION (src/run.ts:546) stays at 1, so already-ready long-context registry rows (syncPlatformRegistryRows, src/db.ts:1314) keep their broken no-snapshot measurements and the fixed prompt is never re-measured for those cases.
Files Reviewed (3 files)
  • services/auto-routing-benchmark/src/cli-runner.ts - 1 issue (carried, unchanged)
  • services/auto-routing-benchmark/src/cli-runner.test.ts - 0 issues
  • services/auto-routing-benchmark/src/container-auth.test.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit 4a594ab)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

The change correctly fixes the missing workspace snapshot for long-context decider cases and routes the prompt through stdin to avoid MAX_ARG_STRLEN/E2BIG and the CLI's argv re-quoting; the one concern is that execution inputs change while BENCHMARK_ENGINE_VERSION stays at 1.

Issue Details (click to expand)

WARNING

File Line Issue
services/auto-routing-benchmark/src/cli-runner.ts 86 Prompt/transport change is not captured by the engine identity, so already-ready long-context cases keep their broken no-snapshot measurements and are carried as comparable.
Files Reviewed (5 files)
  • services/auto-routing-benchmark/README.md - 0 issues
  • services/auto-routing-benchmark/container/server.mjs - 0 issues
  • services/auto-routing-benchmark/src/cli-runner.ts - 1 issue
  • services/auto-routing-benchmark/src/cli-runner.test.ts - 0 issues
  • services/auto-routing-benchmark/src/container-auth.test.ts - 0 issues

Note: the container smoke test used a kilo stand-in, so the end-to-end assumption that the deployed CLI (behind the npm wrapper) reads the piped prompt to EOF remains source-evidence only; no defect found, but it is not covered by an automated real-CLI test.

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 36.2K · Output: 3.7K · Cached: 222.7K

Review guidance: REVIEW.md from base branch main

…, price snapshots once, and reserve drain space for re-measures
const [failed] = await orm.batch([
failOrphanedRunningProfilesStatement(orm, failureReason, olderThanIso, nowIso),
orm
.delete(profileRemeasures)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bot: A failed settlement can discard the queued remeasurement request

Suggested fix: When stale claims belong to a completed run whose profile still has old-revision results, release the remeasurement row back to the unclaimed queue (or preserve an operator-visible failed state) instead of deleting it. Alternatively, make run completion conditional on successful settlement and provide a retry path. Add a test where settlement fails, the run completes, and orphan cleanup runs; verify the repair remains discoverable and retryable.

@iscekic

iscekic commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator Author

bot: Closing as superseded. The head of this branch is an ancestor of the #7793 head that merged to main, so every change here is already on main.

@iscekic iscekic closed this Oct 19, 2026
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