From 8bae4ebaf62acb5966dddea74a543d2238ae2f1c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 17:21:31 +0000 Subject: [PATCH 1/4] test(server): project updates on folded settings reach new threads Failing reproduction for #14991: on a folded install, scripts and defaultThreadEnvMode saved through ProjectService.update never reach the resolvers launch and the UI read. AI-assisted; verified with the tests and tools listed above. --- .../server/src/project/ProjectService.test.ts | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/server/src/project/ProjectService.test.ts b/apps/server/src/project/ProjectService.test.ts index 1517bed31ba23..9f39a4311f0cf 100644 --- a/apps/server/src/project/ProjectService.test.ts +++ b/apps/server/src/project/ProjectService.test.ts @@ -35,6 +35,8 @@ import * as WorkspacePaths from "../workspace/WorkspacePaths.ts"; import * as ProjectEnrichmentService from "./ProjectEnrichmentService.ts"; import * as ProjectFaviconResolver from "./ProjectFaviconResolver.ts"; import * as ProjectService from "./ProjectService.ts"; +import { resolveProjectScripts } from "@t3tools/shared/projectScripts"; +import { resolveProjectSettings } from "@t3tools/shared/projectSettings"; import * as RepositoryIdentityResolver from "./RepositoryIdentityResolver.ts"; const layerWorkspacePaths = Layer.succeed(WorkspacePaths.WorkspacePaths, { @@ -96,13 +98,14 @@ const layerTestFor = ( | ProjectFaviconResolver.ProjectFaviconResolver | RepositoryIdentityResolver.RepositoryIdentityResolver >, + settings?: Parameters[0], ) => RuntimeLayer.layerProjectService.pipe( Layer.provideMerge(ProjectEnrichmentService.layer), Layer.provideMerge(layerWorkspacePaths), Layer.provideMerge(projectMetadataLayer), Layer.provideMerge(SqlitePersistence.layerMemory), - Layer.provideMerge(ServerSettings.layerTest()), + Layer.provideMerge(ServerSettings.layerTest(settings)), Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "project-service-test-" })), Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)), Layer.provideMerge(layerEnrichmentCompletions), @@ -615,6 +618,44 @@ it.layer(layerTest)("ProjectService", (it) => { ); }); +it.effect("an update on folded settings reaches the actions and defaults new threads use", () => + Effect.gen(function* () { + const service = yield* ProjectService.ProjectService; + const projectId = ProjectId.make("project:folded"); + const setup = { + id: "setup", + name: "Setup", + command: "vp install", + icon: "configure", + runOnWorktreeCreate: true, + } as const; + yield* service.create({ + commandId: CommandId.make("command:project:folded-create"), + projectId, + title: "Folded", + workspaceRoot: "/work/folded", + }); + + const updated = yield* service.update({ + commandId: CommandId.make("command:project:folded-update"), + projectId, + scripts: [setup], + defaultThreadEnvMode: "worktree", + }); + + const settings = yield* (yield* ServerSettings.ServerSettingsService).getSettings; + assert.deepEqual(resolveProjectScripts(settings, updated), [setup]); + assert.equal( + resolveProjectSettings(settings, projectId, updated).settings.defaultThreadEnvMode, + "worktree", + ); + }).pipe( + Effect.provide( + layerTestFor(layerMetadata, { projectSettingsFolded: true, defaultThreadEnvMode: "local" }), + ), + ), +); + it.effect("keeps project snapshots available when optional metadata enrichment fails", () => Effect.gen(function* () { const layerFailingMetadata = Layer.merge( From f18b8209000b5658a8b9dcc742cc4a5320be8f93 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 17:26:04 +0000 Subject: [PATCH 2/4] fix(server): project updates on folded settings reach new threads ProjectService.update and create wrote scripts, default thread mode, default model and auto-pull only to the legacy project record, which launch, the Actions menu and Settings stop reading once project settings are folded. They now also write the matching projectSettingsOverrides entry, so agent writes through t3_project_update take effect. Fixes pingdotgg/t3code#14991 AI-assisted; verified with the tests and tools listed above. --- apps/server/src/project/ProjectService.ts | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/apps/server/src/project/ProjectService.ts b/apps/server/src/project/ProjectService.ts index 7080a9ff2bdfa..5d86bf3f4d31a 100644 --- a/apps/server/src/project/ProjectService.ts +++ b/apps/server/src/project/ProjectService.ts @@ -106,6 +106,7 @@ export class ProjectOperationError extends Schema.TaggedError, + ) { + const changes = { + defaultModelSelection: input.defaultModelSelection, + defaultThreadEnvMode: input.defaultThreadEnvMode, + defaultAutoPull: input.autoPull, + defaultProjectScripts: input.scripts, + }; + if (Object.values(changes).every((value) => value === undefined)) return; + const settings = yield* serverSettings.getSettings; + const entry: Record = { ...settings.projectSettingsOverrides[projectId] }; + for (const [key, value] of Object.entries(changes)) { + if (value === null) delete entry[key]; + else if (value !== undefined) entry[key] = value; + } + yield* serverSettings.updateSettings({ + projectSettingsOverrides: { + [projectId]: Object.keys(entry).length === 0 ? null : entry, + }, + }); + }, + (effect, projectId) => + Effect.mapError( + effect, + (cause) => new ProjectOperationError({ operation: "update-settings", projectId, cause }), + ), + ); + const update: ProjectService["Service"]["update"] = Effect.fn("ProjectService.update")( function* (input) { const existing = yield* readRow(input.projectId); @@ -429,6 +466,7 @@ export const make = Effect.gen(function* () { ...(input.pinned === undefined ? {} : { pinned: input.pinned }), ...(input.archived === undefined ? {} : { archived: input.archived }), }); + yield* writeProjectSettingsOverrides(input.projectId, input); if (workspaceRoot !== previousRoot) { yield* projectEnrichment.invalidate([previousRoot, workspaceRoot]); } From d14a76be546fc78e1411e52c4ee574f3d5138a22 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 17:38:49 +0000 Subject: [PATCH 3/4] fix(server): project settings writes keep command order and concurrent edits Write the settings overrides only when a project command first commits, under the project lock, so a retried command cannot reapply a superseded value. Merge the per-project entry inside the settings write lock by letting updateSettings take a patch computed from current settings, so concurrent edits to other override keys are kept. AI-assisted; verified with the tests and tools listed above. --- .../server/src/project/ProjectService.test.ts | 21 +++++- apps/server/src/project/ProjectService.ts | 75 +++++++++---------- apps/server/src/serverSettings.ts | 24 ++++-- 3 files changed, 73 insertions(+), 47 deletions(-) diff --git a/apps/server/src/project/ProjectService.test.ts b/apps/server/src/project/ProjectService.test.ts index 9f39a4311f0cf..1cf679771b9a2 100644 --- a/apps/server/src/project/ProjectService.test.ts +++ b/apps/server/src/project/ProjectService.test.ts @@ -643,12 +643,31 @@ it.effect("an update on folded settings reaches the actions and defaults new thr defaultThreadEnvMode: "worktree", }); - const settings = yield* (yield* ServerSettings.ServerSettingsService).getSettings; + const settingsService = yield* ServerSettings.ServerSettingsService; + const settings = yield* settingsService.getSettings; assert.deepEqual(resolveProjectScripts(settings, updated), [setup]); assert.equal( resolveProjectSettings(settings, projectId, updated).settings.defaultThreadEnvMode, "worktree", ); + + yield* service.update({ + commandId: CommandId.make("command:project:folded-update-local"), + projectId, + defaultThreadEnvMode: "local", + }); + // A late retry of the first command must not reapply its superseded value. + const retried = yield* service.update({ + commandId: CommandId.make("command:project:folded-update"), + projectId, + scripts: [setup], + defaultThreadEnvMode: "worktree", + }); + assert.equal( + resolveProjectSettings(yield* settingsService.getSettings, projectId, retried).settings + .defaultThreadEnvMode, + "local", + ); }).pipe( Effect.provide( layerTestFor(layerMetadata, { projectSettingsFolded: true, defaultThreadEnvMode: "local" }), diff --git a/apps/server/src/project/ProjectService.ts b/apps/server/src/project/ProjectService.ts index 5d86bf3f4d31a..1d956f363efe7 100644 --- a/apps/server/src/project/ProjectService.ts +++ b/apps/server/src/project/ProjectService.ts @@ -106,7 +106,6 @@ export class ProjectOperationError extends Schema.TaggedError, + ) => { + const changes = { + defaultProjectScripts: command.scripts, + ...(command.type === "project.meta.update" + ? { + defaultModelSelection: command.defaultModelSelection, + defaultThreadEnvMode: command.defaultThreadEnvMode, + defaultAutoPull: command.autoPull, + } + : {}), + }; + if (Object.values(changes).every((value) => value === undefined)) return Effect.void; + return serverSettings.updateSettings((settings) => { + const entry: Record = { + ...settings.projectSettingsOverrides[command.projectId], + }; + for (const [key, value] of Object.entries(changes)) { + if (value === null) delete entry[key]; + else if (value !== undefined) entry[key] = value; + } + return { + projectSettingsOverrides: { + [command.projectId]: Object.keys(entry).length === 0 ? null : entry, + }, + }; + }); + }; + const commit = Effect.fn("ProjectService.commit")(function* (command: ProjectCommand) { const { projectId } = command; const dispatchError = (cause: unknown) => @@ -271,13 +301,17 @@ export const make = Effect.gen(function* () { now, }); if (Result.isSuccess(planned)) { - const { receipt } = yield* eventSink.commitProjectCommand({ + const { receipt, committed } = yield* eventSink.commitProjectCommand({ commandId: command.commandId, projectId, commandType: command.type, acceptedAt: now, event: planned.success, }); + // Under the project lock and only on first commit, so retries cannot undo newer commands. + if (committed && command.type !== "project.delete") { + yield* writeProjectSettingsOverrides(command); + } return receipt; } return yield* eventSink.commitRejectedProjectCommand({ @@ -392,47 +426,11 @@ export const make = Effect.gen(function* () { workspaceRoot, ...(input.scripts === undefined ? {} : { scripts: input.scripts }), }); - yield* writeProjectSettingsOverrides(input.projectId, input); yield* projectEnrichment.invalidate([workspaceRoot]); return yield* readCommitted(input.projectId); }, ); - // Launch and clients read these from settings overrides once legacy project fields are folded. - const writeProjectSettingsOverrides = Effect.fn("ProjectService.writeProjectSettingsOverrides")( - function* ( - projectId: ProjectId, - input: Pick< - ProjectUpdateInput, - "defaultModelSelection" | "defaultThreadEnvMode" | "autoPull" | "scripts" - >, - ) { - const changes = { - defaultModelSelection: input.defaultModelSelection, - defaultThreadEnvMode: input.defaultThreadEnvMode, - defaultAutoPull: input.autoPull, - defaultProjectScripts: input.scripts, - }; - if (Object.values(changes).every((value) => value === undefined)) return; - const settings = yield* serverSettings.getSettings; - const entry: Record = { ...settings.projectSettingsOverrides[projectId] }; - for (const [key, value] of Object.entries(changes)) { - if (value === null) delete entry[key]; - else if (value !== undefined) entry[key] = value; - } - yield* serverSettings.updateSettings({ - projectSettingsOverrides: { - [projectId]: Object.keys(entry).length === 0 ? null : entry, - }, - }); - }, - (effect, projectId) => - Effect.mapError( - effect, - (cause) => new ProjectOperationError({ operation: "update-settings", projectId, cause }), - ), - ); - const update: ProjectService["Service"]["update"] = Effect.fn("ProjectService.update")( function* (input) { const existing = yield* readRow(input.projectId); @@ -466,7 +464,6 @@ export const make = Effect.gen(function* () { ...(input.pinned === undefined ? {} : { pinned: input.pinned }), ...(input.archived === undefined ? {} : { archived: input.archived }), }); - yield* writeProjectSettingsOverrides(input.projectId, input); if (workspaceRoot !== previousRoot) { yield* projectEnrichment.invalidate([previousRoot, workspaceRoot]); } diff --git a/apps/server/src/serverSettings.ts b/apps/server/src/serverSettings.ts index 251becba12f6c..50b643638058d 100644 --- a/apps/server/src/serverSettings.ts +++ b/apps/server/src/serverSettings.ts @@ -262,8 +262,9 @@ export class ServerSettingsService extends Context.Service< readonly getSettings: Effect.Effect; + /** A function patch is computed from the current settings under the write lock. */ readonly updateSettings: ( - patch: ServerSettingsPatch, + patch: ServerSettingsPatch | ((current: ServerSettings) => ServerSettingsPatch), ) => Effect.Effect; readonly updateProviderInstance: ( @@ -326,7 +327,12 @@ const makeTest = Effect.fn("serverSettings.makeTest")(function* ( getSettings, updateSettings: (patch) => updateTestSettings((currentSettings) => - Effect.succeed(applyServerSettingsPatch(currentSettings, patch)), + Effect.succeed( + applyServerSettingsPatch( + currentSettings, + typeof patch === "function" ? patch(currentSettings) : patch, + ), + ), ), updateProviderInstance: (mutation, patch = {}) => updateTestSettings((currentSettings) => @@ -1184,8 +1190,11 @@ const make = Effect.gen(function* () { }; const updateAndPersistSettings = ( - patch: ServerSettingsPatch, - update: (current: ServerSettings) => Effect.Effect, + patchInput: ServerSettingsPatch | ((current: ServerSettings) => ServerSettingsPatch), + update: ( + current: ServerSettings, + patch: ServerSettingsPatch, + ) => Effect.Effect, ): Effect.Effect => writeSemaphore.withPermits(1)( Effect.gen(function* () { @@ -1197,9 +1206,10 @@ const make = Effect.gen(function* () { cause: parseFailure.value, }); } + const patch = typeof patchInput === "function" ? patchInput(current) : patchInput; // An older client echoes a reference as the redacted marker; restore it before vetting so // a removed provider's reference is cleared below rather than restored by persistence. - const updated = withEchoedSecretReferences(current, yield* update(current)); + const updated = withEchoedSecretReferences(current, yield* update(current, patch)); // Vet before secrets: a variable the policy hides from clients is not one they removed. const vetted = managed.vetWrite(current, yield* normalizeServerSettings(updated), patch); if (vetted._tag === "Locked") { @@ -1367,8 +1377,8 @@ const make = Effect.gen(function* () { start, ready: Deferred.await(startedDeferred), getSettings: getMaterializedSettings, - updateSettings: (patch) => - updateAndPersistSettings(patch, (current) => + updateSettings: (patchInput) => + updateAndPersistSettings(patchInput, (current, patch) => ensureSecretProviderWritesAllowed(patch, settingsPath).pipe( Effect.as(applyServerSettingsPatch(current, patch)), ), From e4d37c9c024223d53176f7360fa853b295702c55 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 17:42:20 +0000 Subject: [PATCH 4/4] test(server): settings mocks accept a patch computed from current settings AI-assisted; verified with the tests and tools listed above. --- apps/server/src/device/DeviceService.test.ts | 21 +++++++++++-------- .../ThreadSettlementService.test.ts | 9 +++++--- .../src/provider/ProviderRegistry.test.ts | 7 +++++-- apps/server/src/serverSettings.ts | 19 ++++++++++++----- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/apps/server/src/device/DeviceService.test.ts b/apps/server/src/device/DeviceService.test.ts index f2e0bcdf0c725..dab657fce11f9 100644 --- a/apps/server/src/device/DeviceService.test.ts +++ b/apps/server/src/device/DeviceService.test.ts @@ -313,15 +313,18 @@ const fixture = Effect.fn("fixture")(function* ( start: Effect.void, ready: Effect.void, getSettings: Ref.get(settings), - updateSettings: (patch) => - Ref.updateAndGet(settings, (current) => ({ - ...current, - enableDeviceSupport: patch.enableDeviceSupport ?? current.enableDeviceSupport, - enableAgentDeviceAccess: - patch.enableAgentDeviceAccess ?? current.enableAgentDeviceAccess, - deviceOnboardingCompleted: - patch.deviceOnboardingCompleted ?? current.deviceOnboardingCompleted, - })), + updateSettings: (update) => + Ref.updateAndGet(settings, (current) => { + const patch = ServerSettings.resolveServerSettingsPatch(current, update); + return { + ...current, + enableDeviceSupport: patch.enableDeviceSupport ?? current.enableDeviceSupport, + enableAgentDeviceAccess: + patch.enableAgentDeviceAccess ?? current.enableAgentDeviceAccess, + deviceOnboardingCompleted: + patch.deviceOnboardingCompleted ?? current.deviceOnboardingCompleted, + }; + }), streamChanges: Stream.empty, subscribeChanges: Effect.succeed(Stream.empty), }), diff --git a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts b/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts index cca6ee08e7116..e3946028dc4b1 100644 --- a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts @@ -20,7 +20,6 @@ import { type OrchestrationV2ThreadShell, type PullRequestSummary, type ServerSettings as ContractServerSettings, - type ServerSettingsPatch, } from "@t3tools/contracts"; import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings"; import * as SecureRandom from "effect/crypto/SecureRandom"; @@ -598,9 +597,13 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options: const scriptRuns = yield* Queue.unbounded(); - const updateSettings = (patch: ServerSettingsPatch) => + const updateSettings = (update: ServerSettings.ServerSettingsUpdate) => Effect.gen(function* () { - const next = applyServerSettingsPatch(yield* Ref.get(settings), patch); + const current = yield* Ref.get(settings); + const next = applyServerSettingsPatch( + current, + ServerSettings.resolveServerSettingsPatch(current, update), + ); yield* Ref.set(settings, next); yield* PubSub.publish(settingsChanges, next); return next; diff --git a/apps/server/src/provider/ProviderRegistry.test.ts b/apps/server/src/provider/ProviderRegistry.test.ts index b5501943ca04f..02ea1696ffbcb 100644 --- a/apps/server/src/provider/ProviderRegistry.test.ts +++ b/apps/server/src/provider/ProviderRegistry.test.ts @@ -289,10 +289,13 @@ function makeMutableServerSettingsService( start: Effect.void, ready: Effect.void, getSettings: Ref.get(settingsRef), - updateSettings: (patch) => + updateSettings: (update) => Effect.gen(function* () { const current = yield* Ref.get(settingsRef); - const next = applyServerSettingsPatch(current, patch); + const next = applyServerSettingsPatch( + current, + ServerSettingsModule.resolveServerSettingsPatch(current, update), + ); encodeServerSettings(next); yield* Ref.set(settingsRef, next); yield* PubSub.publish(changes, next); diff --git a/apps/server/src/serverSettings.ts b/apps/server/src/serverSettings.ts index 50b643638058d..cadf300ad3339 100644 --- a/apps/server/src/serverSettings.ts +++ b/apps/server/src/serverSettings.ts @@ -250,6 +250,16 @@ function ensureProviderInstanceMutationAllowed( return Effect.void; } +/** A function is computed from the current settings under the write lock. */ +export type ServerSettingsUpdate = + | ServerSettingsPatch + | ((current: ServerSettings) => ServerSettingsPatch); + +export const resolveServerSettingsPatch = ( + current: ServerSettings, + update: ServerSettingsUpdate, +): ServerSettingsPatch => (typeof update === "function" ? update(current) : update); + export class ServerSettingsService extends Context.Service< ServerSettingsService, { @@ -262,9 +272,8 @@ export class ServerSettingsService extends Context.Service< readonly getSettings: Effect.Effect; - /** A function patch is computed from the current settings under the write lock. */ readonly updateSettings: ( - patch: ServerSettingsPatch | ((current: ServerSettings) => ServerSettingsPatch), + patch: ServerSettingsUpdate, ) => Effect.Effect; readonly updateProviderInstance: ( @@ -330,7 +339,7 @@ const makeTest = Effect.fn("serverSettings.makeTest")(function* ( Effect.succeed( applyServerSettingsPatch( currentSettings, - typeof patch === "function" ? patch(currentSettings) : patch, + resolveServerSettingsPatch(currentSettings, patch), ), ), ), @@ -1190,7 +1199,7 @@ const make = Effect.gen(function* () { }; const updateAndPersistSettings = ( - patchInput: ServerSettingsPatch | ((current: ServerSettings) => ServerSettingsPatch), + patchInput: ServerSettingsUpdate, update: ( current: ServerSettings, patch: ServerSettingsPatch, @@ -1206,7 +1215,7 @@ const make = Effect.gen(function* () { cause: parseFailure.value, }); } - const patch = typeof patchInput === "function" ? patchInput(current) : patchInput; + const patch = resolveServerSettingsPatch(current, patchInput); // An older client echoes a reference as the redacted marker; restore it before vetting so // a removed provider's reference is cleared below rather than restored by persistence. const updated = withEchoedSecretReferences(current, yield* update(current, patch));