@devries-cameron20 / t3code Mirror · read-only / commits / 9e9fa10449
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 01:45 UTC

fix(server): clear snooze when settling threads (#17547)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Rick Heere committed Oct 19, 2026 at 23:20 UTC 9e9fa10449a5f4dff41faf73ea099241c7781446
2 files changed +84 -1
apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
+78
@@ -22,6 +22,7 @@ import * as DateTime from "effect/DateTime";
22 import * as Effect from "effect/Effect";
23 import * as Layer from "effect/Layer";
24 import * as Result from "effect/Result";
25 +import * as Stream from "effect/Stream";
26 import * as TestClock from "effect/testing/TestClock";
27 import * as SqlClient from "effect/sql/SqlClient";
28 import * as SqlitePersistence from "../persistence/Sqlite.ts";
@@ -1100,3 +1101,80 @@ it.effect("replays a thread.create receipt without changing the thread", () =>
1101 assert.equal(yield* orchestrator.getThreadEventSequence(threadId), original.sequence);
1102 }).pipe(Effect.provide(layerTest)),
1103 );
1104 +
1105 +it.effect("explicit settle clears snooze atomically and stays idempotent after re-snoozing", () =>
1106 + Effect.gen(function* () {
1107 + const orchestrator = yield* Orchestrator.OrchestratorV2;
1108 + const projections = yield* ProjectionStore.ProjectionStoreV2;
1109 + const events = yield* EventSink.EventSinkV2;
1110 + const threadId = ThreadId.make("thread:settle-snoozed");
1111 + yield* orchestrator.dispatch({
1112 + type: "thread.create",
1113 + commandId: CommandId.make("create-settle-snoozed"),
1114 + threadId,
1115 + projectId: ProjectId.make("project:settle-snoozed"),
1116 + title: "Snoozed thread",
1117 + modelSelection,
1118 + runtimeMode: "full-access",
1119 + interactionMode: "default",
1120 + branch: null,
1121 + worktreePath: null,
1122 + createdBy: "user",
1123 + creationSource: "web",
1124 + });
1125 + const now = yield* DateTime.now;
1126 + const settledAt = DateTime.add(now, { seconds: 1 });
1127 + const snoozedUntil = DateTime.add(now, { hours: 1 });
1128 + for (const round of [1, 2]) {
1129 + yield* orchestrator.dispatch({
1130 + type: "thread.snooze",
1131 + commandId: CommandId.make(`snooze-before-settle-${round}`),
1132 + threadId,
1133 + snoozedUntil: DateTime.formatIso(snoozedUntil),
1134 + });
1135 + assert.deepInclude(yield* projections.getThread(threadId), {
1136 + snoozedUntil,
1137 + snoozedAt: yield* DateTime.now,
1138 + });
1139 + yield* TestClock.adjust("1 second");
1140 + const commandId = CommandId.make(`settle-snoozed-${round}`);
1141 + yield* orchestrator.dispatch({ type: "thread.settle", commandId, threadId });
1142 + const expected = {
1143 + settledOverride: "settled",
1144 + settledAt,
1145 + snoozedUntil: null,
1146 + snoozedAt: null,
1147 + updatedAt: yield* DateTime.now,
1148 + } as const;
1149 + const committed = yield* events.readByCommandId({ commandId }).pipe(Stream.runCollect);
1150 + assert.lengthOf(committed, 1);
1151 + assert.equal(committed[0]?.event.type, "thread.settled");
1152 + assert.deepInclude(committed[0]?.event.payload, expected);
1153 + const settled = yield* projections.getThreadShell(threadId);
1154 + assert.deepInclude(settled, expected);
1155 + assert.deepInclude((yield* projections.getThreadProjection(threadId)).thread, expected);
1156 +
1157 + yield* TestClock.adjust("1 second");
1158 + yield* orchestrator.dispatch({
1159 + type: "thread.settle",
1160 + commandId: CommandId.make(`settle-again-${round}`),
1161 + threadId,
1162 + });
1163 + assert.deepEqual(yield* projections.getThreadShell(threadId), settled);
1164 + }
1165 + yield* orchestrator.dispatch({
1166 + type: "thread.unsettle",
1167 + commandId: CommandId.make("unsettle-after-snooze"),
1168 + threadId,
1169 + reason: "user",
1170 + });
1171 + const active = {
1172 + settledOverride: "active",
1173 + settledAt: null,
1174 + snoozedUntil: null,
1175 + snoozedAt: null,
1176 + } as const;
1177 + assert.deepInclude(yield* projections.getThreadShell(threadId), active);
1178 + assert.deepInclude((yield* projections.getThreadProjection(threadId)).thread, active);
1179 + }).pipe(Effect.provide(layerTest)),
1180 +);
apps/server/src/orchestration-v2/Orchestrator.ts
+6 -1
@@ -2889,7 +2889,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
2889 pinnedAt: null,
2890 pinOrderKey: null,
2891 activeOrderKey: null,
2892 - updatedAt: alreadySettled ? thread.updatedAt : now,
2892 + snoozedUntil: null,
2893 + snoozedAt: null,
2894 + updatedAt:
2895 + alreadySettled && thread.snoozedUntil == null && thread.snoozedAt == null
2896 + ? thread.updatedAt
2897 + : now,
2898 };
2899 }
2900 case "thread.unsettle": {