Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Important Review skippedAuto reviews are limited based on label configuration. 🚫 Review skipped — only excluded labels are configured. (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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. Comment |
Summary
exportAccountsis called from an active transaction after the storage path driftsValidation
npm exec vitest run test/storage.test.tsnpm run typechecknote: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
this pr hardens storage path transactions by pinning all load/save operations to the storage path captured at transaction start, rather than re-calling
getStoragePath()mid-transaction. it also clearsstate.activein afinallyblock so post-transaction exports always reload fresh state, and adds a fast-fail guard inexportAccountswhen called inside an active transaction whose storage path has drifted — with correct equivalence handling for windows case/slash normalization and symlink-resolved paths.changes:
loadAccountsInternalandsaveAccountsUnlockedaccept an optionalstoragePathparameter (defaults togetStoragePath()) so callers can pin the pathwithAccountStorageTransactionandwithAccountAndFlaggedStorageTransactioncapturestoragePath(andflaggedStoragePath) once at transaction start and thread them through all load/save/rollback callswithAccountAndFlaggedStorageTransactionnow also pinsgetFlaggedAccountsPath()at transaction start, so rollbacks target the correct flagged storage rootstate.active = falseinfinally, preventing stale snapshots from leaking into post-transaction exportsexportAccountsreplaces the silent wrong-path fallback with an explicit error on path drift; unchanged-path exports continue to use the in-transaction snapshotnormalizeStorageComparisonPath/areEquivalentStoragePathshelpers handle symlinks and windows path equivalencenormalizeStorageComparisonPathonly catchesENOENTfromfs.realpath— windowsEPERM/EACCES(antivirus locks) would surface as unexpected errors fromexportAccounts; worth catching those and falling back to the normalized inputwithAccountAndFlaggedStorageTransactionConfidence Score: 4/5
activeflag teardown viafinallyis solid; the fast-fail export guard eliminates a silent wrong-path data hazard; test coverage is extensive across the new behaviors including windows-style paths, symlinks, and rollback under EBUSY. single gap is the narrow ENOENT-only catch innormalizeStorageComparisonPathwhich is a p2 windows safety concern, not a blocking logic bug.lib/storage.tslines 393–402 —normalizeStorageComparisonPatherror catch should also coverEPERM/EACCESfor windows safetyImportant Files Changed
activeflag cleared infinally;exportAccountsfast-fails on path drift; newnormalizeStorageComparisonPathhandles symlinks and windows case/slash normalization correctly — one gap: onlyENOENTis caught in the realpath fallback, windowsEPERM/EACCESwould surface as unexpected errorsSequence Diagram
sequenceDiagram participant C as caller participant T as withAccountStorageTransaction participant L as loadAccountsInternal participant S as saveAccountsUnlocked participant E as exportAccounts participant ALS as AsyncLocalStorage C->>T: call handler T->>T: capture storagePath = getStoragePath() T->>L: load(persistMigration, storagePath) L-->>T: snapshot T->>ALS: run(state{snapshot, storagePath, active:true}, handler) ALS->>C: handler(current, persist) C->>S: persist(storage) → saveAccountsUnlocked(storage, storagePath) S-->>C: done note over C: path drift may occur here C->>E: exportAccounts(path) E->>ALS: getStore() → state alt paths differ E-->>C: throw "Export blocked by storage path mismatch" else paths equivalent E-->>C: export from state.snapshot end C-->>ALS: handler returns/throws ALS->>ALS: finally: state.active = false T-->>C: result or errorPrompt To Fix All With AI
Last reviewed commit: "fix: harden storage ..."