Skip to content

fix: re-attach the original openai wire system on rebuild (kernel system hoist) - #129

Open
ranxianglei wants to merge 2 commits into
masterfrom
2026-08-22_openai-system-hoist
Open

fix: re-attach the original openai wire system on rebuild (kernel system hoist)#129
ranxianglei wants to merge 2 commits into
masterfrom
2026-08-22_openai-system-hoist

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Symptom

Restart on provider-mode openai wire (glm-5.3 etc.): pre-restart panel shows blocks; post-restart panel shows Blocks: none, Sent-to-LLM balloons 146k → 546k, all ranges reappear uncompressed. Blocks only re-materialize at the first provider request. Additionally: after any compression covering the first span, rebuilt payloads lose the system prompt entirely (live wire systemLen 45151 → 0).

Root cause

The openai wire's leading system message sat INSIDE the fold id space (it took m00001). System content is host runtime state — live 45k chars vs ~7.4k reconstruction across restarts — so:

  1. every span fingerprint derived from a restart's reconstruction mismatched → the guard rejected every in-stream replay → "Blocks: none" until the first wire fold;
  2. a compression covering m00001..m000xx ate the system piece → rebuilt payloads carried no system at all.

anthropic (top-level system) and responses (instructions) never had this — openai was the odd codec folding system into the id space.

Fix (with acp-kernel 0.0.37)

Kernel PR ranxianglei/acp-kernel#120 hoists the contiguous leading system/developer prefix out of the openai fold space; openaiToCore now returns { msgs, systemText }. This PR:

  • payloadToCore carries systemText from the kernel hoist
  • NEW restoreOpenaiSystemPrefix(originalMessages, rebuilt): re-attaches the ORIGINAL contiguous leading system/developer messages from the wire verbatim (roles / count / name fields byte-for-byte), mirroring the anthropic top-level system path — never the reconstruction
  • rebuild wiring in src/index.ts composes fidelity-restore + system-restore

Tests

  • updated 2 old-contract tests (wire-transform, wire-fidelity range off-by-one)
  • NEW e2e restart regression: live wire system carries runtime injections the restart cannot reproduce (glm-5.3-like); asserts the block survives post-restart pre-LLM AND the original injected system rides every rebuilt payload
  • 261 pass / 0 fail, tsc clean, acp-kernel 0.0.37 from npm

…tem hoist)

The kernel (0.0.37) hoists the leading system/developer prefix out of the
openai fold space: system content is host runtime state (45k live vs ~7k
reconstruction across restarts), so keeping it inside the id space made
every span fingerprint unstable AND let a compression covering the system
piece delete the model's system prompt from every rebuilt payload
(glm-5.3 wire: systemLen 45151 -> 0 after the first compression).

- payloadToCore now carries systemText from the kernel hoist
- restoreOpenaiSystemPrefix re-attaches the ORIGINAL contiguous leading
  system/developer messages verbatim on rebuild (roles/count/name fields
  preserved), mirroring the anthropic top-level system path
- restart regression: live wire system with runtime injections the
  restart cannot reproduce - block survives pre-LLM and the original
  system rides every rebuilt payload
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