Repository navigation
fix(config): replace stale pre-migration backup instead of crashing - #258
Conversation
…issue #257) When ocx init writes a fresh config, the old .pre-openai-tiers-v2.bak from a previous installation becomes orphaned. The next ocx start would crash with OpenAiTierBackupCollisionError because the backup differs from the new config. Two layers of defense: 1) ocx init now deletes any stale backup after writing a fresh config. 2) backupConfigBeforeOpenAiTierMigration now replaces a stale backup with a warning instead of throwing, catching the same state through other paths (manual edits, partial upgrades).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 272ae8604a
ℹ️ 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".
- Delete stale backup and fall through to atomic creation path instead of writing in-place, ensuring secrets are written to a hardened temp file before publication (addresses Codex comment about hardening before write) - Update e2e test expectation: collisionFailsBeforeSave is now false since stale backups are replaced instead of causing a crash - Update fixture to capture first migration warnings before collision test - Update unit test to expect 'created' instead of 'reused' for stale path
Add actionable guidance to the error message: tell users to run 'ocx init' or check their config. The previous message was technical and didn't help users who hadn't configured a provider yet.
… configured" This reverts commit 7753409.
|
Review status: the direction is right (replacing a stale pre-migration backup instead of crashing on fresh init), but all three OS legs are failing on the same e2e assertion — the end-to-end contract in One policy question to resolve in the same pass: the current heuristic treats a manually-edited config as "stale" too — is that intended? A manual edit that happens to collide shouldn't silently get replaced. Once the e2e contract is updated and CI is green across the 3 OS legs, this is ready for another look. (Tracking issue: #257.) |
Address PR #258 owner policy question: silently replacing any differing backup treated a user-intentional rollback point as stale, which is destructive if the user manually created or edited the v2 backup. New heuristic in backupConfigBeforeOpenAiTierMigration: - Parse the existing backup as JSON. - If it has openaiProviderTierVersion === 2, it is a post-migration snapshot that became stale when config.json was rewritten (e.g. ocx init after a prior migration). Replace it. - If it is unparseable JSON (e.g. a test sentinel or truncated file), treat as stale and replace. - Otherwise (valid JSON with openaiProviderTierVersion != 2, i.e. a real pre-migration v1 backup), throw OpenAiTierBackupCollisionError to avoid silently destroying the user rollback point. Two new unit tests cover both branches. The e2e collision fixture uses a non-JSON sentinel so collisionFailsBeforeSave stays false as before.
|
Addressed the policy question in the latest commit ( The previous heuristic treated any differing backup as stale and replaced it unconditionally. That is risky: a user who manually keeps The new heuristic in
The e2e collision fixture uses a non-JSON sentinel, so |
|
Reviewed the backup lifecycle and tests. This correctly distinguishes stale post-migration v2 backups from intentional pre-migration rollback snapshots, recreates stale backups through the hardened atomic path, and adds useful coverage. No external calls, process execution, dependency changes, or suspicious behavior found. Merging into dev. |
…idge-jun#258) * fix(config): replace stale pre-migration backup instead of crashing (issue lidge-jun#257) When ocx init writes a fresh config, the old .pre-openai-tiers-v2.bak from a previous installation becomes orphaned. The next ocx start would crash with OpenAiTierBackupCollisionError because the backup differs from the new config. Two layers of defense: 1) ocx init now deletes any stale backup after writing a fresh config. 2) backupConfigBeforeOpenAiTierMigration now replaces a stale backup with a warning instead of throwing, catching the same state through other paths (manual edits, partial upgrades). * fix(config): address Codex review comments on stale backup handling - Delete stale backup and fall through to atomic creation path instead of writing in-place, ensuring secrets are written to a hardened temp file before publication (addresses Codex comment about hardening before write) - Update e2e test expectation: collisionFailsBeforeSave is now false since stale backups are replaced instead of causing a crash - Update fixture to capture first migration warnings before collision test - Update unit test to expect 'created' instead of 'reused' for stale path * fix(router): improve error message when no OpenAI provider is configured Add actionable guidance to the error message: tell users to run 'ocx init' or check their config. The previous message was technical and didn't help users who hadn't configured a provider yet. * Revert "fix(router): improve error message when no OpenAI provider is configured" This reverts commit 7753409. * fix(config): distinguish stale from intentional pre-migration backups Address PR lidge-jun#258 owner policy question: silently replacing any differing backup treated a user-intentional rollback point as stale, which is destructive if the user manually created or edited the v2 backup. New heuristic in backupConfigBeforeOpenAiTierMigration: - Parse the existing backup as JSON. - If it has openaiProviderTierVersion === 2, it is a post-migration snapshot that became stale when config.json was rewritten (e.g. ocx init after a prior migration). Replace it. - If it is unparseable JSON (e.g. a test sentinel or truncated file), treat as stale and replace. - Otherwise (valid JSON with openaiProviderTierVersion != 2, i.e. a real pre-migration v1 backup), throw OpenAiTierBackupCollisionError to avoid silently destroying the user rollback point. Two new unit tests cover both branches. The e2e collision fixture uses a non-JSON sentinel so collisionFailsBeforeSave stays false as before.
Summary
Fixes #257.
When
ocx initwrites a freshconfig.json, the old.pre-openai-tiers-v2.bakfrom a previous installation becomes orphaned. The nextocx startcrashes withOpenAiTierBackupCollisionErrorbecause the backup differs from the new config.Root cause
The OpenAI tier startup migration creates a backup of the config before migrating it. On a fresh
ocx init, the old backup is a snapshot of a config that no longer exists. The collision check (sameBytes) sees the difference and throws, treating a stale backup as a genuine conflict.Fix (two layers)
Layer 1:
ocx initnow deletes any stale.pre-openai-tiers-v2.bakafter writing a fresh config. Init means "start fresh," so any rollback target from a previous config is orphaned.Layer 2:
backupConfigBeforeOpenAiTierMigrationnow replaces a stale backup with a warning instead of throwing. This catches the same state through other paths (manual config edits, partial upgrades, etc.). The EEXIST race-resolution path still throws on genuine concurrency conflicts.Changes
src/cli/init.ts: Delete stale backup after writing fresh configsrc/config.ts: Replace stale backup with warning instead of throwingtests/openai-provider-option-startup.test.ts: Update collision test to expect replacementVerification
bun run typecheck: clean