From 1efe21f430694438d0782d87567b1fab74d64a96 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:07:41 +0100 Subject: [PATCH 1/2] settings: Duration fields from one list; a bad saved interval falls back to its default (#45 #46) Every interval (Duration) setting is found by walking the settings schema (packages/shared/src/forkSettingsIntervals.ts). A test checks each one survives upstream's patch merge and its save and load, so a Duration missing from a hand-kept list fails CI. A save refuses an interval that is negative, not finite (JSON writes it as null) or too large; a settings file holding one loads with that interval at its default and a warning instead of failing whole. Co-Authored-By: Claude Opus 5.5 --- .github/fork-seams.json | 4 +- .../src/fork/serverSettingsWriteCheck.ts | 2 +- apps/server/src/fork/settingsFileRead.ts | 23 ++ .../src/serverSettings.forkIntervals.test.ts | 247 ++++++++++++++++++ apps/server/src/serverSettings.ts | 3 +- docs/fork/updates.md | 8 +- packages/shared/src/forkSettingsIntervals.ts | 140 ++++++++++ packages/shared/src/forkSettingsPatch.ts | 12 +- 8 files changed, 434 insertions(+), 5 deletions(-) create mode 100644 apps/server/src/fork/settingsFileRead.ts create mode 100644 apps/server/src/serverSettings.forkIntervals.test.ts create mode 100644 packages/shared/src/forkSettingsIntervals.ts diff --git a/.github/fork-seams.json b/.github/fork-seams.json index 7153bddbf2fbf..0e860c1296057 100644 --- a/.github/fork-seams.json +++ b/.github/fork-seams.json @@ -31,11 +31,13 @@ ] }, "apps/server/src/serverSettings.ts": { - "why": "Every settings write goes through upstream's patch and write paths here. The fork swaps in its patch (fork/serverSettingsPatch.ts, under upstream's name, so a project's MCP profile a client left out is kept) and calls its save check (fork/serverSettingsWriteCheck.ts) once in each write path.", + "why": "Every settings write goes through upstream's patch and write paths here. The fork swaps in its patch (fork/serverSettingsPatch.ts, under upstream's name, so a project's MCP profile a client left out is kept) and calls its save check (fork/serverSettingsWriteCheck.ts) once in each write path. The load decodes the file after fork/settingsFileRead.ts (old auto-update names renamed, an unusable interval left out so it reads as its default).", "added": [ "// Fork: upstream's patch keeping a project's MCP profile a client left out, and the save check.", "import { applyServerSettingsPatchKeepingForkProjectKeys as applyServerSettingsPatch } from \"./fork/serverSettingsPatch.ts\";", "import * as ForkSettingsWrite from \"./fork/serverSettingsWriteCheck.ts\";", + "import { prepareSettingsFile } from \"./fork/settingsFileRead.ts\"; // Fork: renames, bad intervals", + ": decodePersistedServerSettingsExit(withDefaults(prepareSettingsFile(parsed.value)));", "Effect.flatMap(ForkSettingsWrite.withCheck(update, \"test settings\")), // Fork: save check", "yield* ForkSettingsWrite.check(current, updated, settingsPath); // Fork: save check" ] diff --git a/apps/server/src/fork/serverSettingsWriteCheck.ts b/apps/server/src/fork/serverSettingsWriteCheck.ts index 026593671960c..23809e97d53c9 100644 --- a/apps/server/src/fork/serverSettingsWriteCheck.ts +++ b/apps/server/src/fork/serverSettingsWriteCheck.ts @@ -12,7 +12,7 @@ import { import * as HostProcess from "@t3tools/shared/HostProcess"; import { Effect } from "effect"; -/** Fails when saving `next` over `current` would bring in a fork setting that cannot apply. */ +/** Fails when saving `next` over `current` would bring in a fork setting or interval that cannot apply. */ export function check( current: ServerSettings, next: ServerSettings, diff --git a/apps/server/src/fork/settingsFileRead.ts b/apps/server/src/fork/settingsFileRead.ts new file mode 100644 index 0000000000000..b5c9db0a5ad57 --- /dev/null +++ b/apps/server/src/fork/settingsFileRead.ts @@ -0,0 +1,23 @@ +/** + * Fork: the parsed settings file before upstream's decode: old auto-update names renamed, and an + * unusable interval left out with a warning, so it reads as its default instead of failing the + * whole file (which resets every setting). The next save removes it from the file. + */ +import { dropUnusableStoredIntervals } from "@t3tools/shared/forkSettingsPatch"; +import * as Effect from "effect/Effect"; + +import { renameRetiredAutoUpdateKeys } from "../cloud/autoUpdateSettings.ts"; + +export function prepareSettingsFile(parsed: unknown): unknown { + const { settings, dropped } = dropUnusableStoredIntervals(renameRetiredAutoUpdateKeys(parsed)); + if (dropped.length > 0) { + // The decode is synchronous; its own warnings (wait checks) are logged the same way. + Effect.runSync( + Effect.logWarning( + "settings: unusable intervals in settings.json read as their defaults; the next settings save removes them from the file", + { dropped }, + ), + ); + } + return settings; +} diff --git a/apps/server/src/serverSettings.forkIntervals.test.ts b/apps/server/src/serverSettings.forkIntervals.test.ts new file mode 100644 index 0000000000000..2ba707184e731 --- /dev/null +++ b/apps/server/src/serverSettings.forkIntervals.test.ts @@ -0,0 +1,247 @@ +// Fork: interval (Duration) settings. Every one, found by walking the settings schema, survives a +// patch and a save and load (#45: upstream's patch merge and save each list them by hand). A save +// refuses an interval no run could use, and a file that holds one loads with that interval at its +// default instead of failing whole (#46). + +import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; +import * as NodeServices from "@effect/platform-node/NodeServices"; +import { + DEFAULT_SERVER_SETTINGS, + ServerSettings, + ServerSettingsError, + ServerSettingsPatch, +} from "@t3tools/contracts"; +import { + findDurationPaths, + ForkSettingsWriteError, + SETTINGS_INTERVAL_PATHS, +} from "@t3tools/shared/forkSettingsPatch"; +import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings"; +import { assert, it } from "@effect/vitest"; +import * as Duration from "effect/Duration"; +import * as Effect from "effect/Effect"; +import * as Exit from "effect/Exit"; +import * as FileSystem from "effect/FileSystem"; +import * as Layer from "effect/Layer"; +import * as Schema from "effect/Schema"; + +import * as ServerSecretStore from "./auth/ServerSecretStore.ts"; +import * as ServerConfig from "./config.ts"; +import * as SqlitePersistence from "./persistence/Sqlite.ts"; +import * as ManagedPolicy from "./policy/ManagedPolicy.ts"; +import * as ServerSettingsModule from "./serverSettings.ts"; + +const layerServerSettings = () => + ServerSettingsModule.layer.pipe( + Layer.provide(ServerSecretStore.layer), + Layer.provide(ManagedPolicy.layerTest()), + Layer.provideMerge(Layer.fresh(SqlitePersistence.layerMemory)), + Layer.provideMerge( + Layer.fresh(ServerConfig.layerTest(process.cwd(), { prefix: "t3code-fork-intervals-test-" })), + ), + ); + +const isRecord = (value: unknown): value is Record => + typeof value === "object" && value !== null && !Array.isArray(value); + +const getPath = (value: unknown, path: ReadonlyArray): unknown => + path.reduce((node, key) => (isRecord(node) ? node[key] : undefined), value); + +const setPath = (value: unknown, path: ReadonlyArray, leaf: unknown): unknown => { + const [key, ...rest] = path; + if (key === undefined) return leaf; + const node = isRecord(value) ? value : {}; + return { ...node, [key]: setPath(node[key], rest, leaf) }; +}; + +const millisAt = (settings: ServerSettings, path: ReadonlyArray): number | undefined => { + const value = getPath(settings, path); + return Duration.isDuration(value) ? Duration.toMillis(value) : undefined; +}; + +/** What else a patch needs for an interval under this top key to apply. */ +const PATCH_CONTEXT: Readonly> = { + // Overrides apply only to a custom profile. + backgroundActivity: { profile: "custom" }, +}; + +/** A patch, as a client sends it, that sets the interval at `path` to `millis`. */ +const decodePatch = Schema.decodeUnknownSync(ServerSettingsPatch); + +const patchSetting = (path: ReadonlyArray, millis: number): ServerSettingsPatch => + decodePatch(setPath({ [path[0]!]: PATCH_CONTEXT[path[0]!] }, path, millis)); + +const readFileText = Effect.gen(function* () { + const config = yield* ServerConfig.ServerConfig; + const fs = yield* FileSystem.FileSystem; + return yield* fs.readFileString(config.settingsPath); +}); + +const writeFileText = (text: string) => + Effect.gen(function* () { + const config = yield* ServerConfig.ServerConfig; + const fs = yield* FileSystem.FileSystem; + yield* fs.writeFileString(config.settingsPath, text); + }); + +const decodeFile = (text: string): ServerSettings => { + const decoded = ServerSettingsModule.decodeSettingsFileText(text); + if (Exit.isFailure(decoded)) assert.fail(`the file does not decode: ${text}`); + return decoded.value; +}; + +const SET_MILLIS = 123_456; +const pathName = (path: ReadonlyArray) => path.join("."); + +it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))( + "interval settings found from the schema (#45)", + (it) => { + it("finds every interval, each at a key path", () => { + const { paths, outOfReach } = findDurationPaths(ServerSettings); + // An interval inside a record or array has no fixed path for the checks below to follow. + assert.deepStrictEqual(outOfReach, []); + for (const known of [ + "automaticGitFetchInterval", + "providerHealthRefreshInterval", + "backgroundActivity.overrides.hostPowerMonitorIdleInterval", + "headlessUsageRefreshInterval", + ]) { + assert.include(paths.map(pathName), known); + } + // No default is the value set below, so each check sees a change. + for (const path of paths) + assert.notStrictEqual(millisAt(DEFAULT_SERVER_SETTINGS, path), SET_MILLIS); + }); + + it.each(SETTINGS_INTERVAL_PATHS.map((path) => ({ name: pathName(path), path })))( + "keeps $name through a patch", + ({ path }) => { + const patched = applyServerSettingsPatch( + DEFAULT_SERVER_SETTINGS, + patchSetting(path, SET_MILLIS), + ); + assert.strictEqual(millisAt(patched, path), SET_MILLIS); + }, + ); + + it.effect.each(SETTINGS_INTERVAL_PATHS.map((path) => ({ name: pathName(path), path })))( + "keeps $name through a save and the next load", + ({ path }) => + Effect.gen(function* () { + yield* writeFileText("{}"); + const service = yield* ServerSettingsModule.ServerSettingsService; + const saved = yield* service.updateSettings(patchSetting(path, SET_MILLIS)); + assert.strictEqual(millisAt(saved, path), SET_MILLIS); + const text = yield* readFileText; + assert.strictEqual(getPath(JSON.parse(text), path), SET_MILLIS); + assert.strictEqual(millisAt(decodeFile(text), path), SET_MILLIS); + }).pipe(Effect.provide(layerServerSettings())), + ); + }, +); + +it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))( + "an interval no run could use (#46)", + (it) => { + const REFUSED = [ + // A client's JSON can say 1e400, which parses as Infinity and would be saved as null. + { + name: "1e400", + path: ["providerHealthRefreshInterval"], + millis: JSON.parse("1e400") as number, + }, + { name: "a negative value", path: ["headlessUsageRefreshInterval"], millis: -5 }, + { + name: "a value past the largest", + path: ["backgroundActivity", "overrides", "hostPowerMonitorActiveInterval"], + millis: 1e300, + }, + ]; + + it.effect.each(REFUSED)( + "refuses a save of $name and leaves the file as it was", + ({ path, millis }) => + Effect.gen(function* () { + yield* writeFileText('{"enableAgentBrowserAccess": false}'); + const service = yield* ServerSettingsModule.ServerSettingsService; + yield* service.getSettings; + const patch = patchSetting(path, millis); + const failure = yield* Effect.flip(service.updateSettings(patch)); + assert.instanceOf(failure, ServerSettingsError); + assert.instanceOf(failure.cause, ForkSettingsWriteError); + assert.include((failure.cause as ForkSettingsWriteError).problem, pathName(path)); + assert.strictEqual(yield* readFileText, '{"enableAgentBrowserAccess": false}'); + }).pipe(Effect.provide(layerServerSettings())), + ); + + // As a hand edit or an older server's save of 1e400 leaves it. + const BAD_FILE = `{ + "enableAgentBrowserAccess": false, + "automaticGitFetchInterval": null, + "headlessUsageRefreshInterval": "10m", + "backgroundActivity": { + "profile": "custom", + "overrides": { + "providerHealthRefreshInterval": 90000, + "hostPowerMonitorActiveInterval": -5, + "hostPowerMonitorIdleInterval": 1e400 + } + } + }`; + + it.effect( + "loads a file holding bad intervals with those at their defaults and the rest kept", + () => + Effect.gen(function* () { + yield* writeFileText(BAD_FILE); + const service = yield* ServerSettingsModule.ServerSettingsService; + const loaded = yield* service.getSettings; + // The rest of the file is read, not reset to every default. + assert.strictEqual(loaded.enableAgentBrowserAccess, false); + assert.strictEqual( + millisAt(loaded, ["backgroundActivity", "overrides", "providerHealthRefreshInterval"]), + 90_000, + ); + for (const path of [ + ["headlessUsageRefreshInterval"], + ["backgroundActivity", "overrides", "hostPowerMonitorActiveInterval"], + ["backgroundActivity", "overrides", "hostPowerMonitorIdleInterval"], + ]) { + assert.strictEqual( + millisAt(loaded, path), + millisAt(DEFAULT_SERVER_SETTINGS, path), + pathName(path), + ); + } + + // Loaded again before any save (a start that stopped before saving): the same result. + assert.deepStrictEqual(decodeFile(BAD_FILE), decodeFile(BAD_FILE)); + assert.strictEqual(decodeFile(BAD_FILE).enableAgentBrowserAccess, false); + + // A save is not refused, and leaves a file with no bad interval that loads as it was saved. + yield* service.updateSettings({ enableAgentBrowserAccess: true }); + const text = yield* readFileText; + const file = JSON.parse(text) as unknown; + assert.notInclude(text, "null"); + assert.isUndefined(getPath(file, ["headlessUsageRefreshInterval"])); + assert.isUndefined( + getPath(file, ["backgroundActivity", "overrides", "hostPowerMonitorIdleInterval"]), + ); + assert.strictEqual( + getPath(file, ["backgroundActivity", "overrides", "providerHealthRefreshInterval"]), + 90_000, + ); + const reloaded = decodeFile(text); + assert.strictEqual(reloaded.enableAgentBrowserAccess, true); + assert.strictEqual( + millisAt(reloaded, [ + "backgroundActivity", + "overrides", + "providerHealthRefreshInterval", + ]), + 90_000, + ); + }).pipe(Effect.provide(layerServerSettings())), + ); + }, +); diff --git a/apps/server/src/serverSettings.ts b/apps/server/src/serverSettings.ts index ac042a2305b49..02c2e810f6936 100644 --- a/apps/server/src/serverSettings.ts +++ b/apps/server/src/serverSettings.ts @@ -49,6 +49,7 @@ import * as ServerConfig from "./config.ts"; import { type DeepPartial, deepMerge } from "@t3tools/shared/Struct"; import { fromJsonStringPretty, fromLenientJson } from "@t3tools/shared/schemaJson"; import { renameRetiredAutoUpdateKeys } from "./cloud/autoUpdateSettings.ts"; +import { prepareSettingsFile } from "./fork/settingsFileRead.ts"; // Fork: renames, bad intervals import { deriveLegacyProjectOverrides, fallbackTextGenerationModelSelection, @@ -403,7 +404,7 @@ export function decodeSettingsFileText( const parsed = decodeSettingsFileJsonExit(raw); return Exit.isFailure(parsed) ? parsed - : decodePersistedServerSettingsExit(withDefaults(renameRetiredAutoUpdateKeys(parsed.value))); + : decodePersistedServerSettingsExit(withDefaults(prepareSettingsFile(parsed.value))); } /** The load's lenient parse of a settings file's text (comments, trailing commas), before decoding. */ diff --git a/docs/fork/updates.md b/docs/fork/updates.md index bc32839597fbf..688d4a3a191d5 100644 --- a/docs/fork/updates.md +++ b/docs/fork/updates.md @@ -32,6 +32,12 @@ watches; it changes nothing on the machine, and `0` turns it off. field reaches upstream's structs unchanged (an upstream key of the same name would hide it), that every fork setting has a patch field and a patch rule, and pins the count of fork lines in `settings.ts`; `forkSettingsPatch.test.ts` pins them in `packages/shared/src/serverSettings.ts`. +- [`serverSettings.forkIntervals.test.ts`](../../apps/server/src/serverSettings.forkIntervals.test.ts) + finds every interval (Duration) setting by walking the settings schema, the fork's and upstream's, + and fails when one does not survive a patch or a save and load: upstream's patch merge and its + `ATOMIC_SETTINGS_KEYS` list each interval by hand, and a missed one is saved as a broken object. + The same schema walk ([`forkSettingsIntervals.ts`](../../packages/shared/src/forkSettingsIntervals.ts)) + makes a save refuse an interval no run could use and a load read one as its default. - The seam check ([`fork-seam-check.cjs`](../../.github/scripts/fork-seam-check.cjs)) refuses any line the fork adds to an upstream file beyond the seam lines pinned in [`.github/fork-seams.json`](../../.github/fork-seams.json), with or without a comment. It runs on @@ -91,7 +97,7 @@ change, or a fork line beyond the seams, it stops and opens one issue. Then: fork's own file (a setting into `forkSettings.ts`); a changed seam line is fixed in `.github/fork-seams.json`. 3. Run the pin tests before pushing: - `vp test run packages/contracts/src/forkDefaults.test.ts packages/contracts/src/forkSettings.test.ts packages/shared/src/forkSettingsPatch.test.ts apps/server/src/serverSettings.forkDefaults.test.ts apps/server/src/serverSettings.forkSettings.test.ts apps/server/src/cloud/autoUpdateSettings.test.ts apps/server/src/cloud/autoUpdate.test.ts`. + `vp test run packages/contracts/src/forkDefaults.test.ts packages/contracts/src/forkSettings.test.ts packages/shared/src/forkSettingsPatch.test.ts apps/server/src/serverSettings.forkDefaults.test.ts apps/server/src/serverSettings.forkSettings.test.ts apps/server/src/serverSettings.forkIntervals.test.ts apps/server/src/cloud/autoUpdateSettings.test.ts apps/server/src/cloud/autoUpdate.test.ts`. 4. Push with `--force-with-lease` and start fork-follow once, as its report says. ### The sync that brings upstream's updater diff --git a/packages/shared/src/forkSettingsIntervals.ts b/packages/shared/src/forkSettingsIntervals.ts new file mode 100644 index 0000000000000..0c718ce72205a --- /dev/null +++ b/packages/shared/src/forkSettingsIntervals.ts @@ -0,0 +1,140 @@ +/** + * Fork: every interval (Duration) in the server settings, found by walking the settings schema, so + * a new one, the fork's or upstream's, is covered without being listed anywhere. A save refuses an + * interval no run could use, and a settings file that holds one loads with that one interval at its + * default instead of failing whole (a failed decode resets every setting). + */ +import { ServerSettings } from "@t3tools/contracts"; +import * as Duration from "effect/Duration"; +import * as Schema from "effect/Schema"; +import * as SchemaAST from "effect/SchemaAST"; + +/** Largest interval a setting takes, in milliseconds: beyond it a millisecond count is not exact. */ +const MAX_SETTINGS_INTERVAL_MILLIS = Number.MAX_SAFE_INTEGER; + +/** True for a millisecond count an interval setting can hold and the settings file can save. */ +const isUsableIntervalMillis = (millis: number): boolean => + Number.isFinite(millis) && millis >= 0 && millis <= MAX_SETTINGS_INTERVAL_MILLIS; + +const isDuration = (ast: SchemaAST.AST): boolean => + ast._tag === "Declaration" && ast.run === Schema.Duration.ast.run; + +/** + * Every Duration in `schema`'s decoded type: `paths` by key from the top, and `outOfReach` for one + * inside a record, an array or a declaration, where no fixed key path leads (written with `*`). + */ +export function findDurationPaths(schema: Schema.Top): { + readonly paths: ReadonlyArray>; + readonly outOfReach: ReadonlyArray; +} { + const paths: Array> = []; + const outOfReach: Array = []; + const found = new Set(); + const suspended = new Set(); + const walk = (node: SchemaAST.AST, path: ReadonlyArray, reachable: boolean): void => { + const ast = SchemaAST.toType(node); + if (isDuration(ast)) { + const name = path.join("."); + if (found.has(name)) return; + found.add(name); + if (reachable) paths.push(path); + else outOfReach.push(name); + return; + } + switch (ast._tag) { + case "Objects": + for (const property of ast.propertySignatures) { + walk(property.type, [...path, String(property.name)], reachable); + } + for (const index of ast.indexSignatures) walk(index.type, [...path, "*"], false); + return; + case "Union": + // A member that is an object still has keys: an interval in it has the same path. + for (const member of ast.types) walk(member, path, reachable); + return; + case "Arrays": + for (const element of [...ast.elements, ...ast.rest]) walk(element, [...path, "*"], false); + return; + case "Declaration": + for (const parameter of ast.typeParameters) walk(parameter, [...path, "*"], false); + return; + case "Suspend": + // A recursive schema: once is enough to find a Duration in it. + if (suspended.has(ast)) return; + suspended.add(ast); + walk(ast.thunk(), [...path, "*"], false); + return; + default: + return; + } + }; + walk(schema.ast, [], true); + return { paths, outOfReach }; +} + +/** Every interval setting's path, from the server settings schema. */ +export const SETTINGS_INTERVAL_PATHS = findDurationPaths(ServerSettings).paths; + +const isRecord = (value: unknown): value is Readonly> => + typeof value === "object" && value !== null && !Array.isArray(value); + +const getPath = (value: unknown, path: ReadonlyArray): unknown => + path.reduce((node, key) => (isRecord(node) ? node[key] : undefined), value); + +const intervalMillis = (value: unknown): number | undefined => + Duration.isDuration(value) ? Duration.toMillis(value) : undefined; + +/** + * Why a save of `next` must be refused for an interval, or `undefined`: an interval the save sets + * that is negative, not finite (a file cannot hold it: JSON writes it as `null`) or too large. One + * the save leaves as it was is never refused, so it cannot block saving anything else. + */ +export function settingsIntervalProblem( + current: ServerSettings, + next: ServerSettings, +): string | undefined { + for (const path of SETTINGS_INTERVAL_PATHS) { + const millis = intervalMillis(getPath(next, path)); + if (millis === undefined || isUsableIntervalMillis(millis)) continue; + if (Object.is(millis, intervalMillis(getPath(current, path)))) continue; + return `${path.join(".")} must be from 0 to ${MAX_SETTINGS_INTERVAL_MILLIS} milliseconds, not ${millis}: pick a smaller interval (0 turns it off where the setting allows).`; + } + return undefined; +} + +/** + * The parsed settings file with each interval it holds that no run could use (not a number, `null`, + * negative, not finite or too large) left out, so that one setting decodes as its default and the + * rest load; `dropped` names each one with what the file held. A path through a non-object is left + * to the decode. + */ +export function dropUnusableStoredIntervals(parsed: unknown): { + readonly settings: unknown; + readonly dropped: ReadonlyArray; +} { + let settings = parsed; + const dropped: Array = []; + for (const path of SETTINGS_INTERVAL_PATHS) { + const parent = getPath(settings, path.slice(0, -1)); + const key = path.at(-1); + if (key === undefined || !isRecord(parent) || !Object.hasOwn(parent, key)) continue; + const value = parent[key]; + if (typeof value === "number" && isUsableIntervalMillis(value)) continue; + dropped.push( + `${path.join(".")} (${typeof value === "number" ? String(value) : (JSON.stringify(value) ?? typeof value)})`, + ); + settings = withoutPath(settings, path); + } + return { settings, dropped }; +} + +/** A copy of `value` without the key at `path`; each object on the way is copied, not changed. */ +function withoutPath(value: unknown, path: ReadonlyArray): unknown { + const [key, ...rest] = path; + if (key === undefined || !isRecord(value)) return value; + if (rest.length === 0) { + const { [key]: _removed, ...kept } = value; + return kept; + } + return { ...value, [key]: withoutPath(value[key], rest) }; +} diff --git a/packages/shared/src/forkSettingsPatch.ts b/packages/shared/src/forkSettingsPatch.ts index 8ff459f21c158..67d3dfd3821b6 100644 --- a/packages/shared/src/forkSettingsPatch.ts +++ b/packages/shared/src/forkSettingsPatch.ts @@ -21,6 +21,14 @@ import { } from "@t3tools/contracts"; import * as Schema from "effect/Schema"; +import { settingsIntervalProblem } from "./forkSettingsIntervals.ts"; + +export { + dropUnusableStoredIntervals, + findDurationPaths, + SETTINGS_INTERVAL_PATHS, +} from "./forkSettingsIntervals.ts"; + const FORK_PATCH_KEYS = Object.keys(FORK_PATCH_RULES) as ReadonlyArray; export type ForkSettingsPatch = Pick; @@ -264,7 +272,8 @@ function mcpProfileRefProblem( } /** - * Why the server must refuse this save of fork settings, or `undefined`. Checks `next` (the + * Why the server must refuse this save of fork settings or of an interval (any setting's, see + * forkSettingsIntervals.ts), or `undefined`. Checks `next` (the * settings after the patch) against `current`, so it also sees a project's or thread's value that * a client sent back unchanged. Deleting a profile still in use is not refused yet (a later PR). */ @@ -273,6 +282,7 @@ export function forkSettingsWriteProblem( next: ServerSettings, ): string | undefined { const problems: Array = [ + settingsIntervalProblem(current, next), maxEntriesProblem(current, next), mcpProfileRefProblem(next, "mcpProfile", next.mcpProfile, current.mcpProfile, false), mcpProfileRefProblem( From 23eed84354bf8cd89a31b68e313077e26b87af39 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:12:00 +0100 Subject: [PATCH 2/2] docs: FORK_CHANGES row for the interval settings fix (#323) Co-Authored-By: Claude Opus 5.5 --- FORK_CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/FORK_CHANGES.md b/FORK_CHANGES.md index 4301918f56508..defd82467f679 100644 --- a/FORK_CHANGES.md +++ b/FORK_CHANGES.md @@ -36,6 +36,7 @@ is missing here or a setting named here does not exist. | Playtest mode, part 3: the worker renews claims, ends idle, too-long and gone-thread sessions, finishes what a restart cut, and tells the thread once when T3 ended a session. | A person tries an agent's unfinished work on a test target, round after round, no PR per round. | `server.playtest`, `projectOverride.playtest` | off | [#262](https://github.com/scuttletoby/t3code/pull/262) | | Handoff instead of compaction, part 1: the setting and the pure "should this thread hand off now?" decision. Nothing acts on it yet. | Long threads keep their children, PRs and waits instead of compacting. | `server.handoff`, `projectOverride.handoff` | off | [#282](https://github.com/scuttletoby/t3code/pull/282) | | Review rules, part 1: the setting for how this machine runs a review lens (runner, state question), off by default; `{"preset": "recommended"}` turns the fork's defaults on. A bad hand edit reads as off and is kept. Nothing reads it yet. | The repo says what a pull request needs and CI enforces it; the machine says how reviews run. | `server.reviewRules`, `projectOverride.reviewRules` | off | [#291](https://github.com/scuttletoby/t3code/pull/291) | +| An interval setting the settings file cannot hold (negative, not finite, too large) is refused when saved; one already in the file reads as its default instead of resetting every setting. A test finds every interval setting from the schema. | A `1e400` saved as `null` made the next start reject the whole settings file. | none | always | [#323](https://github.com/scuttletoby/t3code/pull/323) | ## Repository, CI and releases