Repository navigation
[PR] dsh purpose: declare auxiliary requests instead of content-guessing (#6880) - #6883
Conversation
…declares it (#6880) The dsh in-process plugin reads GenerateOptions.purpose off the llm/stream dispatch options (dsh contract: set ONLY on auxiliary calls — session-title / compaction / auto-review / timeline-report; ordinary conversation leaves it unset) and stamps it per fetch as x-bili-plugin-purpose, next to the existing x-bili-plugin(-conversation) marker. Server side: - plugin.ts: pluginPurposeHeader() — honored only behind the x-bili-plugin marker (same trust discipline as the conversation header); an unannounced client's purpose header is inert. - side-request.ts: isSideRequest gains a purpose parameter — a declared purpose classifies the request as side by declaration, outranking every body heuristic (max_tokens<=200 / system-text templates #2503/#4438/ #5656/#5584). Those recognizers stay as the fallback for pre-#6880 plugin installs. KNOWN_AUXILIARY_PURPOSES documents the set (not a gate). - handle.ts: both isSideRequest call sites pass the declared purpose (a declared side request takes the #388 verbatim passthrough and rides the raw persona key — no more |sub:<fp> ghost lanes); the compaction guard short-circuits on purpose=compaction so the marker-DECISIVE INSTRUCTION text check (#2193) is no longer load-bearing for post-#6880 installs while remaining the fallback. Tests: new tests/issue6880-purpose-declaration.test.ts (trust gate, declared sidecar at 4096 budget with template-drifted text, no-header control, unannounced purpose inert, declared compaction survives instruction drift); dsh-llm-stream-attribution.test.ts covers plugin-side capture/stamp (including junk-value degradation).
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.10311-pr.6883.252ed3cThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr6883.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ard) The lane-guard job (#2170) requires a side-lane suite edit alongside any side-request.ts/handle.ts lane change: exhaustively pin isSideRequest's new purpose argument over agent × purpose × the strongest main-shape body (main veto outranks declaration; known side agent wins as before; empty/ absent purpose keeps the pre-#6880 table byte-identical), plus the two blind shapes the template recognizers exist for flipping by declaration without content matching.
(ai: opencode/qwen3.8-27b) Duplicate check: not a duplicate — no other open PR touches dsh purpose declaration; this PR is part 1 of #6880's three-part proposal (#6723 is an unrelated batch PR). Review — PR #6883 (dsh purpose declaration)① Direction gate (original issue). The PR implements part 1 of #6880's three-part proposal: the in-process dsh plugin declares each auxiliary request's ② Regression review (existing-behavior audit). I read the pre-change code on every touched path and judged each existing behavior:
No unintentional regression found. ③ Code review. The trust gate is correctly placed (marker-gated at definition). The ④ Test validity. The new tests are real, not tautological: they spin up an actual server, send real HTTP requests, and assert on the forwarded body (verbatim), session ⑤ Diff cleanliness. 7 files, +371 −10, all on-topic; no unrelated changes, no whitespace churn, no lock-file churn. ⑤b Code cleanliness. Good naming ( Two log-accuracy findings — fixed directly on the PR branch (labeled commit
CI: in progress at the time of this review (30 checks, 0 failed, 12 pending — test shards running). Local targeted: typecheck clean; the 3 PR test files + lane gates + compaction guard 63/63; the dsh/side/plugin lane sweep 652/652. The 19 failures in the broader server/persona/compaction/title/issue sweep are pre-existing on clean HEAD (verified identical failure set in both directions). 八问(中文)
合并判定:代码正确、测试有牙、diff 干净、无回归、rollout 安全。两处日志准确性小修已直接补进 PR 分支(commit |
… the raw session id (#6880) The #6883 purpose header was only stamped for auxiliary dispatches, which left the persona-order ladder (claim races, |sub:<fp> fork rungs) live for dsh main turns even on upgraded plugins. dsh mints one UUID per session and never recycles an id (SESSION_ALREADY_EXISTS in its store), so for a conversation whose plugin declares purposes the raw session id IS the complete identity — the ladder is dead weight there. - dsh-native: stamp x-bili-plugin-purpose on every dispatch — the real dsh purpose for aux calls, or the new "conversation" sentinel for main turns (dsh leaves GenerateOptions.purpose unset for ordinary conversation, so no real purpose can collide; junk values degrade to the sentinel, never the raw value). - plugin.ts: export PLUGIN_PURPOSE_CONVERSATION sentinel. - handle.ts: normalize the sentinel back to "absent" before the side classification (it is a main turn, never a sidecar); a request CARRYING the header in any value skips all four persona-order call sites and keys the verbatim raw id. Pre-#6883 plugins stamp no header and keep the ladder byte-for-byte; persisted |sub: lanes of old traffic become orphan history (new declared traffic never resolves onto them). The declared compaction guard now reads the normalized purpose. - tests: truth-table pin for the sentinel split (#2170 lane-guard), three new handle-level v2 pins (first-sight raw key, system-drift stays raw, sentinel is a main turn), attribution stamps updated to the v2 wire.
6eb3ac9 to
3226c7e
Compare
… the raw session id (#6880) The #6883 purpose header was only stamped for auxiliary dispatches, which left the persona-order ladder (claim races, |sub:<fp> fork rungs) live for dsh main turns even on upgraded plugins. dsh mints one UUID per session and never recycles an id (SESSION_ALREADY_EXISTS in its store), so for a conversation whose plugin declares purposes the raw session id IS the complete identity — the ladder is dead weight there. - dsh-native: stamp x-bili-plugin-purpose on every dispatch — the real dsh purpose for aux calls, or the new "conversation" sentinel for main turns (dsh leaves GenerateOptions.purpose unset for ordinary conversation, so no real purpose can collide; junk values degrade to the sentinel, never the raw value). - plugin.ts: export PLUGIN_PURPOSE_CONVERSATION sentinel. - handle.ts: normalize the sentinel back to "absent" before the side classification (it is a main turn, never a sidecar); a request CARRYING the header in any value skips all four persona-order call sites and keys the verbatim raw id. Pre-#6883 plugins stamp no header and keep the ladder byte-for-byte; persisted |sub: lanes of old traffic become orphan history (new declared traffic never resolves onto them). The declared compaction guard now reads the normalized purpose; the compaction authored/refusal logs and the sideLane label state the ACTUAL identification basis (declared purpose=… instead of claiming the content heuristics) — review follow-up on the original PR, folded in. - tests: truth-table pin for the sentinel split (#2170 lane-guard), three new handle-level v2 pins (first-sight raw key, system-drift stays raw, sentinel is a main turn), attribution stamps updated to the v2 wire.
3226c7e to
4662b07
Compare
ranxianglei
left a comment
There was a problem hiding this comment.
Independent review (fresh clone, re-ran everything myself — complements the ework bot pass, which focused on commits 1–2; the v2 raw-key bypass of commit 4662b074 is the delta I dug into).
Local verification (all on head 4662b074):
npm run typecheckclean;tests/issue6880-purpose-declaration.test.ts+dsh-llm-stream-attribution+side-lane-truth-table+side-request-isolation= 71/71- prefix sweep
dsh-*/side-*/plugin-*/persona-*/compaction-*/title-*/issue*: 3559 pass / 29 fail — the 29 are identical on clean basee0d63bf8(verified in a second worktree: same 66-file subset, same 29). Environment-specific, not PR-caused check:unused-exports+check:test-import-graphclean; remote CI fully green (e2e-dsh lane skips on PRs are the expected three-layer CI behavior — on-demand/cron only)
v2 bypass audit (commit 4662b07) — the part the earlier pass didn't cover:
- All four persona-ladder entry points are gated (
!dshDeclaredPersona && dshPersona && !sideRequestLike): google, anthropic-dsh, openai, responses (src/server/handle.ts). Declared dsh traffic therefore never enterspersonaConversationOrderon any wire. - Fall-through safety verified: declared dsh traffic on the anthropic wire falls to the
claudeAnthropicPersonaOrderAppliesclause, which is false for dsh (src/host-profiles.ts:81personaOrderKeyed: false— onlyclaude-responsesis true); on the responses wire thestableSystemAnchorclause is false (dsh stamps thex-bili-pluginmarker, sopluginAgentHeader !== undefined) andinstructionsFingerprintAppliesis codex/claude-responses-only → both land on the raw key. Structurally safe under the KDD #9 permitlist discipline. - v2 invariant (one dsh UUID = one conversation) verified against the dsh source study in #6880: subagent children always mint a fresh UUID (
packages/subagent/subagent/src/manager.ts:335), forks mint fresh ids, resume reuses the same id. Residual assumption (documented, accepted): a future dsh that ever dispatches a different persona under the same session id without settingpurposewould merge into the main session on v2 — the aux set today always sets it (llm/src/types.ts:600-605), so this holds for current dsh. session-resolve.ts|sub:<fp16(tag)>lanes are a different mechanism (msgid-tag driven, not header driven) — untouched by this PR; declared traffic bypasses them simply because it never reaches the resolver.- Junk-value degradation note: an aux purpose that fails the ASCII/≤64 capture gate degrades to the
conversationsentinel at stamp time (src/agent/dsh-native.ts:2621attr.purpose ?? "conversation") — i.e. it declares MAIN. Unavoidable (unset-main and junk-aux are indistinguishable at the seam) and harmless for current dsh (purposes are fixed ASCII literals), recording it as the accepted trade-off.
One suggestion (owner call, not fixed here): the KDD #9 mechanism text (AGENTS.md line 50 + reference/design-decisions.md) and docs/session-identity-resolution.md describe the persona lane as if it applies to all dsh traffic — commit 3 changed who enters the ladder (declared plugin traffic never does). Per the append-only ledger convention that reads as a new entry (next: #20) or a Tier B addendum, not a rewrite of #9. CI doc lanes are mechanical-sync only, so nothing catches this.
Verdict: approve. No regressions (old plugin byte-identical; new plugin + old server = inert header), tests are toothy (real server, forwarded-body assertions, zero-egress 422, both gate directions), diff is clean and on-topic. Merge once you decide the doc/ledger touch above is in or out of scope for this PR.
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1215-master.d1ff6ea # this exact build
npm install -g billion-context@master # always the newest merged build
|
What & why
The dsh in-process plugin now reads
GenerateOptions.purposeoff thellm/streamdispatch options and stamps it per fetch asx-bili-plugin-purpose. dsh's contract for that field: set ONLY on auxiliary calls (session-title / compaction / auto-review / timeline-report) — ordinary conversation leaves it unset. So presence of the header is the side/main signal, and bili stops guessing which requests are auxiliary by matching body content (the #2503/#4438/#5656/#5584 template chain, the ≤200-token budget rule).Background: #6880 (dsh source study — every auxiliary call passes
purposeon the same dispatch seam the plugin already listens on).Changes
Plugin side (
src/agent/dsh-native.ts)llm/streamlistener capturesoptions.purpose(ASCII-gated, ≤64 chars; absent/junk values simply stay off the wire — same degradation discipline as the sid capture)x-bili-plugin-purposenext tox-bili-plugin/x-bili-plugin-conversationServer side
src/plugin.ts:pluginPurposeHeader()— honored only behind thex-bili-pluginmarker (same trust discipline as the conversation header); an unannounced client's purpose header is inert telemetrysrc/server/side-request.ts:isSideRequest(parsed, requestAgent?, purpose?)— a declared purpose classifies the request as side by declaration, outranking every body heuristic; the content recognizers stay as the fallback for pre-[Design][dsh] Stop guessing dsh's auxiliary requests — the in-process plugin can declare each request's purpose explicitly #6880 plugin installs.KNOWN_AUXILIARY_PURPOSESdocuments the known set (documentation, not a gate — a brand-new dsh sidecar purpose needs no bili recognizer anymore)src/server/handle.ts:isSideRequestcall sites pass the declared purpose → declared side requests take the 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 verbatim passthrough and ride the raw persona key (no more|sub:<fp>ghost lanes for them)purpose=compaction, so the marker-DECISIVE INSTRUCTION text check ([dsh] 原生压缩拦截门的 SHAPE 信号(≤4 条消息)在 dsh-compaction-basic 0.2.0-rc.2 上恒假 → 压缩静默落地 → 1510 条 fold 锚点永久失配,连刷 166 条 no-anchor-match 且面板仍报 netSaved 355.9M #2193 lesson: a stale shape goes silent) is no longer load-bearing for post-[Design][dsh] Stop guessing dsh's auxiliary requests — the in-process plugin can declare each request's purpose explicitly #6880 installs; it remains the fallback for old installsRollout safety
Tests
tests/issue6880-purpose-declaration.test.ts: trust gate (purpose without marker is inert), declared title sidecar at 4096 budget with template-drifted text → raw-key passthrough, no-header control, declared compaction under instruction drift → guard still fires (422, zero egress)tests/dsh-llm-stream-attribution.test.ts: plugin-side capture + stamp, junk-value degradation (control chars / >64 / spaces / non-ASCII / non-strings)Local: typecheck clean,
dsh-*/side-*/plugin-*649/650 (the 1 failure —dsh-tool-registration-lifetime— fails identically on clean HEAD in this environment),server-*/persona-*/compaction-*/title-*/issue*sweep failures verified pre-existing on clean HEAD, unused-exports + test-import-graph gates clean.