Skip to content

feat: codex compact family — combined #322/#323/#324/#325/#317/#319 + UA unification - #336

Merged
ranxianglei merged 25 commits into
masterfrom
2026-08-29_codex-compact-family
Aug 29, 2026
Merged

ranxianglei merged 25 commits into
masterfrom
2026-08-29_codex-compact-family

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Model: glm-5.3 (via pi)

What

One combined PR of the six downstream PRs of #249 (via the #321 layered plan), so they land, get reviewed, and get tested as the unit they were designed to be:

Included Content
#322 launcher aligns codex auto-compact budget with bili window (resolveCodexBudgetArgs)
#323 native-compaction rebase detection gated on SSE semantic terminal (response.completed/response.failed), not HTTP status
#324 src/codex-models.ts: codex perceived-window table (bundled snapshot + 272k fallback) + codexAlignedWindow min() clamp
#325 src/codex-compact.ts: intercept codex native compaction, forge 2-event SSE (fc_bili_ ACP summary), strip echo next request; kill-switch `BILI_CODEX_COMPACT=intercept
#317 x-codex-turn-metadata partition: thread_source=="user" → session-id, any other value → thread-id (guardian family included)
#319 anonymous tail-window reattach, any-offset substring search on stored itemHashes
new UA unification: codex-models.ts had its own isCodexClient matching only codex_cli_rs/ — missed codex_exec/ (the exec-mode UA, the same dead-code class fixed on #325 in c507e0c). Now imports the single CODEX_UA_PREFIXES implementation from codex-compact.ts (0074964)

The one merge conflict (src/server.ts Prepared object, #324×#325) was resolved keeping both fields — resetAfterSuccess and codexForge.

Why one PR

Verification (all on this exact tree)

  • npm run typecheck ✅
  • npm test 816/816 ✅
  • npm run build ✅
  • e2e full suite incl. forge phase (real codex 0.147 exec + local sglang qwen3.8-27b, ~8 min): pass 1 fail 0. Evidence from the run log:
    • preflight compressed 3 range(s) … (34384 → 32013)
    • codex compact intercepted (trigger); forged SSE with 2 block summary(s), upstream not contacted
    • stripped 1 bili compaction item(s) echoed by codex (echo stripping verified on subsequent turns)
  • Cross-PR interaction review: delegated reviewer, findings folded in before merge.

Supersedes

#317 #319 #322 #323 #324 #325 (close after this merges; #249 closes as superseded by the family, #326 stays closed-recommendation).

ework-agent and others added 19 commits August 28, 2026 22:32
Codex (>=0.147) reuses the root session-id header on subagent threads, so
the legacy identity chain mapped every thread of one task onto a single
session — subagents inherited the root's compression state, breaking #150's
isolation (a guardian subagent must read the user's original authorization
verbatim, never a compressed summary).

Add codexTurnIdentity(): when x-codex-turn-metadata is present and
cross-checked (metadata.thread_id === thread-id header), partition by
thread_source — "user" keeps the session-id header (current root
semantics, stable across turns), "subagent" gets its own thread-id (fresh
independent state per thread). Untrusted metadata (absent / unparseable /
mismatched / unknown thread_source) falls through to the legacy chain
unchanged, so no-metadata clients (omp pck, etc.) see zero regression.

The trusted id enters the verbatim session chain directly (no hashing, no
new dimensions) and bypasses subagentNamespace, leaving the kernel's
empty-instructions non-anchoring path untouched for metadata-less clients.

Tests: unit coverage for both thread_source values, cross-check mismatch,
JSON parse failure, unknown thread_source, missing headers, omp pck chain
unaffected; plus a server-level test proving subagent and root threads land
in distinct isolated sessions.
…ty (#316 PR-B)

A client that drops its oldest messages (truncation) previously failed the
full-depth prefix match and was orphaned into a fresh pfa- session, stranding
the old session's compression blocks. resolve() now falls back to a
tail-window comparison: the incoming's leading items are matched against each
stored chain's trailing items (position-independent per-item hashes), so a
truncated replay reattaches its original session and the kernel reconciles by
message id (verified: blocks deactivate gracefully on truncation and revive on
full replay, no throw).

New pfa- sessions also record a best-effort lineage (discarded candidates +
reason truncated/forked) in session metadata for UI/debug only — never used
for matching. Live-edge overwrite semantics unchanged.

- src/prefix-affinity.ts: TAIL_WINDOW/MIN_TAIL_MATCH/MAX_STORED_ITEMS/
  MIN_FORK_PREFIX; perItemHashes + lcpLength; resolve() gains tail-window
  reattach + lineage; note() stores per-item hashes; AnonymousAffinity gains
  via + itemHashes + lineage.
- src/server.ts: tail-window reattach log line; note() 4th arg; metadata
  records via + lineage.
- tests/prefix-affinity.test.ts: note() call sites updated to 4 args.
- tests/tail-window-reconcile.test.ts (new): tail-window reattach, prefix/new
  regressions, fork + truncated lineage, and a kernel reconcile anchor test.

Independent of PR-A (codex turn-metadata, #317). Pre-flight: typecheck OK,
746/746 tests, build OK.
guardian_review / guardian_classifier (Feature string) / memory_consolidation
threads previously fell back to the legacy chain and landed on the root
session — the exact #150 isolation violation. Invert the discrimination:
only "user" joins the root session; every other thread_source with a valid
thread_id cross-check partitions by thread-id.
…tail (PR review)

Tail-pinned matching only reattached when the client retained <=
TAIL_WINDOW (8) items; a rolling-window client keeping 20-30 items
orphaned on every slide. Search the incoming's leading window across the
stored chain's per-item hashes at any offset (<= 57 offsets x 8 compares,
trivial). MAX_STORED_ITEMS 64 -> 128 so deeper windows stay searchable.
…R-C)

The rebase marker fired on ANY 2xx upstream response, so a failed,
incomplete, or truncated compaction stream scheduled a rebase on top of a
compaction that never happened (the #249 false-rebase bug): bili discarded
valid blocks and mis-tracked the ledger.

- new src/stream-terminal.ts: terminal-state observer for Responses
  responses. SSE: response.completed -> completed, response.failed /
  response.incomplete -> failed, no terminal event before EOF -> unknown.
  JSON: output array -> completed, error field -> failed, unparseable /
  empty / oversized -> unknown. unknown is the safe default (no rebase;
  next request self-heals via kernel message-id deactivation).
- server.ts: both markNativeCompactionBoundary call sites now gate on
  observed terminal === completed. 2xx empty body no longer rebases.
- trigger-path hardening in prepareResponses: a trailing
  compaction_trigger request is detected BEFORE injection — no compress
  system prompt, no compress tools, renderTags none, compressInjected
  false (response flows through plain passthrough instead of the
  rewriter), and resetAfterSuccess is set so its terminal state gates
  the rebase. Nudge skip now keys off the same pre-injection detection.
- tests: 16 unit tests for the observer + e2e through the proxy covering
  completed / failed / truncated / 2xx-error-JSON / empty-body /
  JSON-output and the clean-forward assertions; finality-test control
  moved to a separate session (a completed trigger now rebases the
  compacting session, legitimately disarming its nudge).
…321 PR-E2)

When BILI_CODEX_COMPACT=intercept, the client is codex (UA codex_cli_rs/),
and the ACP state is healthy (transform ok + steady-state < 90% of window +
an active block to hand off), bili forges a success response for codex's
native compaction requests and never contacts upstream — a deterministic
handoff to the ACP state:

- trigger form (input ends with compaction_trigger): forged 2-frame SSE
  (response.output_item.done with one {type:compaction, id:fc_bili_*,
  encrypted_content:bili:acp:<summary>} + response.completed with honest
  usage). Matches codex's collect_compaction_output contract (exactly one
  compaction item + response.completed; all other events ignored).
- endpoint form (POST /responses/compact): forged JSON {output:[...]} where
  output is the rebuilt history (recent items + ACP summary), matching
  codex's CompactHistoryResponse parser.

Otherwise (kill-switch off by default, ACP not keeping up >= 90%, or nothing
compressed yet) the request passes through to upstream and native compaction
backstops (rebased by the PR-C semantic gate). Bili-generated compaction
items (fc_bili_ prefix / bili:acp: sentinel) are stripped from subsequent
requests so codex's echoed item does not double-count.

Pre-flight: typecheck clean; 752/752 tests (7 unit + 5 e2e new); build ok;
forge code verified inlined in dist.
The /bili/ prefix section had no Claude Code entry. Add it (claude's undici
fetch ignores HTTPS_PROXY, so the /bili/ URL form via ANTHROPIC_BASE_URL is
the only manual option) plus a note that manual mode must set
CLAUDE_CODE_AUTO_COMPACT_WINDOW itself — the bili claude launcher does this
automatically (PR-D) but manual /bili/ users do not get the injection.
claude clamps the value down to its perceived model window, so over-setting
is safe. EN + zh-CN.
…/0.147.0, so the intercept never fired for real exec-mode clients (verified by real-device e2e: isCodex=true, gate=true, forged SSE accepted)
…pt' into 2026-08-29_codex-compact-family

# Conflicts:
#	src/server.ts
@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-08-29_codex-compact-family (e6b822d)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-336

Each push to this PR publishes a new version under the pr-336 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr336.tgz
npm install -g package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · vllm-qwen/qwen3.8-27b

[bot] Picked up. Reviewing PR #336 now: fetching the combined tree, re-running typecheck/test/build, and auditing each of the six included PRs plus the UA-unification commit. Will report findings here.

@ranxianglei

Copy link
Copy Markdown
Owner Author

Comprehensive cross-PR review (delegated reviewer, on this exact tree)

Verified clean: conflict resolution (both resetAfterSuccess+codexForge kept, paths mutually exclusive), clamp ordering (identity→clamp→preflight→upstream), preflight×intercept composition, turn-metadata partition×intercept/affinity, #322×#324 composition (min(bili, codex table), user override suppresses injection), stream observer soundness. Typecheck clean, no as any, no conflict markers.

1. MAJOR — trigger-form intercept loses the pre-compaction summary. Forge puts block summaries into the opaque compaction item; codex truncates history to [compaction_item, tail…]; bili strips the echo next request ("summary sourced from state"); but the kernel deactivates blocks whose messages vanish from the replay (#319's own test codifies this: tests/tail-window-reconcile.test.ts:131-157). Verified empirically against bundled acp-kernel: processTurn with truncated post-compaction input → state.blocks: [], summary NOT rendered. Net: everything that lived only in compressed blocks disappears from the model's view on the first post-forge turn. The e2e forge phase only recalls the turn immediately before the forge (survives via codex's retained tail) — untested gap. Endpoint form does NOT have this bug (forged {output} carries rendered summaries as replayable items, src/server.ts:1696-1703). Fix direction: on echo-strip, replace the echoed item with a rendered summary message (endpoint-form semantics) or re-anchor blocks.

Minors: 2) prepareResponsesCompact mutates state before the gate; on gate-fail forwards the unstripped original body upstream (server.ts:1690-1696). 3) Endpoint-form Prepared lacks stream/protocol → terminal observation always JSON parser (server.ts:2289). 4) Tail-window any-offset match can cross-merge distinct conversations with identical templated heads (prefix-affinity.ts:200-222, MIN_TAIL_MATCH=3, no min-content-size guard). 5) Clamp overrides operator's explicit compress.modelContextLimit — inverts the "operator-owned, never floored" invariant (server.ts:797-821); at least warn+document. 6) codexTurnIdentity "user" path bypasses stronger header precedence (session-id.ts:143-150). 7) Pending plugin register can be stolen by a subagent-thread session (server.ts:1003-1008, amplified by #317).

