fix: stop logging settings.json contents from the git-fetch tick, and log an unreadable file once (release review)

The settings readers for git fetch and keep-warm no longer repeat V8's JSON.parse message, which
quotes the text around the fault and could print voiceSettings.apiKey. The 15 s scheduler tick now
logs an unreadable settings.json once, and again only after a successful read in between. Stale
comments that said settings.json is rewritten in place now say writes are atomic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-27 02:53:08 +01:00
1 parent 0f1fca6ea0
commit da740d4b00
4 files changed
+80 -14

No files matched your search

+16 -5
View File
@@ -45,8 +45,10 @@
* `DEFAULT_GIT_TIMEOUT_MS`): both settings are per device and never reach the server, so the server
* cannot know what a device chose.
* - A failure is reported, not retried harder: the folder keeps its schedule and gets its next run at its
* own interval. A settings read that fails skips this tick only, because settings.json is rewritten in
* place and a kept fallback would hold the feature off until the next settings change.
* own interval. A settings read that fails skips this tick only, rather than deciding from defaults.
* settings.json is replaced atomically, so such a failure is a file that does not parse (a hand edit) or
* a real read error, which lasts until someone fixes it: it is logged once, and again only after a read
* has succeeded in between, not every 15 s tick.
*
* @module git-fetch-scheduler
*/
@@ -130,6 +132,8 @@ export class GitFetchScheduler {
private readonly folderOf = new Map<string, string>();
private running = false;
private stopped = false;
/** The last settings read failed and was logged; cleared by the next read that succeeds. */
private settingsUnreadable = false;
constructor(ports: GitFetchPorts) {
this.ports = ports;
@@ -144,11 +148,18 @@ export class GitFetchScheduler {
try {
settings = await this.ports.readSettings();
} catch (err) {
// A read can land mid-write. Skipping this tick costs one interval; deciding from a fallback would
// hold the feature off until the next settings change.
this.ports.log?.(`git fetch: settings unreadable, tick skipped: ${getErrorMessage(err)}`);
// Writes are atomic, so this is a real read error or a file that does not parse (a hand edit), and it
// stays that way until it is fixed: logged once, not on every tick. The reader never puts the file's
// text in its error (readGitFetchSettings), since settings.json can hold an API key.
if (!this.settingsUnreadable) {
this.settingsUnreadable = true;
this.ports.log?.(
`git fetch: settings unreadable, ticks skipped until it reads again: ${getErrorMessage(err)}`
);
}
return 0;
}
this.settingsUnreadable = false;
// Pass 1 — who is on what, before anything is decided. Every session open on a folder is recorded here,
// not only the one that would get picked, so `remove()` can still see who is open on it when the session
+19 -5
View File
@@ -1171,16 +1171,17 @@ export async function readKeepWarmSettingsOrThrow(): Promise<KeepWarmSettings> {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return keepWarmSettingsFrom({});
throw err;
}
return keepWarmSettingsFrom(JSON.parse(text) as Record<string, unknown>);
return keepWarmSettingsFrom(parseSettingsText(text));
}
/**
* The Git fetch interval's app-wide default (`gitFetchEnabled`, absent = OFF) and its cap
* (`gitFetchIntervalSeconds`, seconds between runs). Read FRESH on every tick by the scheduler, so a live
* toggle takes effect on the next tick and turning it off actually stops the fetching. A missing file is
* the defaults — OFF — but any other read or parse failure rejects, for the same reason as
* {@link readKeepWarmSettingsOrThrow}: settings.json is rewritten in place, so a read can land mid-write,
* and a fallback kept from it would hold the feature off until the next settings change.
* the defaults (OFF), but any other read or parse failure rejects and the scheduler skips that tick rather
* than deciding from defaults. settings.json is replaced atomically (a temp file renamed into place, see
* settings-writer.ts), so such a failure is a real read error or a file that does not parse (a hand edit),
* never a write in progress, and the scheduler logs it once rather than every tick.
*/
export async function readGitFetchSettings(): Promise<GitFetchSettings> {
let text: string;
@@ -1190,7 +1191,20 @@ export async function readGitFetchSettings(): Promise<GitFetchSettings> {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return gitFetchSettingsFrom({});
throw err;
}
return gitFetchSettingsFrom(JSON.parse(text) as Record<string, unknown>);
return gitFetchSettingsFrom(parseSettingsText(text));
}
/**
* settings.json's text for the two readers above, which reject a file that does not parse. The parser's
* own message is never repeated, as in settings-writer.ts: V8 quotes the text around the fault, settings.json
* can hold an API key (`voiceSettings.apiKey`), and both callers log the error they get.
*/
function parseSettingsText(text: string): Record<string, unknown> {
try {
return JSON.parse(text) as Record<string, unknown>;
} catch {
throw new Error(`${SETTINGS_PATH} is not valid JSON`);
}
}
function keepWarmSettingsFrom(settings: Record<string, unknown>): KeepWarmSettings {