Repository navigation
feat(agent): opencode v2 local compression kernel — no proxy, mode parity with bili pi - #909
ranxianglei wants to merge 10 commits into
Conversation
… inside opencode with no proxy Mode 3 for opencode v2, mirroring bili pi: session.event 'context.window.changed' feeds the full transcript into the kernel, the wire view is rebuilt with synthetic summaries + nudge, and the compress tool runs inside opencode (carrier = the tool call, acp_summary suppressed). /compact is intercepted (markCompaction archives blocks whose raw ids left the transcript). Remote proxy mode stays the default.
…ds collapsed every result onto one ref and looped the model v2's context projection emits tool-result messages with id undefined, so the positional core id became "undefined:0" for every call: the kernel deduped them into one message and the rebuild orphaned all later tool calls — the provider filled the gaps with opencode's 'Tool result missing' placeholder and the model re-issued acp_status in a loop (repro'd live in the rig TUI). Tool-result cores now carry tr_<callId> and the rebuild re-attaches each original part by call id.
…e entries by call id (tr_) so results survive the rebuild instead of collapsing onto "undefined:0" and orphaning every tool call (the acp_status loop / "Tool result missing" bug)
… — hostLabel through RewriteCtx/AcpStatusCtx; fix VERSION resolution for dist/agent/*.js depth (package.json walk-up)
…g-format note - acp_status default (no drilldown args) now leads with the same buildStatusPanel /acp renders, followed by the structured report; drilldown queries (scope/view/tool/sort/limit) keep the report alone - stripEchoes gate compared against the literal 8-char string '\x3cacp' instead of the real tag bytes, so model-echoed tags were never stripped on ingest; use the actual hex escape - the shared kernel prompts teach the PROXY tag format (example type="tool:bash", every message tagged); the local host renders text-only so the example mismatched reality and the model fabricated proxy-style tags (observed type="tool:acp_status" written before a tool call). withLocalTagFormatNote appends the actual format + the no-write rule to the local system prompt
…array in-place push - loop/core.ts: a user ESC breaks the parse loop with !sawDone && streamError === undefined — the exact shape the #498 weak-overflow detector counts. Three aborts inside 15min would learn a shrunken context window for the session (#570 false-positive family, MIN_EVENTS=3). Guard the counter with !signal?.aborted, mirroring the existing truncation/degenerate retry guards. - agent/opencode-local.ts: build the compress system array with a spread instead of in-place push — if the host ever reuses e.system across requests or fires the hook twice per request, the push would append one full compress prompt per request and grow the window linearly. - tests/loop-truncation.test.ts #887 T1: aborted cut vs control cut — abort must not count, the same cut without abort must.
[bot] 🏷 Reviewing #909 now. Plan: pull the head branch, diff against the #850 base, run typecheck + full test suite + build on the rebased head, and verify each of the five fixes riding on this branch (tool-result core keying, acp_status panel-first, echo strip, weak-overflow abort guard, system-array spread). Will report findings here with a mergeability verdict. |
The history rewrite that dropped the tracked iso/build artifact also swallowed three unrelated dev-tool scripts (registry/codex-models snapshot refreshers, dump analyzer) into commit e59776b, whose message describes the tr_ keying fix. package.json still wires 'npm run registry:snapshot' / 'codex-models:snapshot' to them, so the deletion broke those scripts. Restore verbatim from the #850 base.
src/compress-tool.ts (LOCAL_TAG_FORMAT_NOTE + its doc comment) and src/agent/opencode-local.ts (stripEchoes comment) carried literal angle-bracket tags; every other source file uses \x3c/\x3e escapes so agent editing tools can't strip them. Runtime string values are byte-identical (verified: typecheck + opencode-local/loop-truncation/plugin-agent tests green).
[bot] 🏷 Review complete. I pulled the head, diffed against the #850 base ( Fixed on this branch (2 commits)1. 2. Riding fixes — verified
Non-blocking notes (no action taken)
Pre-flight & E2E
Diff is otherwise clean — every line traces to the feature or the five recorded fixes. Everything verified above passes with my two commits included. Ready for you to merge (merges stay human-side). 中文摘要:修复了分支上两个问题——e59776b 误删的 3 个 snapshot/devtool 脚本(package.json 仍引用,会坏掉 npm scripts,已按 base 原样恢复)和两处源码里违反 hex-escape 规范的裸 acp 标签(运行时字节不变,已验证);五个随行修复逐条核对无误,全量测试通过,本环境缺本地上游跑不了完整 E2E(代理侧日志显示管线执行正常),可以合并。 |
|
Closing — superseded by architectural decision (align on the Why: this PR's in-process kernel has no wire seam, so it cannot do stream-time echo stripping ( The pi-parity architecture already exists on master: Salvaged from this PR into #910: the mode-independent loop fix (client abort miscounted as weak overflow, |
A client abort breaks the parse loop at the signal check with !sawDone && streamError === undefined — the same shape as a truncation. Three ESCs inside 15min armed a shrunken window (MIN_EVENTS=3) that throttles the session below its true window (ranxianglei#570 false-positive family). Refs ranxianglei#906. Re-lands the loop half of ranxianglei#909 on master (the opencode-local half is superseded — see ranxianglei#909 close reason).
Fixes #908. Stacked on #850 (same convention as #885: base is the #850 source branch so the stack lands together).
What
src/agent/opencode-local.ts— an opencode v2 plugin that runs the acp-kernel compression pipeline IN-PROCESS, giving opencode the same pure-local modebili piusers get: no proxy hop, noBILLION_CONTEXT_PROXY, no MITM, wire traffic straight to the real upstream.session.hookrebuilds the wire view through the kernel (folded messages,acptags on text parts)chat.params.toolsinjects the kernel compress/decompress/acp_status tool set;chat.parametersenforces the compress system prompt (with a local tag-format note — the shared prompt teaches proxy-style tags)acp_statusrenders the same panel as/acp, panel-first, with its own host identity (billion-context-opencode-local@version)Fixes riding on this branch (recorded in #906)
${msg.id}:${i}collapsed every result onto one ref (undefined:0), orphaning each tool call and looping the model (theacp_status×7 / "Tool result missing" bug). Keyed bytr_call id now.'\\x3cacp'that never matched real tag bytes; model-fabricated tags now stripped on ingestsrc/loop/core.ts) — a user ESC broke the parse loop with!sawDone && streamError === undefined, the exact shape the 高 usage 下的非 400 失败(流截断/超时)无任何 overflow 兜底 —— 会话直接死 #498 detector counts; 3 aborts in 15min would learn a shrunken window. Now&& !signal?.aborted, mirroring the existing retry guards. Regression:tests/loop-truncation.test.ts[Bug] 消息引用编号与当前顺序不一致时,compress 范围提示会选错消息,导致“内容不足”失败 #887 T1 (aborted cut must not count; same cut without abort must).e.systemor double-fired hook can no longer append duplicate compress prompts.Pre-flight
npm run typecheck✓npm test— 1673 pass / 0 fail (incl. 11 newtests/opencode-local.test.tstests)npm run build✓ (tsup entry includessrc/agent/opencode-local.ts)E2E (Docker-isolated, real opencode v2 + local sglang)
Four postures green: proxy / launcher / native-spawn / pure-local. Compression stress test in-container: model read ~200K tokens of real source, self-triggered compress 7× (105K folded), refs strictly monotonic, no id reuse, recall-from-summary verified, no tag leakage.
(Note: an early local commit accidentally tracked
iso/build/opencode.exe(207MB rig build artifact); history was rewritten before the first successful push — the branch on origin has never carried it.)