Repository navigation
[PR] feat: fold before pi's cancelled auto-compaction (POST /__bili/plugin/compress) - #6351
HS-Jack-YZY wants to merge 7 commits into
Conversation
cb77c05 to
dc6f364
Compare
[bot] 🏷 查重 (duplicate screening): 不重复 (not a duplicate). Review of #6351 — rebased to current master (
What the PR does (verified in code):
Findings / concerns:
Code quality: good — naming, doc comments, and tests with teeth (real pi On the author's question — "taken further, or left as it is?": my read is that this is a clean, well-tested, self-contained implementation of shape (a) that resolves the reported symptom (#6199: "a host sees nothing while the proxy compresses"). I'd recommend merging as is; the open follow-ups (omp parity, a retention cap, a TUI "done elsewhere" channel) are genuinely separate work and don't block this. Final call is yours. 8问 (reviewer checklist):
判定: 代码质量过关、测试有牙、CI 绿、rebase 干净。建议可合(human merge tier,非 auto-merge)。"taken further vs left as is" 是 owner 决策——我的推荐是按现状合入,omp 对齐 / 保留上限 / TUI "done elsewhere" 通道作为独立后续。 |
…the unrelated ranxianglei#6351 The two comments introduced by this PR cite ranxianglei#6351, which is an unrelated open PR (fold before pi's cancelled auto-compaction). The bug they describe is ranxianglei#6356, which this PR closes.
dc6f364 to
5d561d2
Compare
(ci: opencode/qwen3.8-27b) Rebased the PR onto current master and fixed the red CI. Both blockers are resolved and pushed (new head 1. Merge conflict (merge state dirty) — master added 2. Red CI — test 4 "the route folds a plugin session whose answers outgrew its estimate" — the route returned Verified locally: CI status (live check): I could not verify the new head's CI live — the mirror cache is stale ( 八问:
判定:冲突已解、红 CI 已修(本地定向验证通过);新 head 的全量 CI 结果以远程 CI 为准——mirror 缓存当前 stale,本轮未能 live 验证。 |
…ns {3,5,11,14}
The probe anchor PROXY_TOOL_AT=6 was calibrated on 2026-10-31 for ranxianglei#4521
(schedule {4,6,8,9}). The nudge scheduling has shifted again — nudge now
lands at {3,5,11,14}. Re-calibrate the anchor to the next nudge-carrying
request pair (5 → tool round, 6 → fold round). The fold/proxy-tool-round
mechanics under test are unchanged.
Closes: master-red on test (windows-latest, 22, 3) and (ubuntu-latest, 22, 1).
…/compress)
pi's session_before_compact hook cancels pi's own threshold/overflow
compaction, so the proxy folds only when the next request arrives. The
hook now asks the proxy to fold first and then cancels as before:
- src/plugin.ts: the last preflight call of each plugin session is kept
in a WeakMap (memory only, replaced by the next request, dropped with
the session); handlePluginCompress re-enters it under the session lock
and answers {folded} or {skipped}.
- src/server/handle.ts: retain the call at the preflight site for plugin
sessions (stream off, so a hold sends whitespace before the JSON).
- src/server/admin.ts: the loopback-gated route.
- src/agent/shared.ts, src/agent/pi.ts: the pi hook awaits the fold,
bounded by pi's abort signal and a 300 s timeout, and fails open.
- docs/plugin-protocol.md: the endpoint.
Closes ranxianglei#6199
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…anglei#6199 preflight re-entry The ranxianglei#6199 retained preflight closure re-enters runPrepare AFTER ranxianglei#4753's releaseRequestInput (post-forward) has nulled the request's parsed body. runPrepareInner read the mutable parsed slot on every call, so the route's later re-prepare saw null and threw 'TypeError: Cannot read properties of null (reading input)' in prepareResponses. Capture parsed once at the top of runPreparedPipeline (before it can be released) and read that stable capture in runPrepareInner. Existing paths are unchanged: inboundParsed === parsed for the duration of the initial request and the preflight re-prepare; only the post-release route re-entry is fixed.
5d561d2 to
464ef74
Compare
(ai: mnn/qwen3.8-27b) CI re-trigger (attempt 1/6) — merge conflict re-resolved and pushed. This run the PR was dirty again because master advanced past my last rebase: The one conflict was the same
Resolved as a clean union — kept all of master's symbols and inserted Rebase completed clean → the PR's two commits (the Before pushing I confirmed the fork's branch head was still my previous push ( One honest caveat: the mirror cache stayed stale this run too — 八问
收工判定:冲突已解决并 force-push( |
(ai: vllm-qwen/qwen3.8-27b) No action taken this run — the reported merge conflict no longer exists (verified live). Per status-freshness I checked the live state before touching anything:
So there was nothing to rebase (no conflict) and no red CI to fix (none has failed). Per push discipline I did not force-push a no-op rebase onto an already-current head. If any in-flight test shard turns red, the next auto-fix attempt will pick it up. 八问(结构化结论,供人工 review)
结论:本轮 no-op。PR #6351 当前无合并冲突、CI 在跑且无失败, |
…ic wire shape The probe's hardcoded request-index anchors (PROXY_TOOL_AT/FOLD_AT) broke every time the nudge gate's schedule shifted. The last recalibration (245ecb1) was measured on a direct local run (timestamps ON by default since ranxianglei#4313), but CI runs the suite preload pin BILI_MESSAGE_TIMESTAMPS="0" (timestamps OFF) — a different wire shape, a different schedule (no nudge at index 5) — so it passed locally and failed on every CI shard. Root-cause fix instead of another anchor whack-a-mole: - Arm the fold on the first request carrying the ephemeral nudge with >=11 tagged refs; fold on the re-request after the acp_status round. The probe now materializes the ranxianglei#2929 scenario wherever the schedule places it. - Pin compress.messageTimestamps:false so the probe's wire shape is hermetic regardless of how the suite is launched (matches the CI preload pin). Supersedes the 245ecb1 recalibration. Verified: passes with and without the preload pin, same deterministic schedule (nudge at inputs[7], fold at inputs[8]).
[ework] auto-fix stalled: test (windows-latest, 22, 4), test (ubuntu-latest, 24, 3), test (ubuntu-latest, 22, 3) — stopping for human review |
This run addressed the 4 red checks on PR #6351 (3 test shards +
Both are already fixed on the sentinel-maintained New head: 八问
结论:本 PR 侧无回归,4 条红均为继承 master 红,已通过 merge |
This event is stale — it reports the 3 failing test shards from the old head Re-verified live: the mirror cache now shows the PR head is No further work needed this run — the inherited-master failures are already converged via |
[bot] 🏷 APPROVE — fold before pi's cancelled auto-compaction ( Reviewed the full diff (9 files, +530/−32, head Correctness. The re-entry is the same code path as the normal preflight (same Credential handling. The retained call keeps the request's headers (credential) in a Tests. Scope note (non-blocking). The PR bundles two separate concerns: the #2929 test recalibration (schedule-independent fold probe) and the #6922 module-map row ( 8问 (中文):
判定:可合并(APPROVE)。 无 kernel/ 改动,无人工决策项。 |
Closes #6199
This builds shape A as sketched in #6199. Built that way, the re-entered walk folds only when the session moved after the last request's own preflight: k̂ learned from that answer's usage, an overflow arm, or an auto-fold target. Otherwise the route answers
folded: falseand today's behaviour stands. The reason is that every request reaching pi's threshold has already passed preflight under the proxy's target: bili reports no window to pi, pi sends its own window W to the proxy, the proxy judges against W less an output reservation, and pi compacts at W − 16384. How often a session moves enough to fold is not measured. The code and the tests show both cases. Do you want this taken further, or left as it is?What a pi host sees today
Under bili, the plugin's
session_before_compacthandler returns{cancel: true}for pi'sthresholdandoverflowpasses, so that pi and the proxy do not compact twice. Nothing is folded at that moment. The context stays full until the next model request reaches the proxy, and preflight folds it then, on the request path.What it sees after
The handler first POSTs
{conversationId}to a new loopback route,/__bili/plugin/compress, and awaits it. Then it returns{cancel: true}exactly as before, whatever the answer.preflightCompressIfNeededover the conversation's last model request, under the session lock. It uses the same gates and summary rounds that request ran.compaction_startbefore the hook andcompaction_endafter it. So the fold runs inside pi's own compaction span:signalto the fetch.Answers from the route:
{ok: true, folded: true}{ok: true, folded: false}{ok: true, skipped: "no-request"}{ok: false, error}conversationId400404500While summary rounds run, the route may send
200and whitespace before the JSON. This is the hold preflight already gives a non-streaming client.Out of scope:
auto_compaction_*flow can take the same call as a follow-up.What is retained
The proxy keeps each plugin session's last preflight call in a
WeakMapkeyed by the session, in memory only. That call is the request, its headers included, because the summary rounds need its credential. It is replaced by the session's next request and dropped when the session object goes. It is never logged, persisted or returned by any route.Costs, stated plainly
compaction_end {aborted: true}. pi has no way for an extension to report "done elsewhere".Both compression modes
skipped: "no-request". The request path differs only by the plugin check.Licence
The repository is MIT. A contributor's code is taken under the same MIT terms, with the copyright and permission notice kept.
What was run
Run locally with the
npm testrunner's preloads, atcb77c059aunless stated. The head,dc6f364de, differs from it by one word: anexportdropped for theunused-exportscheck, withcheck-unused-exportsandtypecheckre-run on it.npm run typecheck: clean,tests/included.tests/issue6199-pre-compact-fold.test.tsis new and has six tests:AgentSession._runAutoCompactionwith its collaborators stood in, run against a fake proxy. It checks the ordercompaction_start, then the compress POST, thencompaction_end {aborted: true}, and that the hook returned{cancel: true}./compactor an unowned conversation./__bili/plugin/statuscontains it. The next turn ships the summary.no-requestgates.All six pass (
node --import ./tests/preload-storage-baseline.mjs --import ./tests/preload-test-env.mjs --import tsx --test tests/issue6199-pre-compact-fold.test.ts).tests/plugin-agent.test.tspassed at an earlier amend of this commit; the amends since touched only the new test file.The full suite was not run locally; CI's
testlanes run it on the pushed head.🤖 Generated with Claude Code