Skip to content

fix(codex): stop reporting every history failure as a Codex DB lock - #1202

Merged
lidge-jun merged 5 commits into
lidge-jun:devfrom
Yuxin-Qiao:fix/1191-history-lock-false-positive
Aug 8, 2026
Merged

fix(codex): stop reporting every history failure as a Codex DB lock#1202
lidge-jun merged 5 commits into
lidge-jun:devfrom
Yuxin-Qiao:fix/1191-history-lock-false-positive

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1191.

  • Fixes the false lock report in [Bug] OpenCodex 2.10.2 falsely reports Codex resume history DB locked on Windows / Codex 0.146.0 #1191: since 2.10.1, ocx start, ocx sync, ocx stop, and ocx restore collapsed every non-converged history outcome into "the history DB is locked (Codex app/IDE open?)". A Windows machine with nothing holding state_5.sqlite still saw the warning on every command, and any other failure (permission, unsafe path, dead worker) was equally hidden.
  • Lock acquisition (H/K/N) now compares the requested lock path against its realpath case-insensitively on Windows via samePathIdentity, so legitimate case differences are not refused as unsafe-path; the Windows runtime root is canonicalized through realpath before anything is keyed on it, so differently-cased or junctioned LocalAppData spellings share one lock namespace.
  • restoreLegacyOpenaiHistory now reports its failure reason (busy/permission) like the other history paths, so ocx recover-history classifies honestly too.
  • Apply, restore, and recover-history messages now distinguish: genuine DB lock/busy, permission denial, unsafe coordinator path, unavailable coordinator database, worker error (with the real message), worker death, and worker timeout. Non-lock failures point at ocx doctor instead of blaming the Codex app.

Verification

  • bun run typecheck — clean on the PR head.
  • bun test focused suites (history provider/worker/job, user identity, lock, transition, guardian, residue, convergence, update-stop, etc.) — 207 tests green.
  • bun test tests/crash-guard.test.ts — green in isolation.
  • bun run privacy:scan — passed.
  • git diff --check — clean.
  • Full suite on the PR head: 9642 run, 13 fail. All 13 are pre-existing/unrelated: 11 in tests/management-provider-validation.test.ts (reproduced on clean dev without this change), 1 flaky crash-guard 5s timeout (green in isolation), 1 pre-existing management-seam race.

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.

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.

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

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions

github-actions Bot commented Aug 7, 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 has been marked 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 notified: @lidge-jun @Ingwannu @Wibias

@github-actions
github-actions Bot marked this pull request as draft August 7, 2026 08:53
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

History jobs now preserve specific failure reasons and report them in apply, restore, and recovery flows. Path validation compares platform-aware path identities. The doctor command probes the history coordinator namespace. Proxy shutdown now detects foreign ownership and avoids shared-state teardown.

Changes

History reliability

Layer / File(s) Summary
Platform-aware path validation
src/codex/user-identity.ts, src/codex/catalog-write-serialization.ts, src/codex/history-lock.ts, src/codex/transition-state.ts
Runtime-root resolution validates trusted paths and rejects redirects. samePathIdentity compares paths by platform-specific identity. Database safety checks use this helper.
Structured history failure reporting
src/codex/history-provider.ts, src/codex/history-job.ts, src/codex/inject.ts, src/cli/index.ts
Retry results preserve busy and permission reasons. Apply, restore, and recovery flows format specific messages for locks, unsafe paths, unavailable databases, permissions, worker errors, exits, and timeouts. Worker diagnostics redact the home directory.
Coordinator namespace diagnostics
src/cli/doctor.ts
The doctor command resolves the effective identity and probes the coordinator namespace. It reports probe failures without aborting pending-history checks.
History and path behavior validation
tests/codex-history-job.test.ts, tests/codex-history-provider.test.ts, tests/codex-history-worker.test.ts, tests/codex-inject-history-wording.test.ts, tests/codex-user-identity.test.ts
Tests cover failure formatting, database errors, exhausted lock retries, worker errors under lock, and platform-specific path identity.

Proxy lifecycle safety

Layer / File(s) Summary
Foreign proxy shutdown handling
src/lib/process-control.ts, src/cli/index.ts, tests/grok-lifecycle.test.ts
stopProxy throws ProxyOwnershipRefusedError for HTTP 409 ownership refusals. Stop paths skip shared-state teardown and report that a foreign proxy remains active.

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

