Skip to content

fix(codex): bound oversized rollout inspection - #1115

Draft
Simon-Opopeee wants to merge 5 commits into
lidge-jun:devfrom
Simon-Opopeee:agent/native-history-inspection-fix
Draft

fix(codex): bound oversized rollout inspection#1115
Simon-Opopeee wants to merge 5 commits into
lidge-jun:devfrom
Simon-Opopeee:agent/native-history-inspection-fix

Conversation

@Simon-Opopeee

@Simon-Opopeee Simon-Opopeee commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • Bound native Codex rollout inspection to 64 MiB before loading a referenced JSONL file into memory.
  • Resolve and re-stat the rollout around the read so a changed file fails closed instead of being classified from inconsistent contents.
  • Add a regression test proving an oversized referenced rollout is reported as indeterminate without being loaded.

This pull request is intentionally separate from the GitHub Copilot Responses normalization work in #1111, following maintainer review. It targets the native startup/history safety gap only.

Verification

  • bun test ./tests/codex-native-residue.test.ts — pass.
  • bun run typecheck — pass.
  • bun run privacy:scan — pass.
  • git diff --check — pass.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed; this is an internal safety fix with focused test coverage.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation of referenced rollout files, including checks for both initial and latest session metadata.
    • Oversized, unreadable, modified, truncated, absent, malformed, or structurally invalid files are now reported as indeterminate instead of producing unreliable classifications.
    • Added a 64 MiB inspection limit to prevent excessively large rollout files from being loaded.
    • Preserved existing provider-based classification behavior when valid metadata is available.
    • Correctly recognizes native metadata as residue when rollout files lack a trailing newline.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7b376016-bfb8-47bf-9958-4cf82784d95f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The rollout classifier now performs bounded descriptor-based inspection, detects file changes during reads, validates first and latest metadata records, and reports indeterminate results for inspection failures. Tests cover invalid latest metadata and oversized rollouts.

Changes

Rollout inspection

Layer / File(s) Summary
Bounded rollout reading
src/codex/native-residue.ts
The classifier parses JSONL records and reads resolved rollout paths through file descriptors. It enforces a 64 MiB limit, checks for truncation and concurrent changes, closes descriptors, and reports indeterminate results for inspection failures.
Metadata classification and regression coverage
src/codex/native-residue.ts, tests/codex-native-residue.test.ts
Validation checks both first and latest session metadata records. The classifier reports residue when either provider is opencodex. Tests cover invalid latest metadata, missing trailing newlines, and oversized rollouts without loading their contents.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: lidge-j

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 main change: limiting oversized Codex rollout inspection.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • review readiness checklist open (3/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 3/4).

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

3/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@Simon-Opopeee

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/codex/native-residue.ts`:
- Around line 412-420: Update the validation loop in the residue-detection
function so both first and latest session_meta records are fully validated
before deciding the result; track whether either validated model_provider is
"opencodex", then return residue only after the loop, otherwise preserve the
existing indeterminate behavior. Add a focused regression test near the existing
native-residue tests covering a valid OpenCodex first record with invalid latest
metadata and asserting indeterminate.
- Around line 375-389: Update the rollout inspection flow around the content
read and JSONL loop to open and stat a single file descriptor, then read at most
the captured size using fixed-size chunks rather than readFileSync. Parse each
JSONL record incrementally without creating an array for all lines, restat the
same descriptor after reading, and return indeterminate for short reads or any
metadata change; preserve the existing unreadable-rollout handling.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 87be70f4-acb9-4ade-90c3-5962166b3b29

📥 Commits

Reviewing files that changed from the base of the PR and between a5b3782 and 248074c.

📒 Files selected for processing (2)
  • src/codex/native-residue.ts
  • tests/codex-native-residue.test.ts

Comment thread src/codex/native-residue.ts Outdated
Comment thread src/codex/native-residue.ts Outdated
@Simon-Opopeee

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/codex/native-residue.ts`:
- Around line 385-408: Replace the full-buffer conversion and subsequent
line-array parsing in the rollout inspection flow with incremental parsing of
bounded read chunks. Track only the current partial JSONL record plus the first
and latest session_meta payloads, processing each complete line as it arrives
and preserving behavior across chunk boundaries; remove the content.split("\n")
approach and avoid retaining all parsed lines.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 13e9739a-f219-40ef-b3a6-b637076019f5

📥 Commits

Reviewing files that changed from the base of the PR and between 248074c and e442ab0.

📒 Files selected for processing (2)
  • src/codex/native-residue.ts
  • tests/codex-native-residue.test.ts

Comment thread src/codex/native-residue.ts Outdated
@Simon-Opopeee

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/codex/native-residue.ts`:
- Around line 419-427: Update the descriptor-read loop around readSync to
enforce opened.size as the hard read bound: stop only when totalRead reaches
opened.size, request no more than the remaining observed bytes, and return
indeterminate if readSync returns zero before reaching that size. After the
bounded read, compare the post-read descriptor stat against opened before
continuing, preserving the existing inspection-limit handling.
- Around line 427-453: Update the read-and-parse flow around the chunk decoding
in the native residue implementation to use a single streaming TextDecoder,
decoding each buffer with stream mode and flushing it after the read loop before
processing the remaining partial text. Preserve the existing
rolloutSessionMetaPayload handling and first/latest assignments, and add a
focused regression test that splits a non-ASCII session ID across
ROLLOUT_READ_CHUNK_BYTES.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d5cf7bc6-7260-4863-a51e-eb16398863bf

📥 Commits

Reviewing files that changed from the base of the PR and between e442ab0 and bed7555.

📒 Files selected for processing (2)
  • src/codex/native-residue.ts
  • tests/codex-native-residue.test.ts

Comment thread src/codex/native-residue.ts Outdated
Comment thread src/codex/native-residue.ts Outdated
@Simon-Opopeee
Simon-Opopeee force-pushed the agent/native-history-inspection-fix branch from f509e68 to 926621d Compare August 6, 2026 12:30
@Simon-Opopeee
Simon-Opopeee marked this pull request as ready for review August 6, 2026 12:31
@github-actions
github-actions Bot marked this pull request as draft August 6, 2026 12:31

@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: 926621db5e

ℹ️ 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".

Comment thread src/codex/native-residue.ts
Comment thread src/codex/native-residue.ts Outdated
Comment thread src/codex/native-residue.ts Outdated
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