fix: recreate live account sync on config changes#380
Conversation
Live account sync reused the same controller once created, even when its effective debounce/poll configuration changed. That leaves stale runtime state in place and keeps watching with outdated timing parameters. Track a live-sync config key and recreate the controller when the configuration changes, matching the refresh-guardian pattern.
|
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 20 minutes and 2 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 (7)
✨ 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 |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Superseded by #387, which rebuilds the full open PR stack onto one reviewed integration branch. |
|
Closing in favor of #387. |
Problem
Live account sync kept reusing the same controller once created, even when its effective debounce/poll configuration changed.
That leaves stale runtime state in place and continues watching with outdated timing parameters.
Fix
Track a live-sync config key and recreate the controller when its effective configuration changes.
This mirrors the existing refresh-guardian pattern and keeps runtime watcher state aligned with the current config.
Changes
lib/runtime/live-sync.tslib/runtime/runtime-services.tslib/runtime/live-sync-entry.tsindex.tsliveAccountSyncConfigKeyalongside the sync instance/pathtest/runtime-live-sync.test.tstest/runtime-services.test.tstest/live-sync-entry.test.tsValidation
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 adds config-key tracking to the live account sync system so the watcher is torn down and recreated whenever debounce/poll settings change, mirroring the existing refresh-guardian pattern. changes are clean and the overall approach is sound.
lib/runtime/live-sync.ts: new generic helper addscurrentConfigKey/configKeyparams, compares keys on entry, stops stale sync, and trackscleanupRegisteredto avoid duplicate handlerslib/runtime/runtime-services.ts: newensureLiveAccountSyncStatedelegates to the same pattern but does not trackcleanupRegistered—registerCleanupis called on every sync creation, including recreations triggered by config changeslib/runtime/live-sync-entry.ts: cleanly computesconfigKeyfrom debounce+poll and forwardscurrentConfigKeydown; return value now includesliveAccountSyncConfigKeyindex.ts: adds the module-levelliveAccountSyncConfigKeystate variable and threads it throughensureLiveAccountSyncEntrycorrectlylive-sync-entry.test.tsdoesn't assert on the newliveAccountSyncConfigKeyreturn value and the mock omits itConfidence Score: 3/5
mergeable with caution — the cleanup accumulation in runtime-services.ts is a real correctness divergence from the established pattern
the core logic in live-sync.ts and the wiring in index.ts/live-sync-entry.ts are correct and well-tested. the missing cleanupRegistered guard in runtime-services.ts is a meaningful gap that will silently accumulate handlers across config changes and is inconsistent with the sibling implementation. the missing test coverage in live-sync-entry.test.ts means the new config-key threading is unverified at that layer. neither issue is blocking at normal usage volumes, but both are worth fixing before merge.
lib/runtime/runtime-services.ts (missing cleanupRegistered guard) and test/live-sync-entry.test.ts (missing mock field and assertion)
Important Files Changed
Sequence Diagram
sequenceDiagram participant I as index.ts participant E as live-sync-entry.ts participant S as runtime-services.ts participant Sync as LiveAccountSync note over I,Sync: initial call — configKey=25:250 I->>E: ensureLiveAccountSyncEntry(currentConfigKey=null) E->>E: compute configKey="25:250" E->>S: ensureLiveAccountSyncState(currentConfigKey=null, configKey="25:250") S->>Sync: createSync() → sync1 S->>S: registerCleanup(sync1.stop) ✓ S->>Sync: sync1.syncToPath(targetPath) S-->>E: {liveAccountSync: sync1, configKey: "25:250"} E-->>I: {liveAccountSync: sync1, liveAccountSyncConfigKey: "25:250"} I->>I: liveAccountSyncConfigKey = "25:250" note over I,Sync: config change — debounce/poll updated I->>E: ensureLiveAccountSyncEntry(currentConfigKey="25:250") E->>E: compute configKey="50:500" E->>S: ensureLiveAccountSyncState(currentConfigKey="25:250", configKey="50:500") S->>Sync: sync1.stop() [key mismatch] S->>Sync: createSync() → sync2 S->>S: registerCleanup(sync2.stop) ⚠ no guard — extra handler registered S->>Sync: sync2.syncToPath(targetPath) S-->>E: {liveAccountSync: sync2, configKey: "50:500"} E-->>I: {liveAccountSync: sync2, liveAccountSyncConfigKey: "50:500"} I->>I: liveAccountSyncConfigKey = "50:500"Comments Outside Diff (1)
lib/runtime/runtime-services.ts, line 66-72 (link)no
cleanupRegisteredguard here. every time the config key changes and a new sync is created, another closure is pushed into the cleanup registry. the siblinglive-sync.ts(lines 95-101) was written with an explicitcleanupRegisteredflag +getCurrentSync()indirection precisely to prevent this.each extra closure captures its own local
liveAccountSyncbinding, so it won't double-stop the current sync — but it will call.stop()on the already-stopped previous sync, which is only safe ifstop()is idempotent. more importantly, after N config changes the registry holds N cleanup handlers. on windows, antivirus-induced re-entrant fs locks during a flurry of config reloads could trigger multiple concurrent stop/recreate cycles, each registering another handler.mirror the pattern from
live-sync.ts:or accept/return a
cleanupRegisteredboolean in the params/return type so callers can track and pass it back on the next invocation — exactly howlive-sync.tshandles it.Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: recreate live account sync on confi..." | Re-trigger Greptile