mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 16:25:30 +00:00
fix(skill-tracker): serialize append and retention across processes
This commit is contained in:
1 parent
8abdf329ec
commit
f2d23ded28
5 files changed
+185
-9
No files matched your search
@@ -4,7 +4,8 @@ const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const { ensureDir } = require('../utils');
|
||||
const { ensureDir, log } = require('../utils');
|
||||
const { acquireSettingsLock } = require('../install/claude-settings-lock');
|
||||
|
||||
const VALID_OUTCOMES = new Set(['success', 'failure', 'partial']);
|
||||
const VALID_FEEDBACK = new Set(['accepted', 'corrected', 'rejected']);
|
||||
@@ -131,15 +132,29 @@ function appendRunRecord(runsFilePath, record, options = {}) {
|
||||
: MAX_RUN_RECORDS;
|
||||
|
||||
ensureDir(path.dirname(runsFilePath));
|
||||
fs.appendFileSync(runsFilePath, `${JSON.stringify(record)}\n`, { encoding: 'utf8', mode: RUNS_FILE_MODE });
|
||||
|
||||
// Append and retention must share one critical section. Otherwise a pruner
|
||||
// can overwrite a run another process appended after its read snapshot.
|
||||
const release = acquireSettingsLock(runsFilePath, {
|
||||
label: 'skill run history', timeoutMs: options.lockTimeoutMs ?? 5000,
|
||||
});
|
||||
try {
|
||||
fs.chmodSync(runsFilePath, RUNS_FILE_MODE);
|
||||
} catch {
|
||||
// Windows and some mounts do not support POSIX modes; the record still lands.
|
||||
}
|
||||
fs.appendFileSync(runsFilePath, `${JSON.stringify(record)}\n`, { encoding: 'utf8', mode: RUNS_FILE_MODE });
|
||||
|
||||
pruneRunRecords(runsFilePath, maxRecords);
|
||||
try {
|
||||
fs.chmodSync(runsFilePath, RUNS_FILE_MODE);
|
||||
} catch {
|
||||
// Windows and some mounts do not support POSIX modes; the record still lands.
|
||||
}
|
||||
|
||||
pruneRunRecords(runsFilePath, maxRecords);
|
||||
} finally {
|
||||
try {
|
||||
release();
|
||||
} catch (error) {
|
||||
// Preserve the append result or its original error if cleanup fails.
|
||||
log(`[SkillTracker] Error releasing run history lock: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep only the newest `maxRecords` lines. Rewrites the whole file, which is
|
||||
|
||||
Reference in new issue
Block a user