Skip to content

fix(compact): preserve retained reasoning across native combo failover - #7239

Merged
lidge-jun merged 3 commits into
devfrom
codex/fix-compact-retained-reasoning-failover
Oct 16, 2026
Merged

lidge-jun merged 3 commits into
devfrom
codex/fix-compact-retained-reasoning-failover

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Preserve readable reasoning withheld before a translated Combo compaction when failover succeeds on a canonical native target. Return the unchanged native compaction item followed by the retained historical messages, or an archive notice whose file survives successful replacement history.
  • Keep failure/cancellation archive cleanup and direct native compaction behavior intact; reset Combo selection/cooldowns between the existing parameterized regression cases.
  • Update the compaction contract and public configuration documentation.

Verification

  • Remote Linux focused run on lidge, head 2e969fedfdb8d41802999a29aa8c81422dcd2440: OCX_LANE_SLOTS=3 ~/bin/ocx-lane-ci2.sh 2e969fedfdb8d41802999a29aa8c81422dcd2440 f3-retention-native-2e969fed tests/responses/reasoning-retention-routing.test.ts (passed: typecheck exit 0; 20 tests passed, 0 failed).
  • bun run structure:check and bun run privacy:scan: both passed on the merged head on lidge inside ~/ocx-lane/wt/f3-retention-native-2e969fed. Focused-run summary: ~/ocx-lane/logs/f3-retention-native-2e969fed.summary.
  • The original regression was observed red before the fix. Before the coordinator's Mac execution prohibition arrived, local focused validation completed with 20 passing tests, and typecheck, structure/privacy gates and the docs build passed. No further tests or typecheck are run locally; the remote run and hosted PR CI are the final evidence.
  • Merged latest origin/dev, including fix(gui): restore keep-native-v1 qualifier placement #7237 (050bb444a0), without conflicts before final validation. Full suite intentionally left to hosted GitHub CI per the delegated task's resource boundary. Hosted run 38882505424 is on this exact merged head. At the requested ~35-minute polling limit, gates (including GUI tests, typecheck, privacy and GUI build), docs-site build, structure gate, storage policy, API usage, Docker smoke, npm-global smoke and keyring smoke passed. All four Ubuntu test shards were still running and enforce-target was queued; no current-head failures were reported. Overall hosted CI is PENDING, not certified green. CodeRabbit completed without inline findings.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Co-authored-by: panyuanyuan panyuanyuan@hetao101.com
Co-authored-by: yuanyuanlove yuanyuanlove@users.noreply.github.com

lidge-jun and others added 2 commits October 16, 2026 18:27
Co-authored-by: panyuanyuan <panyuanyuan@hetao101.com>
Co-authored-by: yuanyuanlove <yuanyuanlove@users.noreply.github.com>
Publish locally withheld reasoning or its archive notice alongside successful opaque native compaction output. Isolate combo state between regression cases and document the retention boundary.

Co-authored-by: panyuanyuan <panyuanyuan@hetao101.com>
Co-authored-by: yuanyuanlove <yuanyuanlove@users.noreply.github.com>
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 16, 2026 09:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T09:42:11.126585Z 6e34d48 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 912e6611-2864-4ae0-96cf-801c5a4b8d32
📥 Commits

Reviewing files that changed from the base of the PR and between 4ed45e9 and 6e34d48.

📒 Files selected for processing: 4
  • docs-site/src/content/docs/reference/configuration/server.md
  • src/server/responses/compact.ts
  • structure/transports/responses-failover.md
  • tests/responses/reasoning-retention-routing.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

Routed v1 Combo failover now includes retained reasoning history or an archive notice alongside an opaque native compaction result. The opaque compaction item remains intact. Tests and documentation cover capped and uncapped reasoning retention.

Changes: Routed reasoning retention

Layer / File(s) Summary
Native compaction replacement history
src/server/responses/compact.ts:1795-1805, 1821, tests/responses/reasoning-retention-routing.test.ts:6, 22-23, 31-32, 51-103, structure/transports/responses-failover.md:339, docs-site/src/content/docs/reference/configuration/server.md:830-832, 854-856
The opaque-compaction response appends retained reasoning or an archive notice and retains the archive after publishing replacement history. Tests cover gateway-to-native failover with and without a token cap. Documentation describes archive notices, failure cleanup, and unchanged direct native compact behavior.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 6e34d

No concrete merge-blocking risk is identified; merge after normal checks complete.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: preserving retained reasoning during native Combo failover. It matches the documented implementation and regression tests.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e34d48ed9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


