Skip to content

fix(codex): skip empty native-profile stage sweeps (#1120) - #1134

Merged
lidge-jun merged 1 commit into
devfrom
codex/260806-stack02-native-profile-sweep
Aug 7, 2026
Merged

fix(codex): skip empty native-profile stage sweeps (#1120)#1134
lidge-jun merged 1 commit into
devfrom
codex/260806-stack02-native-profile-sweep

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

Stops a zero-profile installation from fencing itself on a stage-sweep lock it never needed.

runOwnedStageSweep (src/codex/native-profile-startup.ts:131) always called manager.sweepStages(), and sweepStages (src/codex/native-profile-manager.ts:916) entered the locked path even when there was no stage registry and no staging tree at all. A transient lock or Windows ACL failure then left the native-main gate in stage-cleanup-required, native requests surfaced a 503 that read like upstream capacity pressure, and doctor/recover contended on the same profile transaction — the catch-22 in the report.

The sweep is now skipped only when both the stage registry and this instance's staging tree are provably absent. Any artifact that is present, or any path that cannot be proven absent, still enters the existing locked fail-closed cleanup, and owner/claim protection for the physical native-main credential is untouched. The 503 now identifies local native-profile maintenance instead of upstream capacity.

Closes #1120.

Attribution

This is @Ingwannu's work from #1124, cherry-picked with their authorship intact. #1124 stays open for them. The absence-only framing is the right instinct here: the regression test pins that a zero-stage install cannot be fenced and that present-or-unreadable state still fails closed, which is what keeps this safe on a credential path.

Reported by @MarcusNeufeldt (#1120), whose report correctly separated "the lock file exists" from "a transaction is held".

Stack 2 of the 260806 attribution campaign, stacked on #1133. Planning unit: devlog/_plan/260806_stacked_bug_campaign/.

Verification

  • bun test tests/native-profile-stage-lifecycle.test.ts tests/codex-auth-context.test.ts tests/native-profile-drain-server.test.ts — 51 pass, 0 fail
  • bun run typecheck — exit 0
  • bun run privacy:scan — passed
  • Full bun run test via the repository prepush gate — passed

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.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • ^dev$
  • ^preview$

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: c96443b7-d020-4742-8a3b-62f1230ecfb9

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

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
Contributor

Deterministic PR hygiene checks passed.

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

@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: 94c5ccf596

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

* can never be mistaken for an unused profile subsystem.
*/
stageSweepRequired(): boolean {
for (const path of [this.context.stageRegistryPath, this.context.stagingRoot]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep legacy stage state on the fail-closed path

When an upgraded installation still has preview-era state under context.legacyRootDir—especially staging/<homeId>/auth.json—but neither current stage path exists, both lstatSync calls return ENOENT and startup skips the sweep. Previously, sweepStages() entered withLock(), where assertNoLegacyNativeProfileState() rejected this state and kept the native-main gate blocked; this change instead marks traffic ready while legacy staged credentials remain unresolved. Include legacy-state validation in this preflight and treat any legacy state or inspection failure as sweep-required.

AGENTS.md reference: AGENTS.md:L218-L224

Useful? React with 👍 / 👎.

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.

2 participants