Possibly related PRs

  • lidge-jun/opencodex#863 — Both PRs modify native-profile path validation and process/lifecycle coordination.
  • lidge-jun/opencodex#1106 — Both PRs modify history failure propagation and reporting in history-job.ts, history-provider.ts, and inject.ts.

Suggested labels: review-ready

Suggested reviewers: ingwannu, lidge-jun, wibias

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.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 The changes address [#1191] by preserving and surfacing specific history failure reasons and correcting Windows path identity handling.
Out of Scope Changes check ✅ Passed The changes remain within [#1191]; history diagnostics, Windows path safety, and stop lifecycle handling support accurate recovery and reporting.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: reporting specific history failures instead of incorrectly attributing them all to a Codex database lock.
✨ 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.

@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: 89b8503409

ℹ️ 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/history-job.ts Outdated
Comment thread src/codex/history-job.ts
Comment thread src/codex/user-identity.ts Outdated
Comment thread src/codex/history-job.ts
@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/1191-history-lock-false-positive branch 2 times, most recently from 634dba4 to d18aa52 Compare August 7, 2026 09:25
@github-actions
github-actions Bot marked this pull request as ready for review August 7, 2026 09:25
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] I will review pull request #1202. I am responding to the latest comment only. Earlier comments are unavailable in this context.

⚠️ Action not completed

No files to review.

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.

@github-actions
github-actions Bot marked this pull request as draft August 7, 2026 10:26

@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/inject.ts`:
- Around line 1625-1631: Update formatApplyHistoryFailure so the deferred
headline is selected for both blocked outcomes with reason "busy" and failed
outcomes whose historyFailureReason is "busy"; retain the existing skipped and
not-changed headlines for other cases. Add a regression test covering the failed
busy apply outcome and asserting the deferred wording.
🪄 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: ef9ffa40-10ce-47ee-b3ca-71371a8c05e7

📥 Commits

Reviewing files that changed from the base of the PR and between 89b8503 and 304e5b8.

📒 Files selected for processing (4)
  • src/cli/index.ts
  • src/codex/history-job.ts
  • src/codex/inject.ts
  • tests/codex-history-job.test.ts

Comment thread src/codex/inject.ts Outdated
@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/1191-history-lock-false-positive branch from 304e5b8 to 58746f6 Compare August 7, 2026 10:33
@github-actions
github-actions Bot marked this pull request as ready for review August 7, 2026 10:34
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The pull request is marked ready. I will review the current changes.

⚠️ Action not completed

No files to review.

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.

@github-actions
github-actions Bot marked this pull request as draft August 7, 2026 15:22
@github-actions
github-actions Bot marked this pull request as ready for review August 7, 2026 15:22
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness checklist is complete. I will review the current changes in PR #1202.

⚠️ 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 7, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The pull request is ready. I will review the current changes in #1202.

⚠️ 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.

@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: 9d4d533ed2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cli/doctor.ts Outdated

@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: 6

🤖 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/cli/doctor.ts`:
- Around line 911-917: The coordinator probe in the doctor flow must remain
read-only: update resolveCodexHistorySerializationDatabasePath or introduce a
separate pure path resolver so it computes and validates the namespace without
creating directories, while retaining directory initialization in the
history-operation setup path. Update the probe near resolveEffectiveUserIdentity
and getCodexHome to use the non-mutating behavior, and add a focused Bun
regression test under tests/ asserting the probe leaves the filesystem
unchanged.

In `@src/codex/history-job.ts`:
- Around line 206-209: Update redactWorkerMessage to use the same platform-aware
path normalization and case-sensitivity rules as samePathIdentity when replacing
the home directory, while preserving the existing "~" redaction and non-home
message behavior.

In `@src/codex/inject.ts`:
- Around line 1243-1249: Update the final fallback message in the reason/detail
conditional that constructs the Codex resume-history restoration error so it
names the outcome as unknown rather than blaming the Codex app. Preserve the
existing permission, busy, and detail-specific messages, changing only the
no-reason default branch.
- Around line 1261-1308: Update failedHistoryRestoreFromOutcome to delegate
non-busy and non-permission failure messages to the imported
describeHistoryJobFailure formatter, passing the outcome in each applicable
blocked and failed branch. Retain the existing failedHistoryRestore("busy") and
failedHistoryRestore("permission") handling, and preserve the desired-state
messages that are specific to this mapper.
- Around line 1545-1549: In the outcome-selection ternary, combine the `blocked`
and `failed` cases into one condition that calls
`failedHistoryRestoreFromOutcome(outcome)`. Retain `failedHistoryRestore()` as
the fallback for all other outcomes.
- Around line 1618-1639: Add focused regression tests for
formatApplyHistoryFailure and failedHistoryRestoreFromOutcome. Assert busy
blocked and failed apply outcomes use “Codex resume history migration deferred,”
while non-busy failures use “Codex resume history NOT changed”; also assert
blocked and failed restore outcomes mention “holding the history database” only
for genuine busy reasons and explicitly name other failure reasons.
🪄 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: 3714ed64-8603-4dca-a84e-c427739836a0

📥 Commits

Reviewing files that changed from the base of the PR and between 304e5b8 and 9d4d533.

📒 Files selected for processing (5)
  • src/cli/doctor.ts
  • src/codex/history-job.ts
  • src/codex/inject.ts
  • src/codex/user-identity.ts
  • tests/codex-history-job.test.ts

Comment thread src/cli/doctor.ts Outdated
Comment thread src/codex/history-job.ts
Comment thread src/codex/inject.ts Outdated
Comment thread src/codex/inject.ts Outdated
Comment thread src/codex/inject.ts Outdated
Comment thread src/codex/inject.ts
@Wibias
Wibias marked this pull request as draft August 7, 2026 18:03
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness checklist is complete. I will review pull request #1202.

✅ 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/cli/doctor.ts`:
- Around line 917-918: Update the status === "missing" output in the doctor
namespace reporting flow to state only that the history coordinator namespace is
not present, removing the unsupported lifecycle claim. Add a focused regression
test under tests/ that verifies an absent namespace after prior use is reported
with the neutral wording.
🪄 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: 699dd516-eecc-4f7e-b75e-904e4ecc3645

📥 Commits

Reviewing files that changed from the base of the PR and between 9d4d533 and 5bc5a3c.

📒 Files selected for processing (6)
  • src/cli/doctor.ts
  • src/codex/history-job.ts
  • src/codex/inject.ts
  • src/codex/user-identity.ts
  • tests/codex-inject-history-wording.test.ts
  • tests/codex-user-identity.test.ts

Comment thread src/cli/doctor.ts
@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/1191-history-lock-false-positive branch from 5bc5a3c to 44b0a04 Compare August 8, 2026 04:26
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate is complete. I will review the current changes in #1202.

✅ 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cli/index.ts (1)

712-716: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Block shared teardown after a proxy ownership refusal.

The stopProxy catch at Line 676 through Line 681 explicitly handles ownership refusal errors, but it does not set ownershipBlocked. The new guard at Line 715 through Line 716 checks service ownership only.

If a foreign proxy rejects the stop, restoreSharedClientStateAfterStop() still restores Codex configuration and removes the Grok fence while that proxy is running. Record proxy ownership refusal in the same block flag, or skip shared teardown until ownership is verified.

As per path instructions, changes under src/** must not bypass the shared routing/config layers.

🤖 Prompt for 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.

In `@src/cli/index.ts` around lines 712 - 716, Update the stopProxy
ownership-refusal catch block to set the existing ownershipBlocked flag when a
foreign proxy rejects shutdown, so restoreSharedClientStateAfterStop() is
skipped in that case. Preserve environment rollback behavior and the existing
shared routing/configuration layers.

Source: Path instructions

🤖 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.

Outside diff comments:
In `@src/cli/index.ts`:
- Around line 712-716: Update the stopProxy ownership-refusal catch block to set
the existing ownershipBlocked flag when a foreign proxy rejects shutdown, so
restoreSharedClientStateAfterStop() is skipped in that case. Preserve
environment rollback behavior and the existing shared routing/configuration
layers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d87f3fc2-3eae-40ea-b5a5-1751f2ef0081

📥 Commits

Reviewing files that changed from the base of the PR and between 5bc5a3c and 44b0a04.

📒 Files selected for processing (3)
  • src/cli/index.ts
  • src/codex/inject.ts
  • src/codex/transition-state.ts

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness checklist is complete. I will review pull request #1202.

✅ 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.

The history Worker collapsed every non-converged outcome - a genuine
SQLite busy, a permission denial, an unsafe coordinator path, an
unavailable coordinator database, or a dead/timed-out Worker - into one
message blaming the Codex app/IDE for holding state_5.sqlite. On Windows
that reads as a false lock when nothing holds the file (issue lidge-jun#1191), and
it made every other failure undiagnosable.

- The H/K/N lock modules now compare the requested lock path against its
  realpath case-insensitively on Windows (samePathIdentity), matching the
  case-insensitive path identity Windows actually has, instead of refusing
  legitimate spellings as unsafe-path.
- The Windows runtime root is canonicalized via realpath after creation,
  so differently-cased or junctioned LocalAppData spellings land on one
  lock namespace.
- restoreLegacyOpenaiHistory now reports its failure reason (busy or
  permission) instead of a bare failed flag, so recover-history gets the
  same honest classification.
- Apply, restore, and recover-history messages now distinguish genuine
  lock/busy from unsafe-path, unavailable coordinator DB, permission
  denial, worker error (with the real message), worker death, and worker
  timeout, each pointing at 'ocx doctor' when the app is not the cause.
@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/1191-history-lock-false-positive branch from 58e72c8 to 7883173 Compare August 8, 2026 08:14

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/codex/inject.ts (1)

640-650: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the loopback host with the loopback listener.

Lines 640-650 replace only port. The later calls at Lines 677, 761, 767, and 803 still use config?.hostname. If hostname is 0.0.0.0, a LAN address, or another non-loopback host, Codex receives that host with the loopback-listener port.

The public listener does not own that port. It can also require x-opencodex-api-key, while shouldInjectApiAuthHeader correctly suppresses that header for the unauthenticated loopback listener. Codex then cannot reach the intended listener.

Set one effective injection hostname to 127.0.0.1 when unauthenticatedLoopbackListener.enabled is true. Pass it to every generated provider URL and profile URL.

Proposed fix
 const loopback = config?.unauthenticatedLoopbackListener;
+const injectionHostname = loopback?.enabled ? "127.0.0.1" : config?.hostname;
 if (loopback?.enabled) port = loopback.port;

- `... http://${providerBaseHost(config?.hostname)}:${port}/v1`
+ `... http://${providerBaseHost(injectionHostname)}:${port}/v1`

- buildProviderTableBlock(port, websocketsEnabled(config ?? {}), true, config?.hostname)
+ buildProviderTableBlock(port, websocketsEnabled(config ?? {}), true, injectionHostname)

- setRootOpenaiBaseUrl(content, port, config?.hostname)
+ setRootOpenaiBaseUrl(content, port, injectionHostname)

- buildProfileFile(port, catalogPath, websocketsEnabled(config ?? {}), legacyMode, config?.hostname, config?.fastMode)
+ buildProfileFile(port, catalogPath, websocketsEnabled(config ?? {}), legacyMode, injectionHostname, config?.fastMode)
🤖 Prompt for 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.

In `@src/codex/inject.ts` around lines 640 - 650, Update the injection setup
around the loopback listener to derive an effective hostname of 127.0.0.1
whenever unauthenticatedLoopbackListener.enabled is true, while preserving
config?.hostname otherwise. Use this effective hostname for every generated
provider and profile URL at the later injection call sites, including the flows
around lines 677, 761, 767, and 803, alongside the existing effective port.

Source: Path instructions

src/codex/transition-state.ts (1)

356-369: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Reject initialized coordinator state before applying first-use initialization.

initialize() does not accept a databaseWasAbsent flag, but openCodexCoordinatorTransaction() at src/codex/transition-state.ts:426 passes true for zero-byte files from databaseWasEmpty. In initialize(), unsupported schema versions throw, while existing rows are left unchanged and user_version is only set when it is zero. A competing process can initialize a populated coordinator database while this process's lstat saw zero bytes; databaseWasEmpty then overrides that existing state inside the transaction. Move the coordinator-state check into the transaction after BEGIN IMMEDIATE, or prove the first-use path cannot be applied to a populated database before allowing it.

🤖 Prompt for 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.

In `@src/codex/transition-state.ts` around lines 356 - 369, Update
openCodexCoordinatorTransaction and initialize so first-use initialization is
decided after BEGIN IMMEDIATE using the transaction’s current coordinator state,
not the earlier databaseWasEmpty lstat result. Reject unsupported or
already-initialized state before applying first-use initialization, while
preserving normal initialization for genuinely empty databases and avoiding
overwriting existing rows or schema versions.
tests/grok-lifecycle.test.ts (1)

46-56: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Add runtime regression coverage for proxy ownership refusal.

These assertions inspect CLI_SOURCE and PROCESS_CONTROL_SOURCE. They do not execute stopProxy or handleStop. They can pass even when ProxyOwnershipRefusedError fails the instanceof check or when restoreSharedClientStateAfterStop() runs after the HTTP 409 path.

Add a Bun test that drives the real lifecycle with a mocked 409 response. Cover both proxy-stop call sites. Assert that the command fails, the typed refusal is recognized, and shared teardown is not called. Keep the source checks as supplemental contract checks.

As per path instructions, a behavior change in src/ should come with a focused regression test near the existing tests for that subsystem.

Also applies to: 58-63, 79-85, 88-101, 103-110, 112-117, 187-187

🤖 Prompt for 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.

In `@tests/grok-lifecycle.test.ts` around lines 46 - 56, Add focused Bun runtime
regression tests near the existing lifecycle tests that execute the real
stopProxy and handleStop flows with the proxy stop request mocked to return HTTP
409. Cover both proxy-stop call sites, asserting the command fails,
ProxyOwnershipRefusedError is recognized via instanceof, and
restoreSharedClientStateAfterStop() is not called; retain the existing
CLI_SOURCE and PROCESS_CONTROL_SOURCE assertions as supplemental checks.

Source: Path instructions

🤖 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.

Outside diff comments:
In `@src/codex/inject.ts`:
- Around line 640-650: Update the injection setup around the loopback listener
to derive an effective hostname of 127.0.0.1 whenever
unauthenticatedLoopbackListener.enabled is true, while preserving
config?.hostname otherwise. Use this effective hostname for every generated
provider and profile URL at the later injection call sites, including the flows
around lines 677, 761, 767, and 803, alongside the existing effective port.

In `@src/codex/transition-state.ts`:
- Around line 356-369: Update openCodexCoordinatorTransaction and initialize so
first-use initialization is decided after BEGIN IMMEDIATE using the
transaction’s current coordinator state, not the earlier databaseWasEmpty lstat
result. Reject unsupported or already-initialized state before applying
first-use initialization, while preserving normal initialization for genuinely
empty databases and avoiding overwriting existing rows or schema versions.

In `@tests/grok-lifecycle.test.ts`:
- Around line 46-56: Add focused Bun runtime regression tests near the existing
lifecycle tests that execute the real stopProxy and handleStop flows with the
proxy stop request mocked to return HTTP 409. Cover both proxy-stop call sites,
asserting the command fails, ProxyOwnershipRefusedError is recognized via
instanceof, and restoreSharedClientStateAfterStop() is not called; retain the
existing CLI_SOURCE and PROCESS_CONTROL_SOURCE assertions as supplemental
checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 436c0114-c82d-4b97-97bd-449e52d10188

📥 Commits

Reviewing files that changed from the base of the PR and between 5bc5a3c and 58e72c8.

📒 Files selected for processing (5)
  • src/cli/index.ts
  • src/codex/inject.ts
  • src/codex/transition-state.ts
  • src/lib/process-control.ts
  • tests/grok-lifecycle.test.ts

@github-actions
github-actions Bot marked this pull request as ready for review August 8, 2026 08:16
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@github-actions The readiness checklist is complete. I will review pull request #1202.

⚠️ Action not completed

No files to review.

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.

@lidge-jun
lidge-jun merged commit a81f942 into lidge-jun:dev Aug 8, 2026
30 of 32 checks passed
iF2007 pushed a commit to iF2007/opencodex that referenced this pull request Aug 8, 2026
Records a campaign that gave a terminal disposition to every open bug
issue and bug PR at the 2026-08-08 cutoff, and what it got wrong along
the way.

The unit carries the inventory and disposition matrix with file:line
evidence per verdict, the rebase-and-co-author republish protocol, and
per-work-phase implementation docs. Execution records cover the CI
approval unblock, the first CI results, and the merges and closes.

What the audits overturned is the more useful half. Two issues were
queued for closure as resolved and were not - lidge-jun#1176 carried a maintainer
comment from the same morning asking for a v2.11.0 retest, and lidge-jun#1024
rested on an upstream attribution the plan itself proposed to test and
had not tested. lidge-jun#1155 was queued as an unreachable path and is reachable.
lidge-jun#1263 was diagnosed as having no defect and has a real TOCTOU race, shown
by contrast experiment. lidge-jun#1119 was described as fully absorbed and was
not, so its coverage was recreated on dev before it was closed.

Two execution faults are recorded as faults: lidge-jun#1202 was merged without
checking its exact-head CI had concluded success, violating a reading
rule written earlier in this same unit; and a public comment to a
contributor made a false claim about stream defaulting, corrected on the
PR. A transient six-failure test run is recorded as unexplained rather
than dismissed as flaky, since its log was overwritten before the names
could be preserved.

Nothing in the build, typecheck, or test path reads from devlog/.
privacy:scan passes; repo-hygiene 11 pass / 0 fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants