Summary
Follow-up to #1568. The core modifyJson() pattern adoption is complete, but two cleanup items remain.
Remaining Work
1. FileStorage.close() not being called
apps/cli/src/commands/export.command.ts instantiates FileStorage 9 times but never calls .close(), causing the Writer cache to grow unbounded.
Affected locations:
- Lines where
new FileStorage(...) is called without corresponding cleanup
Fix: Wrap FileStorage usage in try/finally to ensure close() is called, or refactor to use a shared instance that's properly managed.
2. Legacy utils.js read-outside-lock pattern
scripts/modules/utils.js writeJSON() function still receives data from outside the lock:
function writeJSON(filepath, data, projectRoot = null, tag = null) {
// 'data' was read OUTSIDE the lock by the caller
withFileLockSync(filepath, () => {
let finalData = data;
// ...
});
}
While it does re-read inside the lock for tag merging scenarios, the initial data parameter still comes from a potentially stale read.
Options:
- Migrate callers to use the TypeScript
modifyJson() pattern
- Add a
modifyJSON() function to utils.js that takes a modifier callback
- Document as acceptable risk if legacy code is being phased out
References
Summary
Follow-up to #1568. The core
modifyJson()pattern adoption is complete, but two cleanup items remain.Remaining Work
1. FileStorage.close() not being called
apps/cli/src/commands/export.command.tsinstantiates FileStorage 9 times but never calls.close(), causing the Writer cache to grow unbounded.Affected locations:
new FileStorage(...)is called without corresponding cleanupFix: Wrap FileStorage usage in try/finally to ensure
close()is called, or refactor to use a shared instance that's properly managed.2. Legacy utils.js read-outside-lock pattern
scripts/modules/utils.jswriteJSON()function still receives data from outside the lock:While it does re-read inside the lock for tag merging scenarios, the initial data parameter still comes from a potentially stale read.
Options:
modifyJson()patternmodifyJSON()function to utils.js that takes a modifier callbackReferences