Skip to content

fix(codex): bound reset-credit lookup responses - #1396

Merged
Wibias merged 2 commits into
lidge-jun:devfrom
luvs01:agent/bound-reset-credit-lookup
Aug 10, 2026
Merged

fix(codex): bound reset-credit lookup responses#1396
Wibias merged 2 commits into
lidge-jun:devfrom
luvs01:agent/bound-reset-credit-lookup

Conversation

@luvs01

@luvs01 luvs01 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cap successful reset-credit lookup responses at 64 KiB before JSON parsing
  • bind the upstream body to client cancellation and reject malformed UTF-8 or JSON with a generic 502
  • project only the reset-credit fields used by management clients

Verification

  • bun test tests/codex-auth-api.test.ts --test-name-pattern "reset-credit lookup" — 9 passed, 0 failed
  • bun run typecheck — passed
  • bun run privacy:scan — passed
  • git diff --check — passed
  • two independent focused reviews found no actionable P0–P3 findings
  • bun run test — the changed lookup tests passed; the Windows run later encountered unrelated identity/catalog fixture failures and a Bun 1.3.14 panic

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. No user-facing configuration or API contract changed.
  • 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 handling of reset-credit responses from upstream services.
    • Oversized, malformed, invalidly encoded, or incomplete responses now fail safely with an appropriate error instead of exposing invalid data.
    • Requests are cancelled more reliably when the client disconnects or upstream data cannot be processed.
    • Valid responses now include only approved fields.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eb640040-09c3-4d4e-a9ea-e03b32d09f31

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 reset-credit lookup now reads upstream JSON within a byte limit, handles invalid or truncated bodies, propagates client cancellation, cancels streams, validates response fields, and returns sanitized 502 responses for invalid payloads.

Changes

Reset-credit response handling

Layer / File(s) Summary
Bounded response parser
src/codex/auth-api.ts, tests/codex-auth-api.test.ts
The parser enforces response-size limits, validates UTF-8, rejects truncated or malformed JSON, cancels oversized streams, and filters invalid response fields.
Abort-aware reset-credit lookup
src/codex/auth-api.ts, tests/codex-auth-api.test.ts
The lookup links timeout and client-abort signals, handles cancellation before and after reader attachment, cancels response bodies, cleans up abort listeners, and returns sanitized 502 responses.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ResetCreditLookup
  participant Upstream
  participant BoundedJsonReader
  Client->>ResetCreditLookup: request reset-credit data
  ResetCreditLookup->>Upstream: fetch with linked abort signal
  Upstream-->>BoundedJsonReader: return response body
  BoundedJsonReader-->>ResetCreditLookup: validated fields or parsing failure
  ResetCreditLookup-->>Client: data or sanitized 502 response
Loading

Possibly related PRs

  • lidge-jun/opencodex#866: Both changes handle bounded and cancellation-aware reset-credit or quota responses in different code paths.

Suggested reviewers: lidge-jun, wibias, ingwannu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 main change: bounding reset-credit lookup responses.
✨ 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 added bug Something isn't working intake: hygiene-blocked Deterministic PR hygiene checks failed labels Aug 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deterministic hygiene checks failed.

  • unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/codex/auth-api.ts.

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

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.

4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently. If no CodeRabbit review appears, comment @coderabbitai review to request one.
Maintainers: @lidge-jun @Ingwannu @Wibias

@Wibias Wibias added the maintainer-sponsored Maintainer sponsors this change to an auth, workflow, release, or dependency surface label Aug 10, 2026
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Aug 10, 2026

@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/auth-api.ts`:
- Around line 1723-1752: Update the fetch flow in the rate-limit reset handler
around linkedSignal and fetch so rejections caused by linkedSignal.signal
abortion return the sanitized “Invalid upstream reset-credit response” JSON with
status 502. Preserve the existing outer-catch behavior for unrelated fetch
failures, and add a regression test where the mocked fetch rejects in response
to the passed abort signal.
🪄 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: 070b74a5-feb3-4f9d-bd90-1eda93778abc

📥 Commits

Reviewing files that changed from the base of the PR and between dc4dd45 and a9fa161.

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

Comment thread src/codex/auth-api.ts
@luvs01
luvs01 force-pushed the agent/bound-reset-credit-lookup branch from 512c254 to 96ccc26 Compare August 10, 2026 04:14
@github-actions
github-actions Bot marked this pull request as ready for review August 10, 2026 04:16
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] I am replying to the latest comment only. Earlier comments are unavailable. I will review pull request #1396 independently.

⚠️ Action not completed

Already reviewed.

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 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] Acknowledged. Pull request #1396 is ready for review. The CodeRabbit review was already triggered.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate passed. I will review pull request #1396.

⚠️ Action not completed

Already reviewed.

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.

@Wibias Wibias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @luvs01. This is a useful hardening change: reset-credit lookup now has a strict response-size boundary, follows client cancellation, rejects malformed upstream data safely, and only exposes the fields management clients actually need. That reduces memory/DoS risk and avoids leaking upstream or abort details through this management surface. I reviewed the current head against latest dev; the prior abort-path finding is fixed, there are no unresolved review threads, and exact-head CI is green. LGTM.

@Wibias
Wibias merged commit 0a76ee8 into lidge-jun:dev Aug 10, 2026
31 of 32 checks passed
lidge-jun added a commit that referenced this pull request Aug 10, 2026
The A-phase audit of WP7 found the unit still described a train that had
stopped. Corrections:

- 011 records the re-pick to 9c05134 and voids the omission risk
  acceptance: #1398, #1396, and #1010 are all ancestors of the new RC, so
  nothing is being left out. Old-RC gate evidence is explicitly not reused.
- 012 states that the reviewed tree and the released tree differ only by
  012 itself, proves 0de4fd2 is a real ancestor, and marks the owner
  decision packet resolved rather than pending.
- 010 names the concrete clean main worktree and drops the stale
  out-of-scope line about #1398.

Also withholds the file path of SEC-03, which is still unfixed. Naming the
file of an open finding is the disclosure the rest of the record avoids;
the audit that reviewed these docs missed it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working maintainer-sponsored Maintainer sponsors this change to an auth, workflow, release, or dependency surface review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants