Skip to content

refactor: delegate primeFold mirrors to acp-kernel mirror constructors (0.0.35) - #126

Merged
ranxianglei merged 1 commit into
masterfrom
2026-08-22_kernel-mirror-cutover
Aug 22, 2026
Merged

refactor: delegate primeFold mirrors to acp-kernel mirror constructors (0.0.35)#126
ranxianglei merged 1 commit into
masterfrom
2026-08-22_kernel-mirror-cutover

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

  • src/wire-fold.ts drops the three hand-rolled primeFold wire mirrors (viewToCoreStream / viewToAnthropicCore / viewToResponsesCore bodies, ~150 lines) and delegates to the acp-kernel mirror constructors added in acp-kernel PR chore(deps): bump acp-kernel 0.0.31 -> 0.0.32 #114 (v0.0.35): mirrorOpenaiToCore / mirrorAnthropicToCore / mirrorResponsesToCore.
  • omp now keeps only the persisted-shape mapping (toMirrorView: ref-tag stripping + pi block types → MirrorMessage); every wire rule — system placement, reasoning_content vs thinking blocks vs summary_text, tool_result folding, whitespace handling — is single-sourced in the kernel, shared with the billion-context proxy (one place to fix, issue provider模式重启acp status 压缩块丢失 #64 class).
  • acp-kernel 0.0.34 → 0.0.35.

Behavior parity

Byte-level parity asserted by the existing suites, all unchanged and green (260/260 bun test, tsc + tsconfig.test.json clean):

  • openai: whitespace-only text blocks kept, reasoning_content join("\n"), tool_calls always pushed when present
  • anthropic: no system piece, signed thinking blocks, whitespace-only text dropped, tool_result folded into user
  • responses: system in instructions, input items in block order, whitespace-only text dropped
  • e2e restart regressions (prime-provider-restart.test.ts, 8 tests incl. inline-<think> demoted host) pass through the kernel constructors unchanged

…s (0.0.35)

wire-fold.ts drops ~150 lines of hand-rolled wire-shape mirrors
(viewToCoreStream/viewToAnthropicCore/viewToResponsesCore bodies) in
favour of the kernel's mirror*ToCore constructors (acp-kernel PR #114,
v0.0.35). omp keeps only the AgentMessage→MirrorMessage mapping
(ref-tag stripping + pi block types); every wire rule — system
placement, reasoning_content vs thinking blocks vs summary_text,
tool_result folding, whitespace handling — is single-sourced in the
kernel, shared with the billion-context proxy.
@ranxianglei
ranxianglei force-pushed the 2026-08-22_kernel-mirror-cutover branch from 30bbd98 to 0c04e84 Compare August 22, 2026 09:53
@ranxianglei
ranxianglei merged commit 13e7d85 into master Aug 22, 2026
5 checks passed
ranxianglei added a commit that referenced this pull request Aug 22, 2026
Checkpoint the provider-mode FoldSlot to disk via acp-kernel/persist
(StateStore) and restore it at session_start, before the primeFold
mirror runs.

Why: at restart the wire payload is unavailable until the first provider
request, so primeFold folds a session-VIEW mirror — a different
fingerprint space than the live wire fold (host transformMessages +
convertMessages reshape the view). Every in-stream compress replay then
failed the span guard and /acp showed "Blocks: none" until the first
provider request refolded the real wire (issue #130).

The restored identities live in the WIRE's own content-hash space
(coreIdentity is a pure function of content), so the first live fold
re-validates the restored slot via LCP; a stale checkpoint degrades to
the normal re-fold, never worse. Zero-block checkpoints are neither
persisted nor restored — they carry nothing the fresh slot lacks but
would suppress the mirror fallback (issue #103 regression found in
tests). Crash without shutdown also degrades to the mirror.

- new src/fold-persist.ts: policy layer over acp-kernel/persist
  (dir/env/config, schema v1, snapshot validation, restore w/ forward-
  compat merge); default dir ~/.omp/acp-omp-folds, env ACP_OMP_FOLD_DIR
- runtime: restoreFold/scheduleFoldSnapshot/flushFoldSync; snapshot at
  live fold + turn commit + compress commit; flushSync at
  session_shutdown before forgetSession
- config: foldPersistence {enabled, dir} (boolean shorthand, default on)
- scripts/test.ts isolates ACP_OMP_FOLD_DIR per run (restored snapshots
  from earlier runs marked replayed calls as already-applied)
- tests/fold-persist.test.ts: restart e2e pre-LLM, crash fallback,
  zero-block guard, corrupt skip, disabled, switch-back no-clobber,
  incremental LCP on extended history

Requires acp-kernel 0.0.40 (persist subpath, kernel PR #126).
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