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

Skip to content

refactor(lib): dedupe drifted isRecord guards into the canonical utils helper - #545

Merged
ndycode merged 1 commit into
mainfrom
claude/audit-27-isrecord-sweep
Jun 10, 2026
Merged

ndycode merged 1 commit into
mainfrom
claude/audit-27-isrecord-sweep

Conversation

@ndycode

@ndycode ndycode commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Sweep follow-up to #544 (which fixed a real bug caused by a drifted local isRecord). This PR audits all nine local isRecord definitions under lib/ and dedupes the two that drifted from the canonical array-rejecting contract in lib/utils.ts:

  • lib/codex-manager/commands/rotation.ts — local guard (typeof value === "object" && value !== null) used when parsing the app runtime helper status file; replaced with import { isRecord } from "../../utils.js".
  • lib/refresh-lease.ts — local guard (value !== null && typeof value === "object") used in parseLeasePayload / parseResultPayload; replaced with import { isRecord } from "./utils.js".

Unlike #544, the drift here was latent: downstream per-field validation already produced all-null/invalid results for array payloads, so there is no observable behavior change — this is dedupe plus hardening against the same silent-drift bug class. The six remaining local copies already match the canonical semantics (reject arrays) and are deliberately left in place.

Changes

  • Delete the two drifted local isRecord definitions; import the canonical helper instead.
  • test/refresh-lease.test.ts: new test pinning that an array result file never makes a caller a follower, and an array lock file is an invalid payload (never owned, never treated stale — acquire times out to bypass without deleting it).
  • test/codex-manager-rotation-command.test.ts: new test pinning that an array helper status file reads as "Codex app helper: not running" rather than a record with all-null fields.

Validation

  • npm run typecheck clean
  • npx eslint on all four touched files, --max-warnings=0
  • npx vitest run test/refresh-lease.test.ts test/codex-manager-rotation-command.test.ts — 51/51 passed (49 pre-existing + 2 new)

Risk / Rollback

Low: zero observable behavior change (array payloads were already rejected by field-level checks); the canonical guard is strictly narrower. Independent of #543/#544 (no overlapping files); based on main. Rollback = 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

dedupes two drifted local isRecord guards in lib/refresh-lease.ts and lib/codex-manager/commands/rotation.ts by importing the canonical array-rejecting helper from lib/utils.ts, and adds regression tests pinning that array JSON payloads are correctly rejected in both files.

  • lib/refresh-lease.ts: removes value !== null && typeof value === \"object\" local guard; canonical guard adds !Array.isArray(value), preventing arrays from being silently parsed as lease/result records with all-null fields.
  • lib/codex-manager/commands/rotation.ts: same removal; array status files now correctly return null from readAppRuntimeHelperStatus instead of a record with every field null.
  • two new vitest tests pin the expected behavior for array payloads in both modules, following established test patterns.

Confidence Score: 4/5

changes to the two targeted files are correct and well-tested; a third drifted guard in runtime-current-account.ts reads the same status file and was not fixed

the audit claimed to cover all nine local copies, but lib/runtime/runtime-current-account.ts line 101 still has the array-accepting form (typeof value === 'object' && value !== null) in its own readAppRuntimeHelperStatus — the same read path the rotation.ts fix covers — leaving the latent drift alive in a parallel code path

lib/runtime/runtime-current-account.ts — local isRecord at line 100 is missing !Array.isArray(value)

Important Files Changed

Filename Overview
lib/codex-manager/commands/rotation.ts removes drifted local isRecord (missing !Array.isArray) and imports canonical from utils.js; used only in readAppRuntimeHelperStatus, correct fix
lib/refresh-lease.ts removes drifted local isRecord and imports canonical; used in parseLeasePayload and parseResultPayload; import path ./utils.js is correct
test/refresh-lease.test.ts new test pins that array JSON in result and lock files never produces follower/owner roles; logic is sound and follows established file patterns
test/codex-manager-rotation-command.test.ts new test pins that an array helper status file reads as 'not running' rather than a record with all-null fields; uses createTempRoot which properly registers for afterEach cleanup

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[JSON file on disk] --> B{JSON.parse}
    B --> C[isRecord check]
    C -- "old: typeof obj && !== null\n(arrays pass!)" --> D[field-level validation\nall fields null]
    C -- "new: canonical utils.isRecord\n(arrays rejected)" --> E[return null\nearly exit]
    D --> F[caller sees all-null struct\nsilent bad state]
    E --> G[caller sees null\ncorrect not-running / invalid]
Loading

Reviews (1): Last reviewed commit: "refactor(lib): dedupe drifted isRecord g..." | Re-trigger Greptile

…s helper

Sweep follow-up to the runtime-current-account isRecord fix: of the nine
local isRecord definitions in lib/, two had drifted from the canonical
array-rejecting contract in lib/utils.ts (both accepted arrays):

- lib/codex-manager/commands/rotation.ts (app helper status file parse)
- lib/refresh-lease.ts (lease lock/result payload parse)

Both local copies are deleted in favor of importing the canonical helper.
Unlike the runtime-current-account case, the drift here was latent:
downstream per-field validation already yielded all-null/invalid results
for array payloads, so there is no observable behavior change. New tests
pin the array-rejection contract at both call sites (array lock/result
files never become a lease or follower result; an array helper status
file reads as "not running").

The six remaining local isRecord copies already match the canonical
semantics and are left in place.

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 10, 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 3 minutes and 4 seconds. Learn how PR review limits work.

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

⌛ 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: 604541aa-7ee3-40c6-83cd-0f563ed6c7fc

📥 Commits

Reviewing files that changed from the base of the PR and between 98d9819 and 5562a43.

📒 Files selected for processing (4)
  • lib/codex-manager/commands/rotation.ts
  • lib/refresh-lease.ts
  • test/codex-manager-rotation-command.test.ts
  • test/refresh-lease.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-27-isrecord-sweep
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/audit-27-isrecord-sweep

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.

@ndycode
ndycode merged commit 74a567c into main Jun 10, 2026
1 of 2 checks passed
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