Review of the main removal commit left dead code behind: ImageFormat/
ImageBillingMode type aliases and the CompressionStats imagesShrunk/
imageBytesSaved/imageTokensSaved fields (seeded by createInitialState,
asserted in the kernel persist test) had zero remaining readers after
src/image-compress.ts went away. Removed them and reworded three
comments that still described the image_full restore channel as live.
The opt-in compress.imageCompression pass and its image_full restore
channel are structurally broken where they matter most:
- hosts that reject bili-injected tools (codex) can never deliver the
restore call — the downscale is permanent for them (#3270 disarmed
the lane, which proved the tool was dead weight there);
- where the tool IS injectable, the model has no reliable way to learn
the ref of the downscaled message (no ref annotations on the wire),
producing the 38-round guess-reject-resend loop from #3266 (cache
hit 75% -> 28%).
Remove the whole feature from host and kernel: arrival-time downscale
pass, image_full injection + sticky restore + fail-streak guardrail,
image stats, persistence keys, wire-contract tool variants, config
schema, docs, and the sharp optional dependency. Every image now passes
through byte-identical at original resolution.
Sessions persisted by older versions load unchanged; legacy
imageShrinks/imageFullRestored state keys and imageShrunk* stats are
ignored on load (storage corpus pins that as a fixture).
kernel 0.0.126.
Pair by order, not id-set membership: a result needs a same-id call EARLIER
in the view (forward pass), a call needs a same-id result LATER (backward
pass). An id-set cannot tell two instances apart when a host re-issues the
same tool-call id for different calls (Agent Teams name:index ids), so a
half-pair whose own partner was folded away used to survive because a
different same-id partner was still visible - shipping an unpaired role:"tool"
message (upstream 400 "tool_call_id ... is not found") or an unanswered
tool_call ("... did not have response messages") and bricking the session.
Unique-id sessions behave identically to the old set lookup; one call still
answers any number of same-id results (precedence, not multiplicity); compress
calls stay exempt.
Fixes#3046
Eligibility and execution used two different definitions of "can this
range fold": recommend screened turn-integrity over the GLOBAL
compressible set while apply judged each SUBMITTED range alone, on a
different array class, and widened boundaries within a capped window.
A turn whose partners sat in other advertised units passed global
screening yet made every submission throw "Range would split N
turn(s)" — a permanent advertise/reject loop (billion-context#3236).
- unit-projection.ts: projectUnit extracts applySingleRange's pre-block
sequence verbatim (boundary widening -> carrier/coverage/media/
protected-tool carve -> protected-zone carve -> turn-integrity
withdrawal -> emptiness); returns the projection or the ready-to-throw
fatal error (zone/split). collectCoverage moves here.
- applySingleRange delegates to projectUnit; errors/warnings stay
byte-identical (existing suite passes untouched).
- recommendNode re-screens every FINAL merged unit through projectUnit
and demotes fatal units to gaps (no re-merge after filtering).
- NodeEffects.applyView: judgment now runs on the EXACT array class
applyCompression executes on; absent it, falls back to the pre-prune
original (#2663) or the given view.
- report.ts: buildStatusReport accepts config + originalMessages; the
uncompressed view appends an additive warning flag to rows whose
projection is fatal (flagged, never dropped); legacy output unchanged.
- kernel/tests/issue3236-recommend-apply-consistency.test.ts: both
divergence geometries (delayed results unreachable / reachable,
double-burst interleave), healthy-turn non-over-screening, gate
intactness on manual submit, and the acp_status flag surface.
kernel 0.0.124 -> 0.0.125
#3222 mandatory fix 2. stripOrphanedToolCalls hardcoded toolName === "compress", so a pending mcp__bili__compress call (no result yet) was deleted as an orphan under active coverage while its bare-name twin survived. prune() now takes an optional isCompressTool predicate (same family as Config.isCompressTool / hideConsumedCompressCalls); unset stays bare-name only, byte-identical to before. pruneNode passes ctx.config.isCompressTool through; renderHandoff keeps the default (no config on that path). Bumps acp-kernel to 0.0.125.
Vertex rejects a request whose user content carries plain (unsigned,
non-thought) text AFTER a functionResponse part with 400 'Requests
ending with a model turn are not supported' (controlled A/B matrix in
#3159; Gemini Developer API accepts both orders). coreToGoogle's
flushUser reassembled every user run as [responses..., content...],
so even a client sending the safe [text, functionResponse] order was
forwarded defective. Add normalizeGoogleUserPartOrder (stable
partition; signed/thought/non-text parts never move; byte-stable no-op
when no plain text follows a functionResponse) and apply it in
flushUser. Bump acp-kernel to 0.0.124.
Review fix for the original PR's fsyncFile: it re-opened the written file
with flag "r" before fsyncing. On POSIX that works (fsync is inode-level),
but on Windows the flush goes through the handle (FlushFileBuffers) and a
read-only handle fails with EPERM — breaking every async state write
(writeNow/scheduleSave) on that platform. Caught by the static-gates lane's
Windows kernel run: 23 persist.test.ts failures, all
'EPERM: operation not permitted, fsync' at StateStore.fsyncFile, while the
sync path (fd opened "w") stayed green.
Open with "r+" (write access, no truncate) so the flush succeeds on both
platforms. Rides the 0.0.124 marker — not yet released.
Review fix on the #3157 PR branch: the new durable-write sites used a single
fs.writeSync(fd, data) whose return value was unchecked. writeSync may return
fewer bytes than requested (short write), which would publish a silently
truncated state file — the same corruption class this PR fixes. The repo's
own idiom (external-summary-credentials.ts set(), web/api.ts atomicWriteConfig,
instance.ts atomicWriteJson) writes through writeFileSync(fd), which loops to
a full write before the fsync. Switch all eight new sites to it; this also
removes the string/Buffer narrowing branches writeFileSync makes unnecessary.
Review fix on the #3157 PR branch (stale-base semantic collision, no textual
conflict): this PR branched when master's kernel was 0.0.122 and bumped to
0.0.123, but master independently consumed 0.0.123 (#2970 foreign-name
compress). Per the repo convention recorded in 9656fc0a1 ("bump past
master's number so each changeset keeps its own marker"), the fsync
changeset gets its own marker: 0.0.124.
Also syncs root package-lock.json packages[kernel], which the original
bump left stale at 0.0.122 (same convention: kernel/package.json + root
lockfile packages[kernel] move together; kernel/package-lock.json stays
as-is).
tmp+rename guarantees rename atomicity but NOT content durability: the bytes sit in the page cache until the OS flushes them, so a power loss / kernel panic between write and rename leaves a size-correct, VDL=0 all-zero file on disk (NTFS journals metadata, not user data). That is exactly the Windows BugCheck 0x1A corruption reported in #3157.
Add atomicWriteDurable (open/write/fsync/close) used by flushSync's canonical + spill writes, and fsyncFile (re-open + fsync, valid because fsync is inode-level) called after writeInner's async writeFile and before its fence-check+rename commit block. Bump acp-kernel to 0.0.123 per the Kernel Boundary version rule.
A user message whose content has >=2 input_text parts (the typical
image+text layout: text | image | text) was rebuilt by patchTextParts
into [input_text(merged), input_image, input_text("")] -- the
consolidated-away text slots were left as EMPTY placeholders instead of
being dropped. Strict Responses backends reject an empty input_text.text
with 400 "text is required" (param points at the empty slot), failing the
whole request.
Consolidate all text into the first text part and DROP the remaining text
slots rather than blanking them to "". The zero- and single-text-part
paths are byte-for-byte unchanged.
Bumps acp-kernel 0.0.122 -> 0.0.123; also syncs the kernel lockfile root
version, which was stale at 0.0.121 on master. Adds a regression test
pinning that the multi-text-part + image rebuild emits no empty
input_text part.
Fixes#3089
Catch-up merge of origin/master (c800ed1) into the #2977 branch to clear the
merge_conflict. Conflicts were only in src/server/handle.ts and
tests/conflict-remediation.test.ts — neither is touched by this PR (#2970),
so both take master's side.
Kernel version collision: master independently consumed acp-kernel 0.0.122
(#3058 preserveRecentMessages 5->3); this branch had also bumped 0.0.121 ->
0.0.122 for #2970. Per the repo convention ("master took N via another PR"),
bump past master's number to 0.0.123 so each changeset keeps its own marker.
Updated kernel/package.json + root lockfile packages[kernel]; left
kernel/package-lock.json as-is (repo convention: not kept in sync).
PR core files (src/config.ts, src/loop/core.ts, kernel hide-consumed/types/
compress + their tests) are byte-identical to the pre-merge head — verified.
computeProtectedRefs can protect a recent tool-call while excluding its paired tool-result (whose name matches neverPreserveRecentTools) from the zone, since that list drops big-result tools from the visible set. The advisory carve then keeps the call visible and folds the result, stranding an orphan function_call that strict Responses validators reject with HTTP 400 invalid_request_error. Make the recent zone symmetric per pair: if either half of a (tool-call, tool-result) matched by toolCallId is protected, protect both. Monotonic - only adds refs.
hideConsumedCompressCalls matched only the bare "compress" name and resolved
carrier identity by raw toolCallId equality. MCP/plugin-mode folds expose
compression as mcp__bili__compress and mint a synthetic block id
(plugin_<ts>) that never equals the re-sent host call id, so those calls
bypassed inactive cleanup + live-range arg reduction entirely (#2970).
Add an optional host-injected isCompressTool predicate (default = bare name
only, byte-identical when unset) and resolve carrier identity by quoted range
when the direct id misses — scoped to non-bare-name calls so the proxy /
in-process path is untouched. Bump kernel 0.0.121 -> 0.0.122.
A degenerate head fold (81-100% coverage) rewrote the whole prefix, but the
claim window only consumed the FIRST sample after it - the proxy re-request.
The client's echo re-bill ~25-66s later carried no foldSeq, fell into the
unattributed ttlRepay residual, and tripped cache-seam with "no fold
attribution". Every one of #2929's seven seams was exactly this shape.
Mirror the #1847 switch discipline for folds:
- kernel buildCacheReport: a fold claims its first sample unconditionally,
then COLD continuations (hit < FOLD_CLAIM_WARM_HIT_PCT=85) up to
FOLD_CLAIM_COLD_ROUNDS=4; a warm line retires every open window.
- cache-ledger recordCacheSample: same state machine on the sparse
LedgerFold.claims/retired fields (legacy persisted ledgers keep the
first-claim behavior).
- web trajectory chart: cause heuristic mirrors the window (foldSeq-first,
fold-between-times fallback for pre-#2929 ledgers).
- i18n: the residual bucket is honestly "unattributed" (upstream
TTL/eviction/unknown), not "TTL expiry"; seam tip mentions post-fold
echo re-bills.
kernel 0.0.119 -> 0.0.120.
Review finding on the head-stability fix: knownSummaryIds was built from
state.blocks unconditionally, so with injectSummaries:false — a path with no
fresh render at all — rebuildMessages would DROP already-rendered summary
copies instead of keeping them, silently inverting that opt-out's semantics
(pre-change: copies stayed). No caller uses injectSummaries:false today
(kernel handoff/compress, host persist/plugin all use the default), but the
opt-out is part of the prune() contract, so the drop set is now scoped to
inject=true and a state-prune.test.ts case pins the retention behavior.
The #2733 clamp landed as unconditional, which broke two kernel tests:
renderHandoff re-derives the model view through prune(), and handoff docs
WANT the summary of older absent material at the head (no provider prefix
cache at stake) — 're-pruning the same snapshot without folded resurrects
the summary at index 0'. PruneOptions now carries headSummaryAnchors
(default false = the pin-safe request path: tail parking + the
after-pin clamp); renderHandoff passes true. The promote-after-prune
regression's placement assertion moves to the new invariant (summary
after the pinned first user message) — its actual subject, consumption
of a pin-covering block via the surviving raw, is unchanged.
kernel suite 1271/1271; repo handoff/kernel/loop/responses/compress/
fold/anthropic/prune/absorb suites green; tsc + unused-exports clean.
The kernel-guard version discipline compares against current master:
master's #2695 bumped kernel to 0.0.116, making this branch's earlier
0.0.116 bump invisible in the PR diff. Bump past it so the panel.ts
storage-mode change (kernel-change: declared in the PR body) carries a
visible version delta.
Production logs (issue #2733, codex/gpt-6-astra wire mode) show the request
after a fold matching only the ~11K immutable instructions+tools head while
the kernel expected the pre-foldPoint prefix (anchor) to stay cached:
shrink 11% foldPoint=m01360 ... anchor≈34427 tok
→ next request cached=11125 (3%) instead of ≥ anchor
Root cause: when a summary block's anchor ids resolve to index 0 — a range
rooted at the pinned first user message (session 01a1210e: foldPoint=m00001),
or a chain re-fold whose effective ids are all pruned — rebuildMessages
splices the summary AHEAD of the pinned first user message. The pinned
message is the provider prefix-cache head; rewriting that slot collapses
the cached prefix on every fold, and the next request re-warms from the
constant head only. That double prefix-cache penalty per fold is 56% of all
uncached tokens in the #2733 log.
Fix (kernel/src/prune.ts), four parts:
- collectSummaryAnchors now prefers block.directMessageIds over effective
(merged) ids and falls back to messages.length (tail) instead of 0, so a
block whose ids were all consumed parks its summary after the surviving
material, never at the head.
- rebuildMessages drops rendered summary copies of ANY known block
(knownSummaryIds from state.blocks, including consumed ones) so stale
copies of merged blocks cannot leak into loop rebuild views.
- after resolving anchors, insertAt is clamped to >= firstUserIndex + 1:
a summary may never precede the pinned first user message.
tests/responses-refold-head-stability.test.ts pins the invariant across a
fold + two chain re-folds rooted at the pin: every summary-carrying view
must keep input[1] byte-identical to the pinned m00001 message. Red on the
old kernel (view 12 head = CHAIN2 summary), green with the fix.
kernel-guard Rule 2: kernel/src/panel/panel.ts gained the host-rendered
storage-mode label (display-only); version bumped so the change can ship
as an independent acp-kernel release.
The four dsh durable-state text carriers (#2419 skill catalog, #2446 mcp
catalog, #2447 workspace-instructions baseline, #2481 runtime-context
snapshot) stop being host-hardcoded boolean guards. A lane-scoped host
classifier now projects each carrier to a canonical durable/<name>
identity via the new kernel Config.messagePathOf hook, and the EXISTING
protectedTools / protectedLatestTools pattern machinery governs them —
same knobs, same semantics as the tool channel (#1947).
kernel (0.0.116):
- Config.messagePathOf: host-projected virtual tool path (pure, cheap,
never re-projects tool-call/tool-result)
- protected.ts: virtualToolPathOf; isMessageProtected + collectLatestProtected
+ isMessageLatestProtected accept virtual paths (protectedTools patterns
and per-path latest semantics both apply to projected carriers)
host:
- durable-message-guards.ts rewritten: DurableMessageClassifier per
carrier (same matching predicates, evidence comments preserved),
durableMessageToolPaths registry (KDD #9 dsh-only allowlist unchanged),
withDurableProtection() — default injects durable/* all-instance
protection (byte-equivalent to the old boolean guards); ANY durable
pattern in protectedTools/protectedLatestTools = whole-identity
takeover (user policy wins verbatim, only the classifier is attached)
- handle.ts / session.ts wiring + config.ts JSDoc for both knobs
tests: kernel protected-virtual-paths 6 (projection domain, pattern
matrix, per-path latest, tool-channel parity); host durable-tool-identity
8 (policy units + e2e: default all-instance, durable/* latest takeover,
exact-identity takeover, lane scoping); the four #24xx suites migrated
to the Path API with e2e assertions unchanged (behavioral parity).
kernel-change: yes — kernel/package.json 0.0.115 -> 0.0.116; new optional
Config field messagePathOf plus virtual-path support in protected.ts.
Backwards compatible: without messagePathOf the kernel behaves exactly
as before (all suites unchanged).
'/acp' couldn't tell you which storage mode the lane actually took —
the only signal was grepping the lane log for '[storage] unified FULL
mode ENABLED'. The plugin status panel and the acp_status tool output
now carry a one-line label:
storage: legacy (json only)
storage: shadow (dual-write dry-run -> index.db)
storage: full (unified-first reads, dual-write)
storage: full requested — blocked by BILI_ENCRYPTION_KEY, running legacy-only
storageStatusLabel() in persist.ts mirrors the constructor's mode
resolution, so the panel can never claim a mode the store refused to
take (the encryption downgrade is rendered explicitly). The kernel
panel input is a pre-rendered string — the kernel never guesses.
The range selector (buildCompressibleRanges) advertised spans the apply side
structurally rejects: live checkpoint carriers (#335) survive pruning but are
carved out at apply time, so a span bridging carriers over covered raws
resolved to zero foldable messages and threw every turn (#2638). The two
screens also judged two different array classes for integrity withdrawal.
- state.ts: shared isLiveCheckpointCarrier predicate — single source of truth
for selector and apply side
- recommend.ts: live carriers screen as gaps so no advertised group bridges
across them; new optional integritySource param lets the withdrawal screening
run on the same array class the apply gate judges (default: passed array)
- pipeline.ts/compress.ts: prune node stashes the pre-prune resent array in
effects.originalMessages; recommend feeds it as the withdrawal source
- report.ts: acp_status UNCOMPRESSED rows open a gap at live carriers so no
reported range bridges across them
- tests: carrier-advertise-validate.test.ts — #2638 production geometry
end-to-end, carrier boundary (live/stale), withdrawal array-class contract,
status-row consistency, plus both directions of the #2607 media split
(archivable folds like text, unrecoverable stays pinned)
Rebased after #2607 landed on master: the originally drafted blanket media
carve was dropped — filterProtectedToolMessages already enforces the #1188
never-fold exemption for unrecoverable payloads, and a blanket carve would
have re-pinned archivable media against #2607's fold-like-text direction.
Media handling itself is untouched by this PR.
kernel-change: advertise/validate disagreement lives inside the kernel
(recommend.ts vs compress.ts); host side cannot express carrier-aware screening
or the pruned-vs-original view split. Closes#2663
remintCoveredLiveIds now also dodges INACTIVE blocks' covered ids when the
same cluster root shows prior-pass continuity — the exact shape a new
duplicate instance lands on a dead block's number and resurrects it in
sync, rendering a carrier for content the instance was never part of (the
every-other-turn carrier flap). A whole-root arrival that is new to
lastPassIds (client rewind to a checkpoint still holding the folded
originals) keeps the converter's ids so the block legitimately resurrects.
kernel: 0.0.114 -> 0.0.115
Default archivable-media folding (#2640) made the opt-in wire-side image
strip redundant, and the strip itself broke the prompt cache every turn on
three of four wires (sliding cutoff moves the byte boundary per turn; only
anthropic had the fold-anchored boundary). Media handling now has exactly
one path: fold + archive + decompress({ imageRef }) recovery.
- kernel: strip-images.ts (stripHistoricalImages) retired; wire barrel and
wire-google tests updated; acp-kernel 0.0.113 -> 0.0.114
(kernel-change: removing a public wire export that exists only for the
removed host policy; no compression behavior changes)
- host: strip wiring, fold-anchored cutoff, and DEFAULT_STRIP_IMAGES_KEEP_RECENT
removed from handle.ts/server.ts/compress-settings.ts; image-restore.ts keeps
the always-on index + spill + decompress machinery (that is the default-fold
recovery path, not the strip's)
- config: compress.stripImages / compress.stripImagesKeepRecent dropped from
the type, whitelist, and parser; old configs get a one-time INERT warning
(warnInertStripImages) instead of silent no-op
- docs: seeds + generated tables regenerated; EN/ZH prose sections replaced
with removal notes; decompress error texts no longer reference the flag
- tests: strip-images / strip-images-compact / strip-log-observability /
strip-cutoff-anchor suites deleted; compress-settings cascade/parse cases
removed; new strip-images-removal.test.ts pins the INERT notice + silence
Closes#2608 (archival-failure-still-strips existed only on the strip path;
with the strip gone there is nothing to fail)