@devries-cameron20 / t3code-1 / commits / 3bd64cf2c1
Fork 0

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

fix(server): mark unread works after an automatic compaction (#25286)

Co-authored-by: maria-rcks <maria@kuuro.net>

oliver committed Oct 29, 2026 at 11:02 UTC 3bd64cf2c1c72c3c09d8258653a8e1e2d30b5116
2 files changed +116 -2
apps/server/src/orchestration-v2/Orchestrator.ts
+8 -2
@@ -3229,8 +3229,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3229 }
3230 let markUnreadVisitedAt: DateTime.Utc | null = null;
3231 if (command.type === "thread.mark-unread") {
3232 - const projection = yield* loadProjectionForCommand(command, ["runs"]);
3233 - const latestRunCompletedAt = projection.runs.at(-1)?.completedAt ?? null;
3232 + const shell = yield* projectionStore
3233 + .getThreadShell(command.threadId)
3234 + .pipe(
3235 + Effect.mapError(
3236 + (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
3237 + ),
3238 + );
3239 + const latestRunCompletedAt = shell?.latestRunCompletedAt ?? null;
3240 if (latestRunCompletedAt === null) {
3241 return yield* new OrchestratorDispatchError({
3242 commandId: command.commandId,
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+108
@@ -6278,6 +6278,114 @@ it.layer(layerSharedApplicationDataPlaneTest)("visited projection", (it) => {
6278 assert.instanceOf(invalidVisit, Orchestrator.OrchestratorDispatchError);
6279 }),
6280 );
6281 +
6282 + it.effect("marks unread before the user's last turn when an automatic compaction followed", () =>
6283 + Effect.gen(function* () {
6284 + const orchestrator = yield* Orchestrator.OrchestratorV2;
6285 + const threadId = ThreadId.make("runtime-layer-mark-unread-compacted");
6286 + const turnCompletedAt = DateTime.makeUnsafe("2026-07-24T10:00:00.000Z");
6287 + yield* orchestrator.dispatch({
6288 + type: "thread.create",
6289 + createdBy: "user",
6290 + creationSource: "web",
6291 + commandId: CommandId.make(`${threadId}:create`),
6292 + threadId,
6293 + projectId: ProjectId.make(`${threadId}:project`),
6294 + title: "Compacted thread",
6295 + modelSelection,
6296 + runtimeMode: "full-access",
6297 + interactionMode: "default",
6298 + branch: null,
6299 + worktreePath: null,
6300 + });
6301 + const runs = [
6302 + { text: "Continue", at: turnCompletedAt },
6303 + {
6304 + text: "/compact",
6305 + idleCompaction: "beforeCacheExpires" as const,
6306 + at: DateTime.makeUnsafe("2026-07-24T11:00:00.000Z"),
6307 + },
6308 + ];
6309 + yield* (yield* EventSink.EventSinkV2).write({
6310 + commandId: CommandId.make(`${threadId}:seed`),
6311 + events: runs.flatMap(({ at, ...message }, index) => {
6312 + const runId = RunId.make(`${threadId}:run-${index}`);
6313 + const messageId = MessageId.make(`${threadId}:message-${index}`);
6314 + return [
6315 + {
6316 + id: EventId.make(`${messageId}:event`),
6317 + type: "message.updated" as const,
6318 + threadId,
6319 + occurredAt: at,
6320 + payload: {
6321 + ...message,
6322 + id: messageId,
6323 + threadId,
6324 + runId,
6325 + nodeId: null,
6326 + role: "user" as const,
6327 + attachments: [],
6328 + streaming: false,
6329 + createdBy: "user" as const,
6330 + creationSource: "web" as const,
6331 + createdAt: at,
6332 + updatedAt: at,
6333 + },
6334 + },
6335 + {
6336 + id: EventId.make(`${runId}:event`),
6337 + type: "run.created" as const,
6338 + threadId,
6339 + runId,
6340 + providerInstanceId: modelSelection.instanceId,
6341 + occurredAt: at,
6342 + payload: {
6343 + id: runId,
6344 + threadId,
6345 + ordinal: index + 1,
6346 + providerInstanceId: modelSelection.instanceId,
6347 + modelSelection,
6348 + providerThreadId: null,
6349 + userMessageId: messageId,
6350 + rootNodeId: null,
6351 + activeAttemptId: null,
6352 + status: "completed" as const,
6353 + queuePosition: null,
6354 + requestedAt: at,
6355 + startedAt: at,
6356 + completedAt: at,
6357 + checkpointId: null,
6358 + contextHandoffId: null,
6359 + },
6360 + },
6361 + ];
6362 + }),
6363 + });
6364 +
6365 + yield* orchestrator.dispatch({
6366 + type: "thread.mark-unread",
6367 + commandId: CommandId.make(`${threadId}:mark-unread`),
6368 + threadId,
6369 + });
6370 + const projection = yield* orchestrator.getThreadProjection(threadId);
6371 + assert.deepEqual(
6372 + projection.thread.lastVisitedAt,
6373 + DateTime.subtract(turnCompletedAt, { milliseconds: 1 }),
6374 + );
6375 + const shell = yield* orchestrator.getThreadShell(threadId);
6376 + assert.deepEqual(shell!.latestRunCompletedAt, turnCompletedAt);
6377 + assert.deepEqual(shell!.lastVisitedAt, projection.thread.lastVisitedAt);
6378 +
6379 + yield* orchestrator.dispatch({
6380 + type: "thread.visit",
6381 + commandId: CommandId.make(`${threadId}:visit`),
6382 + threadId,
6383 + visitedAt: DateTime.formatIso(turnCompletedAt),
6384 + });
6385 + const revisited = yield* orchestrator.getThreadShell(threadId);
6386 + assert.deepEqual(revisited!.lastVisitedAt, turnCompletedAt);
6387 + }),
6388 + );
6389 });
6390
6391 it.layer(Layer.fresh(layerSharedApplicationDataPlaneTest))("thread opens", (it) => {