`tests/responses/responses-compaction-override.test.ts` covers source filtering, trigger selection, config
validation, native and routed handlers, credential retention, portable summaries and replay, and combo failover. Only explicit `reasoningRetention.enabled: true` (default off, including legacy limit-only blocks) makes routed v1 `/responses/compact` and direct routed v2 `compaction_trigger` use `src/responses/reasoning-retention.ts` to withhold readable reasoning from its summarizer; exact text including its historical-context frame within the smaller configured percentage/token cap is restored as framed historical context only after a readable summary succeeds. Repeated compact removes that frame locally again; ordinary requests replay it as a user context message, not a fresh reasoning item. Overflow is provisionally archived once per routed turn and kept only when the returned readable summary names its path; failed, cancelled, invalid, or opaque outcomes remove that attempt's file without deleting earlier successful archives. The percentage/token cap bounds retained context only; each overflow file is request-admission bounded under the resolved OpenCodex home’s `reasoning-archive/`, with no aggregate quota or automatic expiry. Successful archives require manual deletion; switching off or resetting does not delete them. Crash or filesystem cleanup failure can leave provisional files. Failure yields no replacement history. Opaque compaction returns only its unchanged item (no added retained message or rewritten ciphertext); native compact keeps existing behavior. Direct routed v2 remains a single compaction output item: `src/responses/retained-compaction.ts` encodes summary and framed reasoning separately as versioned `ocx2:` JSON/Base64 (encoding, not encryption). Replay expands them into separate historical messages; repeated v1/v2 compaction withholds the reasoning again. Existing `ocx1:` summaries remain readable. `src/codex/ocx-compaction-history.ts` also lowers `ocx2:` into separate summary and reasoning messages for explicit native-history recovery, so later proxy compaction still withholds reasoning. `src/server/responses/compaction-retention.ts` owns provisional archives and request-budget retention; failure or body cancellation releases the attempt. Emergency recovery preserves the structured envelope for JSON and SSE instead of flattening reasoning into the summary. `tests/responses/reasoning-retention-v2.test.ts` and `tests/responses/responses-compaction-recovery.test.ts` cover v2 replay and recovery; `tests/responses/reasoning-retention-routing.test.ts` covers these public contracts; `tests/responses/reasoning-retention.test.ts` covers envelopes, limits and archive failures.
validation, native and routed handlers, credential retention, portable summaries and replay, and combo failover. Only explicit `reasoningRetention.enabled: true` (default off, including legacy limit-only blocks) makes routed v1 `/responses/compact` and direct routed v2 `compaction_trigger` use `src/responses/reasoning-retention.ts` to withhold readable reasoning from its summarizer; exact text including its historical-context frame within the smaller configured percentage/token cap is restored as framed historical context after successful compaction, including routed v1 Combo failover to an opaque native result. Repeated compact removes that frame locally again; ordinary requests replay it as a user context message, not a fresh reasoning item. Overflow is provisionally archived once per routed turn and kept only when successful replacement history names its path, in the readable summary or a separate historical notice alongside an opaque native v1 result; failed, cancelled, or invalid outcomes remove that attempt's file without deleting earlier successful archives. The percentage/token cap bounds retained context only; each overflow file is request-admission bounded under the resolved OpenCodex home’s `reasoning-archive/`, with no aggregate quota or automatic expiry. Successful archives require manual deletion; switching off or resetting does not delete them. Crash or filesystem cleanup failure can leave provisional files. Failure yields no replacement history. Opaque compaction preserves its unchanged item and ciphertext. Routed v1 failover appends any locally withheld retained messages or an archive notice; direct native compact keeps existing behavior. Direct routed v2 remains a single compaction output item: `src/responses/retained-compaction.ts` encodes summary and framed reasoning separately as versioned `ocx2:` JSON/Base64 (encoding, not encryption). Replay expands them into separate historical messages; repeated v1/v2 compaction withholds the reasoning again. Existing `ocx1:` summaries remain readable. `src/codex/ocx-compaction-history.ts` also lowers `ocx2:` into separate summary and reasoning messages for explicit native-history recovery, so later proxy compaction still withholds reasoning. `src/server/responses/compaction-retention.ts` owns provisional archives and request-budget retention; failure or body cancellation releases the attempt. Emergency recovery preserves the structured envelope for JSON and SSE instead of flattening reasoning into the summary. `tests/responses/reasoning-retention-v2.test.ts` and `tests/responses/responses-compaction-recovery.test.ts` cover v2 replay and recovery; `tests/responses/reasoning-retention-routing.test.ts` covers these public contracts; `tests/responses/reasoning-retention.test.ts` covers envelopes, limits and archive failures.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the stale mapped compaction contracts

This source-area contract change leaves structure/overview.md:313, structure/config.md:33, and structure/dashboard-and-usage.md:132 stating that retained reasoning returns only after a readable summary or that opaque output stays unchanged. Those statements now contradict the documented native Combo failover behavior on this line, where an opaque result gains retained messages or an archive notice; update the affected mapped documents so the repository's architecture contracts agree.

AGENTS.md reference: structure/AGENTS.md:L49-L52

Useful? React with 👍 / 👎.

Include the merged keep-native-v1 GUI correction before final hosted validation.

Co-authored-by: panyuanyuan <panyuanyuan@hetao101.com>
Co-authored-by: yuanyuanlove <yuanyuanlove@users.noreply.github.com>
@lidge-jun
lidge-jun merged commit d3cb552 into dev Oct 16, 2026
33 of 35 checks passed
@lidge-jun
lidge-jun deleted the codex/fix-compact-retained-reasoning-failover branch October 16, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant