fix(pi): reduce OMP native inputs and optional Codex reasoning - #433
fix(pi): reduce OMP native inputs and optional Codex reasoning#433SilentBless wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
2 issues found across 10 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/pi-plugin/src/signal-peek-drain.test.ts">
<violation number="1" location="packages/pi-plugin/src/signal-peek-drain.test.ts:210">
P2: This test was removed even though every assertion it pinned still holds against the current source. The test's `code` reads context-handler.ts, which still contains `stripInlineThinkingPi({`, `const combinedWatermark = Math.max(`, and `clearedReasoningThroughTag: combinedWatermark` (lines 5672, 5678, 5684). No other test covers the inline-thinking watermark-sharing wiring, so removing it drops regression coverage with no corresponding source change to justify it. Restore the test or update it if the watermark sharing was intentionally reworked.</violation>
</file>
<file name="packages/pi-plugin/src/native-replay-pi.ts">
<violation number="1" location="packages/pi-plugin/src/native-replay-pi.ts:170">
P2: When an incremental Codex reasoning item has a non-empty `summary`, `clearNativeReasoning` still deletes it because it only checks `content`. Preserve non-empty `summary` items as well, otherwise context reduction drops visible native reasoning instead of only removable encrypted-only reasoning.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| (item.content !== undefined && | ||
| (!Array.isArray(item.content) || item.content.length > 0)) |
There was a problem hiding this comment.
P2: When an incremental Codex reasoning item has a non-empty summary, clearNativeReasoning still deletes it because it only checks content. Preserve non-empty summary items as well, otherwise context reduction drops visible native reasoning instead of only removable encrypted-only reasoning.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/pi-plugin/src/native-replay-pi.ts, line 170:
<comment>When an incremental Codex reasoning item has a non-empty `summary`, `clearNativeReasoning` still deletes it because it only checks `content`. Preserve non-empty `summary` items as well, otherwise context reduction drops visible native reasoning instead of only removable encrypted-only reasoning.</comment>
<file context>
@@ -0,0 +1,187 @@
+ if (
+ typeof item.encrypted_content !== "string" ||
+ item.encrypted_content.length === 0 ||
+ (item.content !== undefined &&
+ (!Array.isArray(item.content) || item.content.length > 0))
+ ) {
</file context>
| (item.content !== undefined && | |
| (!Array.isArray(item.content) || item.content.length > 0)) | |
| ((item.content !== undefined && | |
| (!Array.isArray(item.content) || item.content.length > 0)) || | |
| (item.summary !== undefined && | |
| (!Array.isArray(item.summary) || item.summary.length > 0))) |
| ); | ||
| }); | ||
|
|
||
| test("inline thinking stripping shares the reasoning watermark", () => { |
There was a problem hiding this comment.
P2: This test was removed even though every assertion it pinned still holds against the current source. The test's code reads context-handler.ts, which still contains stripInlineThinkingPi({, const combinedWatermark = Math.max(, and clearedReasoningThroughTag: combinedWatermark (lines 5672, 5678, 5684). No other test covers the inline-thinking watermark-sharing wiring, so removing it drops regression coverage with no corresponding source change to justify it. Restore the test or update it if the watermark sharing was intentionally reworked.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/pi-plugin/src/signal-peek-drain.test.ts, line 210:
<comment>This test was removed even though every assertion it pinned still holds against the current source. The test's `code` reads context-handler.ts, which still contains `stripInlineThinkingPi({`, `const combinedWatermark = Math.max(`, and `clearedReasoningThroughTag: combinedWatermark` (lines 5672, 5678, 5684). No other test covers the inline-thinking watermark-sharing wiring, so removing it drops regression coverage with no corresponding source change to justify it. Restore the test or update it if the watermark sharing was intentionally reworked.</comment>
<file context>
@@ -207,12 +207,6 @@ describe("source contract: peek-then-drain in runPipeline (history)", () => {
- expect(code).toContain("clearedReasoningThroughTag: combinedWatermark");
- });
-
test("model switch reset clears usage, reasoning, failure, limit, and recovery state", () => {
expect(code).toContain("clearedReasoningThroughTag: 0");
expect(code).toContain("clearHistorianFailureState(options.db, sessionId)");
</file context>
There was a problem hiding this comment.
Thanks for narrowing this to the native mutation units rather than dropping the whole payload. I checked OMP's Codex serializer directly: same-model native history bypasses the content conversion, and incremental versus full-snapshot replay behaves as described. I also reproduced the source-level 54,932 → 4,947 result against OMP source, with the native text, hosted image result and tool pair retained, and identical serialized bytes on the following defer pass. Your reported live OMP continuation check is valuable additional evidence beyond that source test.
Please address these before merging:
- Existing
clearedReasoningThroughTagand dropped-tag state predate native rewriting. The new every-pass replay inreasoning-replay-pi.ts/context-handler.tstreats those records as permission to change native bytes immediately, even when no new reduction is queued. Please persist first native application on an already-authorized cache-busting pass, then replay that decision unchanged. Add upgrade-state coverage for both reasoning and already-dropped tool inputs, including multiple defer passes. A seeded legacy-watermark, zero-pressure/empty-queue probe currently removes native ciphertext that was previously retained. - Please restore the deleted “inline thinking stripping shares the reasoning watermark” test in
signal-peek-drain.test.ts, or replace it with stronger coverage of that same property and explain the change. The production code still shares that watermark; restoring the test unchanged passes. - Please separate native retention from ordinary non-Codex typed-thinking cleanup. In
reasoning-replay-pi.ts:155and the matching replay branch,continueonpreservednow suppresses existing cleanup for non-Codex Responses payloads. I ran the same real context-handler fixture on this PR and current master: at 90% usage master empties the old thinking and removes its signature, while this PR retains both and leaves the watermark at zero. A seeded-watermark replay also clears on master but not on the PR. Preserve actual required native dependencies, but add false-capability/non-Codex coverage so that policy does not inadvertently disable the legacy content lane.
I also verified the automated serialization concern in its narrower form: a programmatic BigInt input passed to the native tool-input setter throws here but not on master. A defensive serialization catch is sensible; ordinary JSON model arguments cannot produce that example, so I am not claiming a demonstrated remote-model pipeline outage. Conversely, I would not adopt the suggested blanket preservation of nonempty reasoning summary: your reproduction intentionally clears such old summaries together with optional encrypted reasoning. That is distinct from the protected plaintext reasoning content field.
The new regressions are substantive: reverting the native transcript synchronization, mixed/plaintext preservation guard, and native rollback capture each makes its corresponding test fail. The rollback assertion also really reaches the faulted persistence write. I additionally tested a failed-write pass followed by two defer passes through OMP's actual serializer: one attempted write, watermark zero, retained ciphertext, and three byte-identical 5,817-character inputs (A→A→A). I do not see the rollback restore itself introducing an A→B→A wire flip. Snapshotting a native payload reference when omission is disallowed is avoidable allocation work, not a demonstrated byte-stability defect.
One documentation/testing caveat: function calls carry the canonical dropped-marker JSON, while custom calls use OMP's existing empty-string fallback. The latter does not carry the dropped marker and should not be claimed to have identical copied-input rejection behavior without a tool-level test. Also, this head already includes #431 and the shared bust-permission changes; my cache concern is the first activation of the new native representation, not a missing rebase.
|
Follow-up after checking the contract with the Oh My Pi side: clearing old encrypted reasoning with both compat flags false is supported as described, with computer-call-linked reasoning as the only retention exception (under those flags the native builder emits no reasoning placeholders, so the clearing matches what native would send). Rewriting a matched |
|
Review follow-up pushed in
The proposal to preserve every nonempty native The README also states the native API boundary: OMP has no dedicated native-item mutation API. These reductions operate on the request transcript; the adapter does not itself perform a stored JSONL rewrite. OMP normally clones context input, with a shallow-array fallback for non-cloneable data; native tool-input updates are copy-on-write. Verification on the updated upstream integration:
No new live model calls were made for this follow-up. The four-turn live evidence above remains tied to |
|
Addressed the upgrade-state feedback in f161392.
Verification:
No new live-provider requests were made for this update. The earlier live Codex continuation evidence remains separate from these upgrade/cache-state checks. |
There was a problem hiding this comment.
All reported issues were addressed across 15 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
84d215d to
29d0b26
Compare
What
Reduce OMP's native tool inputs and eligible old Codex reasoning without discarding the surrounding provider-native history.
function_call.argumentsorcustom_tool_call.inputwhile preserving call identity, unrelated native-only reasoning and hosted results.Native text, user/developer carriers and full-history semantics are not rewritten. Ordinary tag injection does not mutate native history. Scheduling and protected windows are unchanged. This PR does not claim to solve every native-text reduction case.
Why
OMP intentionally treats
assistant.providerPayload.itemsas authoritative on same-model native replay. Magic Context currently reduces a tool input or clears old reasoning inassistant.contentwhile leaving that native copy intact. The queue can drain and record a dropped tag, yet the original large input and encrypted reasoning are serialized into the next request.Clearing the whole assistant payload is not an equivalent fix: a source-level counterexample removes the stale input but also loses unrelated native-only reasoning and a hosted image result, even though the selected tool pair remains valid.
The fix is deliberately limited to the two mutation units in the reproduction. Native-text synchronization was excluded after review identified fragmented text identities and instrumentation ownership concerns; it requires a separate contract, not a broader heuristic mapper here.
Preservation boundaries
Native reasoning remains intact for non-Codex or unknown model capabilities, mandatory all-turn/tool-call reasoning, full snapshots, plaintext/malformed reasoning, redacted thinking and computer-linked reasoning. These cases are retained rather than speculatively reconstructed. Tool inputs with ambiguous identities are not guessed.
Related work
No
Fixesreference is used because these are related precedents, not demonstrated duplicates.Verification
The actual Magic Context queue/transcript functions and OMP serializers were exercised from their TypeScript sources using synthetic fixtures. The original queued reduction shrank its serialized request from 146,083 to 5,121 characters, removed old arguments and reasoning, and retained recent encrypted reasoning, a hosted image result and the selected tool pair. Additional source-level checks cover custom-input fallback parity, full-snapshot authority, synthesized tool IDs and mandatory reasoning preservation.
A subsequent live check used the normal installed OMP v18.1.10 CLI with an isolated profile and this built extension on
openai-codex/gpt-6-astra:xhigh. Four model turns completed: the native tool input was actually replaced before a successful continuation, and a real encrypted reasoning item from a later response was then removed before another successful continuation (MC_PROFILE_REASONING_OK.). Its original ciphertext remained in the saved source session; the observer checked its hash was absent from outgoing native history, and the persisted clearing watermark advanced to its range. The native call ID remained stable. Noprevious_response_idshortcut or custom transport was used. This establishes live acceptance for this tested Codex flow, not every provider or native-history shape. Final gates after removing the standalone probes:Independent reviews identified synthesized tool IDs, mandatory reasoning, mixed plaintext/encrypted items and native-text identity risks. The first three are handled by the targeted code and regressions; native-text rewriting was removed from scope. The separate
droppedTokensaccounting issue is unchanged.Source-level OMP handler reproduction
Use sibling Magic Context and OMP source checkouts with their normal development dependencies (including the OMP native addon). The reference OMP revision was
34e938c3b37ab3b60375a6cef9c137166cb5fb70. Save this insidepackages/pi-plugin/native-replay-probe.test.tsand runbun test native-replay-probe.test.tsthere. It runs the real context handler and serializer, not a remote provider.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Fixes OMP native replay so tool-input reductions and eligible Codex reasoning clearing now mutate the serialized provider history and persist as durable replay state, so the reductions survive restarts and session clones.
Bug Fixes
function_call.argumentsorcustom_tool_call.inputwhile preserving call identity, unrelated native-only reasoning, and hosted results; leaves calls untouched when reduced inputs cannot be safely serialized to JSON.providerPayloadif persisting either replay state fails; malformed persisted state also fails closed, keeping native history intact, and the decision retries on the next authorized pass.Written for commit 29d0b26. Summary will update on new commits.
Greptile Summary
This PR synchronizes Magic Context reductions with OMP’s provider-native replay history and persists those decisions across subsequent passes, restarts, and session clones.
Confidence Score: 5/5
The PR appears safe to merge because no actionable new failures or repository-rule violations were identified.
The changes since the previous review introduce no additional code differences, and the current implementation conservatively validates persisted state, gates native mutations, and preserves the prior payload when persistence fails.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Pi context pass] --> B[Apply local transcript reductions] B --> C[Commit canonical transcript] C --> D[Load persisted native replay state] D --> E[Replay saved tool inputs and reasoning decisions] E --> F{Authorized cache-busting pass?} F -- No --> G[Return replayed history] F -- Yes --> H[Detect new native mutations] H --> I{Persist decisions successfully?} I -- Yes --> J[Publish updated native payload] I -- No --> K[Retain prior native payload] J --> G K --> GReviews (5): Last reviewed commit: "refactor: clarify native replay ownershi..." | Re-trigger Greptile