fix: hoist leading system/developer prefix out of the openai fold space - #120
Merged
Conversation
…ld space
The openai codec was the last one folding the system prompt into the
message id space (anthropic keeps it in the top-level system field,
responses collects it as instructions). Two failure modes:
1. A compress range covering pos 0 removed the model's system prompt
from the rebuilt wire entirely (observed: glm-5.3 wire systemLen
45151 -> 0 after the first compression).
2. Restart replay: prime-fold reconstructs system content from host
state (runtime injections differ across restarts), shifting every
span fingerprint covering pos 0, so the guard rejected the replay
and blocks showed as none until the first live request.
openaiToCore now returns { msgs, systemText } with the contiguous
leading system/developer prefix hoisted out; mid-conversation system
traffic stays in the fold space unchanged. mirrorOpenaiToCore needs no
change: the mirror system message folds through the same hoist, so
mirror and live spaces converge regardless of systemText.
This was referenced Aug 22, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: hoist leading system/developer prefix out of the openai fold space
Symptom (restart regression, omp @ glm-5.3)
/home/dog/.omp/acp-omp.logon restart:prime-fold … blocks=0+fold-replay rejected reason=fp m00001..m00264 want 1d8b6f39 got 432bb7b2 @0..264— positions resolve, fingerprint mismatches; 20 s later the first live request replays the same calls successfully (event=replayed).Root cause
The openai codec was the only one folding the system prompt into the message-id space:
systemfield (out of fold space, issue #64)instructions+systemParts, never inmsgsmessages[0]→ fold piece at pos 0 (inside)Two failure modes follow:
~/.omp/acp-omp-dumps/req_76*.json, sid 01a027f3): pre-compress requests carrysystemLen=45151(824–828 msgs); the moment compression coveredm00001..m00264(which includes the system piece) the wire dropped tosystemLen=0on every subsequent request. The model received no system prompt at all after the first compression.primeFoldreconstructs system content from host state (runtime injections differ across restarts: 45k live vs ~7.4k reconstructed). Since the system piece sat at pos 0 inside the id space, every span fingerprint covering it diverged, and the guard correctly rejected the replay → "Blocks: none" until the first live request re-derived ids in live space.Fix
openaiToCorenow returns{ msgs, systemText }:\n\n);originalRoleround-trip;mirrorOpenaiToCoreneeds no change: the mirror emits systemText asmessages[0], which now folds through the same hoist — mirror and live spaces converge regardless of systemText, which is exactly what restart replay needs.Re-injection stays with the existing
injectOpenaiSystem(callers add[originalSystem, compressPrompt]).Tests
tests/openai-system-hoist.test.ts(6): prefix hoisted + ids identical to system-free body; empty systemText; mid-conversation system kept; system-content changes never shift ids (restart regression); mirror converges with live for arbitrary systemText; re-injection round-trip.tests/wire-bili-message-roundtrip.test.ts: the two tests encoding the old contract (leading-only system/developer bodies) rewritten — prefix hoist + mid-conversationoriginalRoleround-trip.Suite: 428/428,
tsc --noEmitclean.Downstream
systemTextat the fold and re-inject the original on rebuild (follow-up PR + e2e restart regression with live system ≠ reconstruction).server.tsopenai branch currently only injects the compress prompt viainjectOpenaiSystem; after this change it must prepend the originalsystemTexttoo (follow-up PR).