Repository navigation
fix: classify opencode v2 title-gen by host-declared intent, not token budget (#1699) - #1703
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1652-pr.1703.0d0acf5This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1703.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…n budget (#1699) opencode v2 sends title-gen requests with NO max_tokens (options {} for kind==="title"), so bili's isTitleGen / side-request heuristic — which defaults a missing output budget to 8192 — misclassified them as main turns and injected the full ~11KiB compress philosophy prompt + ACP compress tool into the title model. Result: garbage session titles (English chat sentence / empty first line). Forward the host's per-request persona id on a new x-bili-plugin-agent header (stamped by the opencode v2 plugin from its own request scope) and treat a known side-request agent ("title") as a side request BY INTENT, routing it verbatim (no injection, kernel state untouched) regardless of output budget. Main personas (build/plan/general) are deliberately absent from the set, so real turns keep compression. The header reader is gated on plugin announcement so a plain client cannot declare a side request by name to dodge compression. Behavior change (intended): an opencode v2 title-gen request WITHOUT max_tokens now routes verbatim instead of being treated as a main turn. Previously it got the full compress philosophy prompt + tool injected; now it does not. This only affects requests that carry x-bili-plugin-agent: title; every other request is untouched.
…1655 hardening dropped the import but missed this call) Drive-by fix for a pre-existing master breakage found while reviewing PR #1703: master's CI is red because this finally block calls rmSync, which #1646/#1655 removed from the imports when converting teardowns to the retry-hardened rmrf helper (tests/tmp-rm.ts). Every other teardown in this file already uses rmrf; this one was missed. Without it, every PR merge-ref run fails here.
908163c to
fdc4d40
Compare
[bot] 🏷 Review complete — PR is in good shape; I rebased it onto current master and fixed a pre-existing master test breakage that was red-flagging every job. Details below. ① Original issue direction (#1699): correctRoot-cause chain verified end-to-end: opencode v2 title-gen omits Duplicate screening: not a duplicate of anything open/closed. Related-but-distinct: #1309/#1431 (auxiliary-request isolation via anchor affinity) share the side-request problem family but address session routing, not classification — flagging so the overlap is visible when you settle the unified strategy under #1309. ② Regression audit — existing behaviors on touched paths, each verdict
③ Code reviewClean and minimal (+98/-4 across 5 files, every line on-purpose). Two observations (non-blocking):
④ Test validityThe two new tests have teeth. Unit: intent outranks both the budget heuristic and the tools guard; ⑤ Diff cleanlinessClean — no unrelated churn; the import-line union keeping
|
…batim routing CI failed 'not ok 3' on the v2 lane: v2's title-gen request re-sends the first user message (the filler) to the title model concurrently with the main request, and after #1703 it routes VERBATIM — no ACP ref tags, no injected tools. Whichever row lands first in the reqLog is a race; when the title row won, find() matched it and the ref-tag assertion failed. - fake-upstream-chat.mjs: oracle rows now carry title:true (the detector already existed to answer title calls inertly). - test 3: skip title rows when locating the filler turn; add a v2-gated pin that title rows must arrive verbatim (lastUserRef null, no compress tool) — the #1699 regression pin. v1 title calls carry neither the v2 agent header nor max_tokens and were never side-classified; unchanged. Local: v2.0.3 lane 4/4, v1.14.47 lane 4/4, typecheck clean.
Closes #1699
Problem
opencode v2 sends title-generation requests with no
max_tokens(options {}forkind === "title"). bili'sisTitleGen/ side-request heuristic defaults a missing output budget to 8192, so those requests were misclassified as normal main turns and got the full ~11 KiB compress philosophy system prompt + ACP compress tool injected into the title model → garbage session titles (an English chat sentence, or an empty first line).Root cause
The side-request classification keys off the token budget — exactly the field opencode v2 omits for title-gen. The intent ("this is a side/title request") exists on the host but was never forwarded to the proxy.
Fix (intent-based, inert-safe)
Forward the host's per-request persona id on a new internal plugin-protocol header, and treat a known side-request agent as a side request by intent:
src/agent/opencode-v2.ts— the opencode v2 plugin stampsx-bili-plugin-agent: <persona>from its own request scope (the sharedcreateOpencodeV2Setupcovers both launcher and native V2 modes).src/plugin.ts— newPLUGIN_REQUEST_AGENT_HEADERconstant +pluginRequestAgentHeader()reader, gated on plugin announcement so a plain client cannot declare a side request by name to dodge compression (same gate as the window/model headers).src/server/side-request.ts—isSideRequest(parsed, requestAgent?): a known side agent (SIDE_REQUEST_AGENTS = {"title"}) is a side request regardless of budget. Main personas (build/plan/general) are deliberately absent, so real turns keep compression. An unknown persona id is inert (falls back to the budget heuristic).src/server.ts— the existing verbatim side-request gate passes the intent through; such requests forward verbatim (no injection, kernel state untouched), consistent with how tiny-budget title-gen already routed.This reuses bili's existing title-gen routing (verbatim passthrough) rather than inventing a new mechanism, and is inert-safe: when the header is absent (older hosts, all other clients) behavior is byte-for-byte unchanged.
Behavior change (intended)
An opencode v2 title-gen request without
max_tokensnow routes verbatim (no compress prompt/tool injected) instead of being treated as a main turn. Old: full ~11 KiB philosophy prompt + tool injected. New: nothing injected. Only requests carryingx-bili-plugin-agent: titleare affected; every other request is untouched.Config surface
None. The new item is an internal plugin↔proxy protocol header (alongside the existing
x-bili-plugin-model/-context-window/-max-output), not a user-facing config field, env var, or CLI flag. No config-schema change.Verification (rebased onto current master)
npm run typecheck— cleannpm test— 3246 tests, 0 fail, including two new opencode v2 title-gen requests get injected with compression philosophy (misclassified by isTitleGen) #1699 regression tests (unit classification + e2e verbatim-vs-injected contrast that reproduces the bug without the header and proves the fix with it)npm run build— successisPluginFoldCallId) during rebase; both symbols kept.127.0.0.1:8199) is unreachable in this sandbox, so it ran locally only as a zero-token preflight (codex 0.147.0 + dist present). CI (ci-e2e.yml) auto-runs the full suite because this diff touchessrc/server.ts; the change is inert on the non-x-bili-plugin-agentpath, so the codex path is unaffected.Review follow-up (2026-09-29, post-review rebase)
8293a542) — clean, no conflicts; branch is now linear (supersedes the interim "Update branch" merge commit, tree-identical apart from the fix below).tests/issue1086-chain-self-exemption.test.ts:728calls barermSync, which the test: teardown rmSync ENOTEMPTY race — most test cleanups lack retry options (CI ubuntu-latest Node 22 flake) #1646/test: harden all recursive rmSync teardowns with retry options #1655 teardown hardening removed from the file's imports when converting teardowns to the retry-hardenedrmrfhelper (tests/tmp-rm.ts); every other teardown in the file already usesrmrf, this one was missed. DeterministicReferenceError, so every PR merge-ref run (and master itself) fails here. Fixed with the samermrf(root)helper — no import change needed. Labeled as its own commit.npm run typecheckclean ·npm run buildsuccess (dist-import-annotations OK) · full suite 3273 tests / 3261 pass / 0 fail / 12 skip.