Skip to content

Commit 673f2cd

Browse files
fix(server): repair settlement projection only and tighten tests
Drop the orchestration_events rewrite from migration 045. Projectors and the engine bootstrap from projection rows and cursors, never a full replay, so repairing projection_threads is enough and the event log stays as recorded. The migration is a single UPDATE and explains why the settledAt == occurred_at match identifies an unrepaired sweep. Migration test covers the no-activity fallback, activity after the sweep, and asserts event payloads are untouched. Engine tests stamp a distinct past settledAt and assert it survives while updatedAt stays the command time; previously they passed the sweep time and asserted nothing. Remove the resolveSettledTimestamp alias on web and have both call sites import the client-runtime helper directly. Mobile slim rows drop the unreachable createdAt fallback. Move the settled ordering line in the user docs into its own paragraph. Co-Authored-By: Claude Code <[email protected]>
1 parent 71940bc commit 673f2cd

10 files changed

Lines changed: 201 additions & 222 deletions

File tree

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,13 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
407407

408408
const status = resolveThreadListV2Status(thread);
409409
const statusLabel = STATUS_LABEL_BY_STATUS[status];
410+
// Settled rows label by the same stamp they sort by, so order and label
411+
// can't disagree. updatedAt is always present, so the resolver never
412+
// returns null here.
413+
const settledTimestamp =
414+
variant === "slim" && !snoozedRow ? resolveSettledThreadTimestamp(thread) : null;
410415
const timeLabel =
411-
variant === "slim" && !snoozedRow
412-
? relativeTime(resolveSettledThreadTimestamp(thread) ?? thread.createdAt)
413-
: threadTimeLabel(thread);
416+
settledTimestamp !== null ? relativeTime(settledTimestamp) : threadTimeLabel(thread);
414417

415418
const handleDelete = useCallback(() => onDeleteThread(thread), [onDeleteThread, thread]);
416419
const handleRegenerateTitle = useCallback(

‎apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,15 @@ describe("OrchestrationEngine", () => {
380380
originalUpdatedAt,
381381
);
382382

383+
// Automatic settlement stamps the last activity, never the sweep time.
384+
const lastActivityAt = "2025-12-20T00:00:00.000Z";
383385
const staleError = yield* engine
384386
.dispatch({
385387
type: "thread.auto-settle",
386388
commandId: CommandId.make("cmd-auto-settle-stale-snapshot"),
387389
threadId: guardedThreadId,
388390
snapshotSequence,
389-
settledAt: now(),
391+
settledAt: lastActivityAt,
390392
})
391393
.pipe(Effect.flip);
392394
expect(staleError._tag).toBe("OrchestrationCommandInvariantError");
@@ -414,7 +416,7 @@ describe("OrchestrationEngine", () => {
414416
commandId: CommandId.make(`cmd-auto-settle-${expectedLiveness}`),
415417
threadId: liveThreadId,
416418
snapshotSequence: livenessSnapshotSequence,
417-
settledAt: now(),
419+
settledAt: lastActivityAt,
418420
})
419421
.pipe(Effect.flip);
420422
expect(livenessError._tag).toBe("OrchestrationCommandInvariantError");
@@ -427,7 +429,7 @@ describe("OrchestrationEngine", () => {
427429
commandId: CommandId.make("cmd-auto-settle-after-liveness-cleared"),
428430
threadId: liveThreadId,
429431
snapshotSequence: livenessSnapshotSequence,
430-
settledAt: now(),
432+
settledAt: lastActivityAt,
431433
});
432434

433435
const freshSnapshotSequence = yield* engine.latestSequence;
@@ -442,16 +444,16 @@ describe("OrchestrationEngine", () => {
442444
commandId: CommandId.make("cmd-auto-settle-after-unrelated-update"),
443445
threadId: guardedThreadId,
444446
snapshotSequence: freshSnapshotSequence,
445-
settledAt: now(),
447+
settledAt: lastActivityAt,
446448
});
447449

448450
const settled = yield* snapshots.getSnapshot();
449-
expect(
450-
settled.threads.find((thread) => thread.id === guardedThreadId)?.settledOverride,
451-
).toBe("settled");
452-
expect(settled.threads.find((thread) => thread.id === liveThreadId)?.settledOverride).toBe(
453-
"settled",
454-
);
451+
for (const threadId of [guardedThreadId, liveThreadId]) {
452+
const thread = settled.threads.find((candidate) => candidate.id === threadId);
453+
expect(thread?.settledOverride).toBe("settled");
454+
expect(thread?.settledAt).toBe(lastActivityAt);
455+
expect(thread?.updatedAt).toBe(now());
456+
}
455457
}).pipe(Effect.provide(makeOrchestrationLayer())),
456458
);
457459

‎apps/server/src/orchestration/decider.settled.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ it.layer(NodeServices.layer)("settled thread decider", (it) => {
9696
const events = Array.isArray(result) ? result : [result];
9797
const settled = events.find((event) => event.type === "thread.settled");
9898
expect(settled?.payload.settledAt).toBe(SETTLED_AT);
99+
// updatedAt stays the command time so the row still moves on settle.
100+
expect(settled?.payload.updatedAt).toBe(settled?.occurredAt);
99101
expect(settled?.payload.updatedAt).not.toBe(SETTLED_AT);
100102
}),
101103
);

0 commit comments

Comments
 (0)