Repository navigation
fix: isolate side requests (title-gen) from main session kernel state - #398
Conversation
…#388) Side requests (title-gen / small utility calls) share the main session key but were running the full prepare pipeline: processTurn (assignRefs / advanceSurvival), session.stats.contextTokens rewrite, snapshotMessages, and rememberPluginMessages. A 56-token title-gen request could clobber the main session's acp_status view, nudge baseline, and per-block survivedCount. - Add isSideRequest(parsed): tiny output budget (max_tokens / max_completion_tokens / max_output_tokens <= 200, same heuristic as prepareOpenai's isTitleGen). Missing/non-positive budget is never a side req. - In handle(), route side requests (non-count-tokens, non-responses-compact) as pure passthrough (forward with prepared=null): no processTurn, no snapshot, no usage capture, no stats mutation, no rememberPluginMessages. - Regression test tests/side-request-isolation.test.ts: unit test for isSideRequest + e2e asserting a side request leaves kernel state, stats, snapshot and nudge baseline byte-identical while main requests advance it. - launcher-plugin-mode tests used an unrealistic max_tokens:10 that collided with the heuristic; bumped to 8192 (they verify binding, not budget). Pre-flight: typecheck clean, 870/870 tests pass, build OK. E2E codex suite skipped locally (no codex binary / local upstream); runs in CI.
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-398Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr398.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 已审查本 PR(分支 正确性(src/server.ts,已对上下文代码逐行核对,非只看 diff):
pre-flight(本地实跑,非引用 PR 作者结论):
测试质量:
边界/注意点(不阻塞):
合规:分支名 建议(合并前):AGENTS.md 要求改动 request pipeline( 验收标准对照(来自 #388):✅ 侧请求前后主会话 acp_status 桶 / ranges / nudge 基线 / 各块 survivedCount 不变;✅ LGTM,待人工合并。 |
[bot] 🏷 独立复核了跟进提交 核心改动(逐行追了
夹具分离干净
我的预检(8b88162,自跑)
合并前建议:AGENTS.md 要求请求管线改动(server.ts 命中)合并前跑 E2E codex 套件。本地无配置好的 upstream,E2E 跑不了 → 请手动触发 CI( 按规则我不合并(PR merge 仅人工)。整体:修复正确、最小、契约齐备,可进 CI。 |
…ess (kernel ranxianglei#398/ranxianglei#403) Kernel 0.0.90 ships the refold-in-place stack (ranxianglei#398/ranxianglei#400/ranxianglei#402) but markBlockRestoredInline had no host caller — the capability was inert in bili's proxy lane: a decompress→recompress loop could never refold, and the kernel's blocked-refold guidance promised an inline-restore path that never materialized on this wire. Wiring: resolveDecompress flips restoredInline (and markDirty) on a successful FULL-BLOCK restore (default one-level view or full) — the tool result stays in the client's re-sent history, so the model holds the re-summarization material. Range restores (startId/endId) return partial content and must NOT flip the flag; inactive blocks are skipped. Tests (tests/refold-wiring.test.ts): flag flip + idempotence, full:true parity, range-restore exclusion, end-to-end proxy-shaped refold (empty view, in-place update, marker cleared, no second block), and a negative control pinning the honest already-compressed rejection. Downstream verification against the published 0.0.90: typecheck ✓, full suite 2559 pass / 0 fail, build ✓.
…refs When the proxy holds no live message view of a session (in-memory copy dropped between model requests by resident-pool eviction or restart) but the refs table is intact, applyRanges fed an empty message list into the kernel: every requested ref was judged dangling, marked DEAD in deadRefs (committed + persisted even on total failure), and receipts blamed content-changed / substrate-destruction while the breaker armed with a false cause. The refs were never actually changed — the next model request restores the view and clears the tombstones anyway. - new gate in applyRanges (+ external-summary lane): refuse with reason gate:no-visible-context and an honest receipt (refs intact, nothing recorded as dead, do-not-retry-until-next-model-request); writes no deadRefs; feeds the loop breaker the true cause - the gate YIELDS when any requested range overlaps an active compression block (#398/#403 refold works from state alone under a proxy-shaped empty view) and for fresh ref-less sessions (unchanged kernel diagnostics) - noteCompressLoopFailure gains forcedCause so the breaker records the honest cause without re-running failure-cause inference - resident-pool evictions are now logged (session id, weight, budget) so the empty-view window is observable instead of silent
…ianglei#3371) screenRecommendedUnits advertised a message-ref unit whose entire span is already owned by an active, NOT restored-inline block — the exact shape applySingleRange's livelock guard (pi#199) is guaranteed to reject ('Range .. contains no new compressible messages'), unless the ranxianglei#398 refold verdict classifies it a genuine in-place refold. Recommend and apply disagreed on one shape: advertise -> reject -> re-advertise, the ranxianglei#3236 loop family reached through the consumed-unit corner. The verdict (evaluateRefold + requestedRefoldSpan + RefoldDecision) moves verbatim from compress.ts to refold.ts so both lanes consult the SAME definition — the projectUnit discipline. The screen now mirrors the apply-side guard exactly: filteredIds === 0 && consumedBlockIds > 0 && !isBlockBoundary survives only when evaluateRefold says 'refold'. Block-boundary units (bN..bM promote/merge) stay exempt, same as apply. No public kernel surface change; the golden ledger is untouched. Also bumps kernel to 0.0.127 and regenerates package-lock.json, which had drifted to 0.0.123 through six version bumps (ranxianglei#3331 review C-H1) — npm ci in a clean checkout would have failed. Kernel boundary: owner-approved via ranxianglei#3371. Tests: kernel suite 1279/1279 incl. new issue3371 fixture (screened-out shape + apply agreement, genuine refold stays advertised and updates b1 in place, fresh spans unaffected); bili-side compress-reject-reasons 4/4, compress-recovery-ranges 10/10, e2e-compress-cascade 7/7; root tsc clean. Closes ranxianglei#3371
The fold→inline-decompress→refold cycle (#398) updates a block in place with its originals off the wire, so live derivation finds nothing and the carried-from-own-previous-summary branch is the ONLY source of the folded-images footer. None of the original five lanes exercised it — teeth-check: with that branch disabled, this lane is the one that fails.
Fixes #388
Side requests (title-gen / small utility calls) share the main session key but were running the full prepare pipeline. A 56-token title-gen request could clobber the main session's
acp_statusview, nudge baseline, and per-blocksurvivedCount.Root cause
rememberPluginMessages(...)ran for every forwarded request (incl. side requests) —acp_statusreads that "last prepare view".prepareAnthropic/prepareOpenai/prepareResponseshad no side-request guard → side requests ranprocessTurn(assignRefs/advanceSurvival), rewrotesession.stats.contextTokens(nudge baseline), and calledsnapshotMessages.isTitleGenexisted but only gated tool injection, never the snapshot/state.Change
isSideRequest(parsed)(src/server.ts): tiny output budget —max_tokens/max_completion_tokens/max_output_tokens≤ 200 (same heuristic asprepareOpenai'sisTitleGen). Missing/non-positive budget is never a side request.handle(): side requests (non-count-tokens, non-responses-compact) are routed as pure passthrough (forwardwithprepared=null) — noprocessTurn, no snapshot, no usage capture, no stats mutation, norememberPluginMessages. The main session's kernel state is driven only by main requests.tests/side-request-isolation.test.ts: unit test forisSideRequest+ e2e asserting a side request leaves kernel state / stats / snapshot / nudge baseline byte-identical while main requests advance it (monotonic).launcher-plugin-modetests used an unrealisticmax_tokens:10that collided with the heuristic; bumped to8192(they verify binding, not budget).Pre-flight
npm run typecheckcleannpm test870/870 passnpm run buildOKcodexbinary / local upstream); runs in CICloses #388