preserve storage path context for deferred saves#339
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. |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 11 minutes and 10 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ 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 |
preserve storage path context for deferred saves
Summary
What Changed
resolvePath()to honor the stored project root when it differs from the current process cwdValidation
npm run lintnpm run typechecknpm testnpm test -- test/documentation.test.tsnpm run buildnpx vitest run test/accounts.test.ts test/paths.test.tsDocs and Governance Checklist
docs/getting-started.mdupdated (if onboarding flow changed)docs/features.mdupdated (if capability surface changed)docs/reference/*pages updated (if commands/settings/paths changed)docs/upgrade.mdupdated (if migration behavior changed)SECURITY.mdandCONTRIBUTING.mdreviewed for alignmentRisk and Rollback
72a115eandcef0db1Additional Notes
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
this pr fixes a correctness bug where deferred (debounced) account saves could write to the wrong project's storage file after a cwd change. the fix captures the storage path context at
AccountManagerconstruction time and wrapssaveToDiskinAsyncLocalStorage.run()so each save executes against its own scoped project root — without touching the globalcurrentStorageStateand without the save-interleave race flagged in the prior review.key changes:
runWithStoragePathStateusesAsyncLocalStorage.run()(notenterWith), correctly scoping context per-call and restoring the ambient state when the callback resolves — this directly fixes the concurrent-save race from the prior reviewAccountManagercapturesstoragePathStateat construction via a shallow spread; safe because allStoragePathStatefields arestring | nullprimitivesresolvePathnow readscurrentProjectRootfrom the active ALS store (or global fallback), keeping the security gate aligned with the correct project scope during savestoBeCloseToreplacestoBeon floating-point health scores to deflake two time-sensitive tracker assertionsbeforeEach/afterEachstate resets added in both test files to prevent cross-test state bleednpm test(full suite) is unchecked in the validation checklist — recommend confirming before merge given the 80% coverage threshold and the security-gate change inresolvePathConfidence Score: 5/5
safe to merge — the concurrency race is correctly resolved using ALS scoping, all remaining findings are P2 quality suggestions
the prior P1 race (concurrent saves clobbering
currentStorageState) is properly addressed by switching toAsyncLocalStorage.run(). the shallow copy ofStoragePathStateis safe for all-primitive fields. theresolvePathchange is correct and scoped. remaining findings are a missing full test run (process gap, not a code defect) and a missing rejection test (coverage gap, not a broken gate). neither blocks merge.test/paths.test.ts— worth adding a rejection-path test;test/accounts.test.ts— fullnpm testrun should be confirmedImportant Files Changed
runWithStoragePathStateusingAsyncLocalStorage.run()— correctly scopes context per-call without touching the globalcurrentStorageState, resolving the prior save-interleave raceprocess.cwd()withgetStoragePathState().currentProjectRoot ?? process.cwd()in theresolvePathsecurity gate — correctly reads the ALS-scoped root inside arun()context and falls back toprocess.cwd()outside onebeforeEach/afterEachstate resets, two new focused save-context tests (deferred and concurrent), andtoBeCloseTofix for flaky health-score assertions; fullnpm testrun not confirmedbeforeEach/afterEachstate resets and an acceptance test forresolvePathunder an activecurrentProjectRoot; missing corresponding rejection test for paths outside the stored rootSequence Diagram
sequenceDiagram participant App participant AM_A as AccountManager(repo-a) participant AM_B as AccountManager(repo-b) participant ALS as AsyncLocalStorage participant Disk as withAccountStorageTransaction App->>AM_A: new AccountManager() [cwd=repo-a] Note over AM_A: storagePathState = {root: repo-a} App->>AM_B: new AccountManager() [cwd=repo-b] Note over AM_B: storagePathState = {root: repo-b} App->>AM_A: saveToDisk() AM_A->>ALS: run(stateA, fn) Note over ALS: context = repo-a (scoped) ALS->>Disk: withAccountStorageTransaction(...) Note over Disk: getStoragePathState() → repo-a ✓ App->>AM_B: saveToDisk() [concurrent] AM_B->>ALS: run(stateB, fn) Note over ALS: context = repo-b (separate scope) ALS->>Disk: withAccountStorageTransaction(...) Note over Disk: getStoragePathState() → repo-b ✓ Note over ALS: both run() scopes resolve independently,\nglobal currentStorageState never mutatedPrompt To Fix All With AI
Reviews (2): Last reviewed commit: "Fix storage path state save race" | Re-trigger Greptile