Nits: 8) forged SSE ignores parsed.stream. 9) array-UA first-entry semantics (no realistic regression — Node comma-joins duplicates). 10) duplicated trigger detection (isCompactionTrigger vs hasCompactionTrigger). 11) BILI_CODEX_COMPACT undocumented in CONFIGURATION.md. 12) forged response.completed reports input_tokens=lastInputTokens (possibly 0 → codex ledger believes empty context).

Top action: resolve #1 (+ e2e assertion recalling a value that was compressed pre-forge) before enabling BILI_CODEX_COMPACT=intercept beyond testing. Default remains pass, so shipping is safe with the kill-switch off.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · vllm-qwen/qwen3.8-27b

[bot] Independent verification of the delegated review complete — all on this exact tree (pr-336 @ 0074964). Pre-flight: npm run typecheck ✅, npm test 816/816 ✅, npm run build ✅.

Verdict per finding:

1. MAJOR — trigger-form summary loss: CONFIRMED, reproduced empirically.

  • Repro against bundled acp-kernel: compress a range with a distinctive summary → trigger turn (full history: block stays active, forge captures it) → post-forge turn with tail-only input (exactly what bili sends upstream after echo-strip) → active blocks = 0, summary not visible to the model. Same at N+3.
  • Root cause in kernel source: syncBlocks (acp-kernel dist/index.js:288) keeps a block alive only if one of its effectiveMessageIds is present or a message with id acp_summary_<blockId> is in the replay. Codex's truncated replay has neither → block deactivated, summary never rendered.
  • Endpoint-form asymmetry confirmed: coreToResponses emits rendered summaries as role:"developer" message items (wire codec), so the forged {output} carries them in codex's own history and they're re-injected via systemParts every turn. Trigger form has no such carrier.
  • E2E gap confirmed: the post-forge assertion (tests/e2e/e2e-codex.test.ts:282) only recalls 9600 — the sentinel planted in the forge-triggering turn itself (survives in codex's retained tail). Nothing recalls a value that was compressed pre-forge.

2. Minor (gate-fail forwards unstripped body): CONFIRMED. server.ts:1692-1696 — processTurn mutates session.state before the gate check; gate-fail (and the catch path) return base whose body is the original buffer, still carrying the echoed fc_bili_ item upstream.

3. Minor (endpoint Prepared lacks stream/protocol): FALSE POSITIVE on this tree. prepareResponsesCompact's base has protocol: "responses" and stream: parsed.stream === true (server.ts:1676-1677); observeResponsesTerminalState(stream, isStream) branches on it correctly (src/stream-terminal.ts:13-15). The JSON parser is used exactly when the client requested non-streaming.

4. Minor (tail-window cross-merge): CONFIRMED, reproduced. Two anonymous conversations sharing a 3-item templated head: the new conversation reattaches to the old one's session (via: "tail-window"). New surface from the any-offset change (pre-#319 matching was tail-pinned). Fix analysis: an offset-0 tail-window match is never a legitimate truncation reattach — a client retaining the full stored head + appends is caught by the step-1 full-prefix match; an offset-0 step-2 match means prefix/fork. Guard = start the scan at offset 1.

5. Minor (clamp overrides operator limit): CONFIRMED. codexAlignedWindow (src/codex-models.ts:79-88) clamps unconditionally; server.ts:817-823 applies it even when the operator explicitly set compress.modelContextLimit, inverting the "operator-owned, never floored" invariant documented at server.ts:797-803. Info log exists; nothing in CONFIGURATION.md.

6. Minor (turn-identity "user" path precedence): CONFIRMED (structural, narrow). session-id.ts:144-147 returns the session-id header directly, bypassing clientConversationHeader precedence. Only affects hybrid clients sending both x-codex-turn-metadata and a stronger header; pure codex is unaffected (session-id is what the legacy chain would return anyway).

7. Minor (pending register steal): CONFIRMED (structural, narrow). server.ts:995-1001 — first new session consumes the pending register; with #317's thread partitioning, a subagent's new session can consume a launcher-mode register intended for the (already-existing) root, and recordPluginSession rebinds the root's conversation id onto the subagent's session.

Nits: 8 ✅ (forge always SSE, ignores parsed.stream), 10 ✅ (isCompactionTrigger duplicates hasCompactionTrigger), 11 ✅ (BILI_CODEX_COMPACT absent from CONFIGURATION.md), 12 ✅ (input_tokens = lastInputTokens, can be 0 → server.ts:1548). 9 — agreed, no realistic regression (Node comma-joins duplicate UA headers).

Action — implementing now on this PR:

  1. fix: keep system prompt byte-stable for prefix cache #1 fix (server-side, no kernel change): at trigger-forge time (and at echo-strip time, covering sessions forged by an older build), capture the active blocks' summaries rendered in the kernel's exact format ([Compressed conversation section] — topic\n…) into persisted session metadata; inject them into the developer-message content on every subsequent Responses turn — endpoint-form semantics. (Kernel-side re-anchoring of detached blocks is the cleaner long-term fix but needs an acp-kernel release first per §5 — noted as follow-up.)
  2. E2E assertion: post-forge recall of a value that was compressed pre-forge (档案fix: post-merge review fixes + per-route context window + XDG config #6 sentinel — compressed in phase 3, proven recallable in phase 4, not in codex's retained tail). Fails on the current tree, passes with the fix.
  3. fix: address all code review findings (condense, routing, session-id, dead code) #2 fix: gate-fail/catch paths forward the stripped body.
  4. feat: OpenAI Responses API support (/v1/responses) #4 fix: tail-window scan starts at offset 1.
  5. Nit 11: document BILI_CODEX_COMPACT in CONFIGURATION.md.

#5/#6/#7 are design trade-offs of the family rather than defects in the combined tree — leaving them for your triage (happy to take any of them as follow-up issues). Will report back with the diff + full re-verification.

ework-agent added 3 commits August 29, 2026 14:27
The trigger-form forge put block summaries into the opaque compaction item, but the kernel deactivates blocks whose messages vanish from the truncated replay (syncBlocks keeps a block only while one of its effectiveMessageIds or its acp_summary_ message is present) — so everything that lived only in compressed blocks disappeared from the model's view on the first post-forge turn.

Fix: capture the active blocks' summaries in the kernel's render format at forge time and at echo-strip time (upgrade path for sessions forged by an older build) into session.metadata.codexForgedSummaries (persisted, exact-text dedup), and re-inject them into the developer message on every /responses turn.

Tests: unit coverage for renderForgedSummary/mergeForgedSummaries; mock-upstream integration test asserting the post-forge turn strips the echoed fc_bili_ item and re-injects the summary as a developer message; e2e forge phase now also recalls a sentinel that was compressed pre-forge (archive #6, not in codex's retained tail).
…g path; tail-window offset-0 guard

prepareResponsesCompact mutated state and then returned the original (unstripped) body on gate-fail/catch — the echoed fc_bili_ item reached upstream. Strip before the early return so pass-mode, gate-fail, and catch paths all forward a clean body.

Tail-window reattach now excludes offset 0: a head-to-head match is either a full-prefix case (step 1) or a distinct conversation sharing a templated head — never a truncation reattach (the retained suffix of a truncation starts strictly inside the stored chain). Closes the cross-merge of two anonymous conversations with identical templated heads.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · vllm-qwen/qwen3.8-27b

[bot] Top action resolved — pushed 3 commits to the PR head (0074964..ccd7036):

656f90d — MAJOR #1 fix: forged-summary handoff to post-forge turns

  • Root cause confirmed against bundled acp-kernel: syncBlocks keeps a block only while one of its effectiveMessageIds (or its acp_summary_<id> message) is present in the replay — codex's truncated post-forge replay has neither, so the block deactivates and the summary never renders.
  • Fix (server-side, no kernel change): capture the active blocks' summaries in the kernel's own render format ([Compressed conversation section] — topic\nsummary) at two points — trigger-forge time and echo-strip time (the latter covers sessions forged by an older build that never captured) — into session.metadata.codexForgedSummaries (persisted, exact-text dedup, append-only across successive forges). They are re-injected into the developer message on every /responses turn (both the prompt-injection branch and the systemParts-only branch).
  • Why not kernel re-anchoring: a synthetic acp_summary_<id> message can't be re-anchored via the Responses wire — responsesToCore re-derives message ids from content hashes (wire item id is not honored for messages), so kernel-side revival would need a kernel change (detached-block support) → new acp-kernel release first (AGENTS.md §5 cross-repo rule). The server-side capture is self-contained in this PR; kernel re-anchoring remains the cleaner long-term option (keeps decompress/search working on forged content) — worth a follow-up issue.
  • E2E assertion added (the one you asked for): the forge phase now also recalls 档案fix: post-merge review fixes + per-route context window + XDG config #6's sentinel (SENTINELS[5]) — compressed into a block in phase 3, proven recallable in phase 4, not in codex's retained tail after the forge. It can only pass via the developer-message handoff. Also added a mock-upstream integration test (tests/codex-compact-e2e.test.ts) driving the real proxy pipeline: post-forge turn asserts (a) the echoed fc_bili_ item is stripped before forwarding and (b) the setup summary is present in a developer message of the forwarded body.

7ed8dab — minors #2 + #4

  • fix: address all code review findings (condense, routing, session-id, dead code) #2: prepareResponsesCompact now strips the bili item before the early return, so pass-mode, gate-fail, and catch paths all forward a clean body (previously the original unstripped body went upstream; pass-mode /responses/compact had no strip at all).
  • feat: OpenAI Responses API support (/v1/responses) #4: tail-window scan starts at offset 1. Proof it's safe: a head-to-head (offset-0) match is either a full-prefix case (step 1 catches it) or a distinct conversation sharing a templated head — the retained suffix of a real truncation always starts strictly inside the stored chain. Regression test added; all existing tail-window tests still pass (their matches are at offset ≥ 2). Residual risk (shared templated middle run, offset > 0) remains but is far rarer than shared heads.

ccd7036 — nit 11: BILI_CODEX_COMPACT documented in CONFIGURATION.md + zh-CN (values, gate, forge forms, summary re-injection, pass-through fallback).

Verification on the pushed tree: npm run typecheck ✅ · npm test 820/820 ✅ (was 816, +4 new) · npm run build ✅. The real codex+sglang forge run isn't possible in this environment (no codex binary / local upstream) — please run ACP_TEST_E2E=1 E2E_FORGE=1 node --import tsx --test tests/e2e/e2e-codex.test.ts once; the new 档案#6 assertion is in that run.

Left for your triage (confirmed earlier, not fixed here): #5 clamp overriding an operator-tuned compress.modelContextLimit (inverts the "operator-owned, never floored" invariant — at minimum warn+document), #6 codexTurnIdentity "user" path bypassing stronger header precedence (hybrid clients only), #7 pending plugin register stealable by a subagent-thread session (launcher+resume only), nits 8 (forge ignores parsed.stream), 10 (duplicated trigger detection), 12 (forged input_tokens can be 0). #3 was a false positive (endpoint Prepared does carry protocol/stream at src/server.ts:1700-1701).

ework's pass (656f90d..ccd7036) and my pass (d4fe1ba) fixed the same
findings concurrently. This reconciles them, best mechanism per finding:

- MAJOR (summary loss after trigger-form forge): hybrid. The echoed
  fc_bili_ item is REPLACED by a summary-carrying user message
  (history-borne: kernel-compressible, kept by codex's user-message
  retention) — and ework's forge-time capture into
  session.metadata.codexForgedSummaries stays as the fallback: when the
  echo does NOT come back, the captured summaries are re-injected into
  the developer message. Exactly one path is active per turn (no
  duplication), and neither an echoed-item loss nor unbounded permanent
  injection can drop or bloat the handoff.
- tail-window cross-merge: keep ework's offset-0 guard (a head-to-head
  match is never a truncation reattach) over the byte-size heuristic.
- endpoint compact: strip-on-all-paths (ework) + all-or-nothing state
  commit with restore on gate-fail/rebuild-failure/error (mine).
- codexTurnIdentity: validated 'user' turns fall through to the legacy
  precedence chain (stronger headers may own the id).
- pending plugin register can no longer be claimed by a subagent thread.
- codex window clamp exempts an operator's explicit
  compress.modelContextLimit (operator tuning is never floored/clamped).
- trigger-form forge honors parsed.stream (JSON when not streaming) and
  mints usage from max(lastInputTokens, payload estimate, 1).
- isCompactionTrigger reuses hasCompactionTrigger.

823/823 unit tests; full e2e incl. forge + pre-forge deep recall pass
against local sglang.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Review findings 全部修复完毕(两次并行修复已协调为一次混合方案)

发现 ework 与我同时对审查发现做了修复并推到同一分支。1c6a72c 把两套方案按机制择优调和:

发现 定案
1 MAJOR 压缩前摘要丢失 混合:回显的 fc_bili_ 项原地替换为携带摘要的 user 消息(历史承载:可被 kernel 再压缩、codex 的 user 保留规则自带存活)+ ework 的 forge 时捕获(session.metadata.codexForgedSummaries)作兜底——回显缺席(codex 丢弃/重启)时才走 dev-message 注入。每轮恰好一条路径活跃,无重复、无无界增长
4 尾窗跨并 ework 的 offset-0 守卫(头对头匹配永远不是截断重挂)取代我的字节阈值
2 endpoint gate 失败路径 strip-全路径(ework)+ 状态快照/恢复(gate 失败/重建失败/异常都还原 pre-turn state)
5 钳制压过运营者 显式 compress.modelContextLimit 豁免(operator-owned, never clamped)
6 user 路径绕过头优先级 校验过的 user 轮落回 legacy 优先级链(强头可拥有 id)
7 子代理偷注册 pending register 只允许根线程会话认领
8 stream=false 伪造 JSON 响应体
10 重复检测 isCompactionTrigger 复用 hasCompactionTrigger
11 未文档化 BILI_CODEX_COMPACT 已入 CONFIGURATION(中英)
12 usage=0 max(lastInputTokens, payload 估算, 1)
3 stream/protocol 缺失 误报——base 本就带 protocol+stream,无需改
9 数组 UA 首元素 已由测试固化,不改

验证:typecheck ✓ · 单测 823/823 ✓ · build ✓ · e2e 全套含 forge + 压缩前深度回忆(档案#6 post-forge 可召回)pass 1 fail 0(本地 sglang,~7min)。

新 e2e 单测覆盖:echo 在场→handoff user 消息且 dev 注入被抑制;echo 缺席→dev 兜底注入生效。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · vllm-qwen/qwen3.8-27b

[bot] 收到 — 独立复核了 1c6a72c 混合树,确认协调正确,可以合并。

独立验证(本环境,pr-336 @ 1c6a72c):npm run typecheck ✅ · npm test 823/823 ✅(与你的数字一致)· npm run build ✅。真实 codex+sglang e2e 本环境跑不了(无 codex 二进制/本地上游),以你的 pass 1 fail 0 为准。

代码层面确认的几个协调点(不止跑测试,逐条看了机制):

  1. 单路径不变量成立:echoReplaced 按本轮实际 input 计算,dev 注入被 echoReplaced ? [] : … 门控 — 回显在场走 history-borne 替换消息、缺席走 dev 兜底,每轮恰好一条,无重复。
  2. fix: post-merge review fixes + per-route context window + XDG config #6 × feat: bili CLI + debug in config + README rewrite #7 正确组合:codexTurnIdentity 对 "user" 轮返回 undefined 后,feat: bili CLI + debug in config + README rewrite #7 的 codexTurnIdentity(req.headers) === undefined 守卫恰好让根线程(user 轮 → undefined)仍可认领 pending register,而 subagent 线程(→ 有值)被挡 — 两个修复互为前提,单独看任一个都会误伤根线程。
  3. 与 stripKernelSummaries 无三重计数:它只在 compress tool-call 仍在场时才剥 kernel 渲染的 summary;post-forge 两者都已不在 replay 中,所以替换消息/dev 注入是唯一载体。锚点幸存的 block 的有界重复(blob + kernel 渲染)已在 codex-compact.ts 注释里明示接受。
  4. 状态快照/恢复覆盖 gate-fail、typeof output === "string"、catch 三条非 forge 路径 ✓;hasCompactionTrigger 复用对 string input 安全(非数组返回 false)✓;defaultCountTokens 在 pinned acp-kernel 中存在(typecheck 通过)✓。

两个已知残留边界(都不值得现在修,记录在案):

  • 旧构建 forge 的会话 + codex 丢弃回显 → 无载体(metadata 未捕获且无 blob 可提取)。双重故障才触发,概率极低。
  • buildTriggerForgeBody 的 stream=false JSON 形态只有单测覆盖 — codex 的 compaction trigger 实际是否发过非流式请求未见实锤,e2e 走的是 SSE 路径。

关于撞车:你贴出 top action 后我直接开工推了修复,没有先确认你是否已动手 — 下次我先在 issue 里认领再动分支。混合方案比任何单方案都好(history-borne 可被 kernel 再压缩,dev 兜底覆盖回显缺席),#249 家族可以合了。合并后记得关 #317/#319/#322/#323/#324/#325。

codex 0.147 ships MCP tools to the model as a namespace tool type;
self-hosted servers (sglang/vllm/ollama/llama.cpp) do not parse it, so
the injected bili MCP tools become silently invisible and the model
fumbles for them. Users had no way to discover BILI_LAUNCHER_PLUGIN=0.

launcherInjectMcp now falls back to wire-injected flat tools when the
codex upstream host is loopback/RFC1918/ULA/link-local/.local and
BILI_LAUNCHER_PLUGIN is unset; BILI_LAUNCHER_PLUGIN=1 forces plugin
mode. claude is unaffected (it flattens MCP tools itself).
@ranxianglei
ranxianglei merged commit d02e2bd into master Aug 29, 2026
6 checks passed
@ranxianglei ranxianglei mentioned this pull request Aug 29, 2026
@ranxianglei
ranxianglei deleted the 2026-08-29_codex-compact-family branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant