Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: throw CodexValidationError from rotation-proxy startup guards - #586

Merged
ndycode merged 2 commits into
mainfrom
claude/audit-67-typed-error-adoption
Jun 11, 2026
Merged

ndycode merged 2 commits into
mainfrom
claude/audit-67-typed-error-adoption

Conversation

@ndycode

@ndycode ndycode commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • First slice of the audit's §4.3 error-contract adoption (finding M11): the two startup guards in startRuntimeRotationProxy now throw CodexValidationError with machine-readable metadata instead of bare Error, and the guarantee is documented in docs/reference/error-contracts.md.

What Changed

lib/runtime-rotation-proxy.ts — two conversions, messages byte-identical:

  • The loopback-only host refusal (runtime-proxy-01 defense) throws CodexValidationError with field: "host", expected: "a loopback host", and the offending host in context.host.
  • The missing-clientApiKey check throws CodexValidationError with field: "clientApiKey", expected: "a non-empty string".

Since messages are unchanged, every existing message-matching caller and test (rejects.toThrow("clientApiKey"), /non-loopback/i, /loopback-only/i) passes untouched; callers gain instanceof CodexValidationError and the stable CODEX_VALIDATION_ERROR code.

docs/reference/error-contracts.md — new "Typed Error Classes" section: lists the lib/errors.ts hierarchy and records the startup-guard guarantee, so the contract doc is backed by machine-readable types as §4.3 intended. It sits next to the existing note that the dual-call helpers deliberately throw native TypeError (that convention is unchanged).

test/runtime-rotation-proxy.test.ts — one new test capturing both guard rejections and asserting the class, field, and context payloads.

Scope Note

The three remaining bare throws in lib/config.ts (Aborting config save because … is unreadable.) are deliberately deferred: one of them sits inside the ESTALE CAS block that open PR #585 rewrites, and converting them now would make my own two open PRs conflict. They'll be a tiny follow-up once #585 merges. After that, the three files §4.3 names carry no bare throws (fetch-helpers already has none — it returns mapped Responses by design).

Validation

  • npm run typecheck (also in the pre-commit hook)
  • npx eslint lib/runtime-rotation-proxy.ts test/runtime-rotation-proxy.test.ts --max-warnings=0
  • npm test -- test/runtime-rotation-proxy.test.ts — 77 passed; the only 2 failures are the documented IPv6-disabled-container baseline names (EAFNOSUPPORT ::1, both present verbatim in docs/audits/evidence/test-baseline-2026-06-10.txt)
  • npm run build deferred to CI

Docs and Governance Checklist

  • docs/reference/error-contracts.md updated in the same PR as the behavior it documents
  • No user-visible message, command, or path changed; CodexValidationError extends CodexError extends Error, so all instanceof Error handling is unaffected

Risk and Rollback

  • Risk level: low — error class tightened, message and throw conditions identical. The only observable difference is richer metadata on the error object.
  • Rollback plan: revert the single commit.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB


Generated by Claude Code

note: greptile review for oc-chatgpt-multi-auth. cite files like lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.

Greptile Summary

tightens the two startup guards in startRuntimeRotationProxy from bare Error to CodexValidationError with machine-readable field, expected, and context fields, and documents the contract in error-contracts.md. messages are byte-identical, so all existing message-matching callers and tests are unaffected.

  • lib/runtime-rotation-proxy.ts: host and clientApiKey guards now throw CodexValidationError; callers gain instanceof branching and the stable CODEX_VALIDATION_ERROR code.
  • test/runtime-rotation-proxy.test.ts: new test covers both guards end-to-end, asserting field, expected, and context payloads.
  • docs/reference/error-contracts.md: new "Typed Error Classes" section records the error hierarchy and the startup-guard guarantee.

Confidence Score: 5/5

safe to merge — error class tightened, throw conditions and messages unchanged, backward-compatible via inheritance

both guards are narrow, deterministic throws at startup; the change only adds metadata to the thrown object. CodexValidationError extends CodexError extends Error, so all instanceof Error and message-matching paths in existing callers and tests continue to work. the new test fully covers field, expected, and context for both guards.

no files require special attention

Important Files Changed

Filename Overview
lib/runtime-rotation-proxy.ts two bare throws converted to CodexValidationError with structured field/expected/context metadata; import added; no logic change
test/runtime-rotation-proxy.test.ts new test exercises both startup guards and asserts instanceof, field, expected, and context; prior feedback on expected assertions was addressed
docs/reference/error-contracts.md new "Typed Error Classes" section documents the CodexError hierarchy and startRuntimeRotationProxy startup-guard guarantees; accurate against errors.ts

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[startRuntimeRotationProxy called] --> B{isLoopbackHost host?}
    B -- no --> C[throw CodexValidationError\nfield: host\nexpected: a loopback host\ncontext: host]
    B -- yes --> D{clientApiKey non-empty?}
    D -- no --> E[throw CodexValidationError\nfield: clientApiKey\nexpected: a non-empty string]
    D -- yes --> F[continue startup…]
Loading

Reviews (2): Last reviewed commit: "test: assert the expected field from bot..." | Re-trigger Greptile

First slice of the audit's §4.3 error-contract adoption (M11). The two
startup guards in startRuntimeRotationProxy — the loopback-only host
refusal and the missing clientApiKey check — now throw
CodexValidationError with field/expected metadata (and the offending
host in context) instead of bare Error. Messages are byte-identical, so
existing message-matching callers and tests are unaffected; callers can
now branch on instanceof or the stable CODEX_VALIDATION_ERROR code.

Documents the guarantee in docs/reference/error-contracts.md (new Typed
Error Classes section) and pins it with a test asserting the class,
field, and context from both guards.

The remaining bare throws in savePluginConfig are deferred until #585
merges - they sit inside the ESTALE CAS block that PR rewrites.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ndycode, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 18 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b167ab56-c5df-47bf-97c0-96c3ee4d97c8

📥 Commits

Reviewing files that changed from the base of the PR and between fb06ca6 and 5433ee0.

📒 Files selected for processing (3)
  • docs/reference/error-contracts.md
  • lib/runtime-rotation-proxy.ts
  • test/runtime-rotation-proxy.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-67-typed-error-adoption
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/audit-67-typed-error-adoption

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 and usage tips.

Comment thread test/runtime-rotation-proxy.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants