fix(app): un-settled threads return to the top of the list (#8231)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
b0a0281269
commit
3b86ef941c
22 files changed
+271
-29
No files matched your search
@@ -303,6 +303,19 @@ describe("sortThreadsForListV2", () => {
|
||||
]);
|
||||
expect(sorted.map((thread) => thread.id)).toEqual(["newest", "middle", "oldest"]);
|
||||
});
|
||||
|
||||
it("surfaces an un-settled thread at the top via its re-entry stamp", () => {
|
||||
const sorted = sortThreadsForListV2([
|
||||
{
|
||||
id: "old-unsettled",
|
||||
createdAt: "2026-06-01T08:00:00.000Z",
|
||||
unsettledAt: "2026-06-01T13:00:00.000Z",
|
||||
},
|
||||
{ id: "newest", createdAt: "2026-06-01T12:00:00.000Z" },
|
||||
{ id: "middle", createdAt: "2026-06-01T10:00:00.000Z" },
|
||||
]);
|
||||
expect(sorted.map((thread) => thread.id)).toEqual(["old-unsettled", "newest", "middle"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildThreadListV2Items", () => {
|
||||
|
||||
@@ -12,7 +12,10 @@ import type {
|
||||
} from "@t3tools/client-runtime/state/thread-settled";
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
|
||||
import { sortPinnedThreadsByOrderKey } from "@t3tools/client-runtime/state/thread-sort";
|
||||
import {
|
||||
activeThreadAnchorTimestampMs,
|
||||
sortPinnedThreadsByOrderKey,
|
||||
} from "@t3tools/client-runtime/state/thread-sort";
|
||||
import type { EnvironmentId, ProjectId, ThreadLinkedPullRequest } from "@t3tools/contracts";
|
||||
|
||||
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
|
||||
@@ -191,19 +194,25 @@ function firstValidTimestampMs(...candidates: ReadonlyArray<string | null | unde
|
||||
}
|
||||
|
||||
/**
|
||||
* v2 sort: static creation order, newest thread on top. Activity NEVER
|
||||
* reorders the list — a row holds its position from open until settled, so
|
||||
* the screen only moves at lifecycle transitions. Mirrors web's
|
||||
* sortThreadsForSidebarV2.
|
||||
* v2 sort: static order, newest anchor on top. Activity NEVER reorders the
|
||||
* list — a row holds its position between lifecycle transitions. The anchor
|
||||
* is creation time until an un-settle re-anchors it (see
|
||||
* activeThreadAnchorTimestampMs), so an un-settled thread surfaces at the
|
||||
* top instead of sinking back to its creation-order slot. Mirrors web's
|
||||
* sortThreadsForSidebar.
|
||||
*/
|
||||
export function sortThreadsForListV2<T extends { readonly id: string; readonly createdAt: string }>(
|
||||
threads: readonly T[],
|
||||
): T[] {
|
||||
export function sortThreadsForListV2<
|
||||
T extends {
|
||||
readonly id: string;
|
||||
readonly createdAt: string;
|
||||
readonly unsettledAt?: string | null | undefined;
|
||||
},
|
||||
>(threads: readonly T[]): T[] {
|
||||
// .sort() on a copy, not .toSorted(): Hermes doesn't ship the ES2023
|
||||
// change-by-copy array methods.
|
||||
return [...threads].sort(
|
||||
(left, right) =>
|
||||
parseTimestampMs(right.createdAt) - parseTimestampMs(left.createdAt) ||
|
||||
activeThreadAnchorTimestampMs(right) - activeThreadAnchorTimestampMs(left) ||
|
||||
left.id.localeCompare(right.id),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -269,15 +269,17 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
const settledRows = yield* sql<{
|
||||
readonly settledOverride: string | null;
|
||||
readonly settledAt: string | null;
|
||||
readonly unsettledAt: string | null;
|
||||
}>`
|
||||
SELECT
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt"
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt"
|
||||
FROM projection_threads
|
||||
WHERE thread_id = 'thread-1'
|
||||
`;
|
||||
assert.deepEqual(settledRows, [
|
||||
{ settledOverride: "settled", settledAt: "2026-01-01T00:00:01.000Z" },
|
||||
{ settledOverride: "settled", settledAt: "2026-01-01T00:00:01.000Z", unsettledAt: null },
|
||||
]);
|
||||
|
||||
yield* eventStore.append({
|
||||
@@ -301,14 +303,24 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
const unsettledRows = yield* sql<{
|
||||
readonly settledOverride: string | null;
|
||||
readonly settledAt: string | null;
|
||||
readonly unsettledAt: string | null;
|
||||
}>`
|
||||
SELECT
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt"
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt"
|
||||
FROM projection_threads
|
||||
WHERE thread_id = 'thread-1'
|
||||
`;
|
||||
assert.deepEqual(unsettledRows, [{ settledOverride: "active", settledAt: null }]);
|
||||
// The un-settle stamps the active-list re-entry time so clients can
|
||||
// surface the thread at the top of the list.
|
||||
assert.deepEqual(unsettledRows, [
|
||||
{
|
||||
settledOverride: "active",
|
||||
settledAt: null,
|
||||
unsettledAt: "2026-01-01T00:00:02.000Z",
|
||||
},
|
||||
]);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -641,6 +641,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
pinnedAt: null,
|
||||
@@ -698,6 +699,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
...existingRow.value,
|
||||
settledOverride: "settled",
|
||||
settledAt: event.payload.settledAt,
|
||||
unsettledAt: null,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
});
|
||||
return;
|
||||
@@ -714,6 +716,13 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
...existingRow.value,
|
||||
settledOverride: event.payload.reason === "user" ? "active" : null,
|
||||
settledAt: null,
|
||||
// Re-entry stamp for active-list ordering. A thread already pinned
|
||||
// active keeps its stamp: the activity reset that clears the pin
|
||||
// is not a re-entry and must not reorder the list.
|
||||
unsettledAt:
|
||||
existingRow.value.settledOverride === "active"
|
||||
? existingRow.value.unsettledAt
|
||||
: event.payload.updatedAt,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -329,6 +329,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
pinnedAt: "2026-02-24T00:00:01.000Z",
|
||||
@@ -454,6 +455,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
pinnedAt: "2026-02-24T00:00:01.000Z",
|
||||
|
||||
@@ -431,6 +431,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archived_at AS "archivedAt",
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt",
|
||||
snoozed_until AS "snoozedUntil",
|
||||
snoozed_at AS "snoozedAt",
|
||||
pinned_at AS "pinnedAt",
|
||||
@@ -468,6 +469,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archived_at AS "archivedAt",
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt",
|
||||
snoozed_until AS "snoozedUntil",
|
||||
snoozed_at AS "snoozedAt",
|
||||
pinned_at AS "pinnedAt",
|
||||
@@ -507,6 +509,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archived_at AS "archivedAt",
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt",
|
||||
snoozed_until AS "snoozedUntil",
|
||||
snoozed_at AS "snoozedAt",
|
||||
pinned_at AS "pinnedAt",
|
||||
@@ -950,6 +953,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archived_at AS "archivedAt",
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt",
|
||||
snoozed_until AS "snoozedUntil",
|
||||
snoozed_at AS "snoozedAt",
|
||||
pinned_at AS "pinnedAt",
|
||||
@@ -1709,6 +1713,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archivedAt: row.archivedAt,
|
||||
settledOverride: row.settledOverride,
|
||||
settledAt: row.settledAt,
|
||||
unsettledAt: row.unsettledAt,
|
||||
snoozedUntil: row.snoozedUntil,
|
||||
snoozedAt: row.snoozedAt,
|
||||
pinnedAt: row.pinnedAt,
|
||||
@@ -1919,6 +1924,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archivedAt: row.archivedAt,
|
||||
settledOverride: row.settledOverride,
|
||||
settledAt: row.settledAt,
|
||||
unsettledAt: row.unsettledAt,
|
||||
snoozedUntil: row.snoozedUntil,
|
||||
snoozedAt: row.snoozedAt,
|
||||
pinnedAt: row.pinnedAt,
|
||||
@@ -2058,6 +2064,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archivedAt: row.archivedAt,
|
||||
settledOverride: row.settledOverride,
|
||||
settledAt: row.settledAt,
|
||||
unsettledAt: row.unsettledAt,
|
||||
snoozedUntil: row.snoozedUntil,
|
||||
snoozedAt: row.snoozedAt,
|
||||
pinnedAt: row.pinnedAt,
|
||||
@@ -2206,6 +2213,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archivedAt: row.archivedAt,
|
||||
settledOverride: row.settledOverride,
|
||||
settledAt: row.settledAt,
|
||||
unsettledAt: row.unsettledAt,
|
||||
snoozedUntil: row.snoozedUntil,
|
||||
snoozedAt: row.snoozedAt,
|
||||
pinnedAt: row.pinnedAt,
|
||||
@@ -2488,6 +2496,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archivedAt: threadRow.value.archivedAt,
|
||||
settledOverride: threadRow.value.settledOverride,
|
||||
settledAt: threadRow.value.settledAt,
|
||||
unsettledAt: threadRow.value.unsettledAt,
|
||||
snoozedUntil: threadRow.value.snoozedUntil,
|
||||
snoozedAt: threadRow.value.snoozedAt,
|
||||
pinnedAt: threadRow.value.pinnedAt,
|
||||
@@ -2632,6 +2641,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
archivedAt: threadRow.value.archivedAt,
|
||||
settledOverride: threadRow.value.settledOverride,
|
||||
settledAt: threadRow.value.settledAt,
|
||||
unsettledAt: threadRow.value.unsettledAt,
|
||||
snoozedUntil: threadRow.value.snoozedUntil,
|
||||
snoozedAt: threadRow.value.snoozedAt,
|
||||
pinnedAt: threadRow.value.pinnedAt,
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
ThreadId,
|
||||
type OrchestrationEvent,
|
||||
type OrchestrationReadModel,
|
||||
type OrchestrationSession,
|
||||
type OrchestrationThread,
|
||||
@@ -14,6 +15,7 @@ import { expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
import { decideOrchestrationCommand } from "./decider.ts";
|
||||
import { projectEvent } from "./projector.ts";
|
||||
|
||||
const NOW = "2026-01-01T00:00:00.000Z";
|
||||
const SETTLED_AT = "2025-12-30T00:00:00.000Z";
|
||||
@@ -428,6 +430,42 @@ it.layer(NodeServices.layer)("settled thread decider", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
// Command-to-projection: an accepted un-settle must land as the re-entry
|
||||
// stamp clients sort by (max of createdAt and unsettledAt, see
|
||||
// activeThreadAnchorTimestampMs in client-runtime), so the thread surfaces
|
||||
// above threads created after it. The projector tests feed events directly;
|
||||
// this one proves the decider actually emits what they consume.
|
||||
it.effect("an accepted un-settle re-anchors the thread for the active list", () =>
|
||||
Effect.gen(function* () {
|
||||
const readModel = makeReadModel("settled");
|
||||
const result = yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.unsettle",
|
||||
commandId: CommandId.make("cmd-unsettle-anchor"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
reason: "user",
|
||||
},
|
||||
readModel,
|
||||
});
|
||||
const events = Array.isArray(result) ? result : [result];
|
||||
const unsettled = events[0]!;
|
||||
expect(unsettled.type).toBe("thread.unsettled");
|
||||
|
||||
const projected = yield* projectEvent(readModel, {
|
||||
...unsettled,
|
||||
sequence: readModel.snapshotSequence + 1,
|
||||
} as OrchestrationEvent);
|
||||
const thread = projected.threads[0]!;
|
||||
expect(thread.settledOverride).toBe("active");
|
||||
// The stamp is the decider's accept time: every thread created before
|
||||
// the un-settle anchors below it.
|
||||
expect(thread.unsettledAt).toBe(unsettled.occurredAt);
|
||||
if (unsettled.type === "thread.unsettled") {
|
||||
expect(thread.unsettledAt).toBe(unsettled.payload.updatedAt);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("prepends activity unsets for turn starts and live session updates", () =>
|
||||
Effect.gen(function* () {
|
||||
const turnResult = yield* decideOrchestrationCommand({
|
||||
|
||||
@@ -62,27 +62,62 @@ it.effect("projects settled lifecycle events", () =>
|
||||
);
|
||||
expect(settled.threads[0]?.settledOverride).toBe("settled");
|
||||
expect(settled.threads[0]?.settledAt).toBe(now);
|
||||
expect(settled.threads[0]?.unsettledAt).toBeNull();
|
||||
|
||||
const unsettleAt = "2026-01-02T00:00:00.000Z";
|
||||
const userUnsettled = yield* projectEvent(
|
||||
settled,
|
||||
makeEvent({
|
||||
sequence: 3,
|
||||
type: "thread.unsettled",
|
||||
payload: { threadId: ThreadId.make("thread-1"), reason: "user", updatedAt: now },
|
||||
payload: { threadId: ThreadId.make("thread-1"), reason: "user", updatedAt: unsettleAt },
|
||||
}),
|
||||
);
|
||||
expect(userUnsettled.threads[0]?.settledOverride).toBe("active");
|
||||
expect(userUnsettled.threads[0]?.settledAt).toBeNull();
|
||||
expect(userUnsettled.threads[0]?.unsettledAt).toBe(unsettleAt);
|
||||
|
||||
// Clearing the keep-active pin on activity is not a re-entry: the thread
|
||||
// is already in the active list, so the stamp must not move it.
|
||||
const activityAt = "2026-01-03T00:00:00.000Z";
|
||||
const activityUnsettled = yield* projectEvent(
|
||||
userUnsettled,
|
||||
makeEvent({
|
||||
sequence: 4,
|
||||
type: "thread.unsettled",
|
||||
payload: { threadId: ThreadId.make("thread-1"), reason: "activity", updatedAt: now },
|
||||
payload: { threadId: ThreadId.make("thread-1"), reason: "activity", updatedAt: activityAt },
|
||||
}),
|
||||
);
|
||||
expect(activityUnsettled.threads[0]?.settledOverride).toBeNull();
|
||||
expect(activityUnsettled.threads[0]?.settledAt).toBeNull();
|
||||
expect(activityUnsettled.threads[0]?.unsettledAt).toBe(unsettleAt);
|
||||
|
||||
const resettledAt = "2026-01-04T00:00:00.000Z";
|
||||
const resettled = yield* projectEvent(
|
||||
activityUnsettled,
|
||||
makeEvent({
|
||||
sequence: 5,
|
||||
type: "thread.settled",
|
||||
payload: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
settledAt: resettledAt,
|
||||
updatedAt: resettledAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(resettled.threads[0]?.unsettledAt).toBeNull();
|
||||
|
||||
// Waking a settled thread on activity IS a re-entry and stamps.
|
||||
const wakeAt = "2026-01-05T00:00:00.000Z";
|
||||
const woke = yield* projectEvent(
|
||||
resettled,
|
||||
makeEvent({
|
||||
sequence: 6,
|
||||
type: "thread.unsettled",
|
||||
payload: { threadId: ThreadId.make("thread-1"), reason: "activity", updatedAt: wakeAt },
|
||||
}),
|
||||
);
|
||||
expect(woke.threads[0]?.settledOverride).toBeNull();
|
||||
expect(woke.threads[0]?.unsettledAt).toBe(wakeAt);
|
||||
}),
|
||||
);
|
||||
@@ -91,6 +91,7 @@ describe("orchestration projector", () => {
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
deletedAt: null,
|
||||
|
||||
@@ -303,6 +303,7 @@ export function projectEvent(
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
deletedAt: null,
|
||||
@@ -364,6 +365,7 @@ export function projectEvent(
|
||||
threads: updateThread(nextBase.threads, payload.threadId, {
|
||||
settledOverride: "settled",
|
||||
settledAt: payload.settledAt,
|
||||
unsettledAt: null,
|
||||
updatedAt: payload.updatedAt,
|
||||
}),
|
||||
})),
|
||||
@@ -371,14 +373,24 @@ export function projectEvent(
|
||||
|
||||
case "thread.unsettled":
|
||||
return decodeForEvent(ThreadUnsettledPayload, event.payload, event.type, "payload").pipe(
|
||||
Effect.map((payload) => ({
|
||||
...nextBase,
|
||||
threads: updateThread(nextBase.threads, payload.threadId, {
|
||||
settledOverride: payload.reason === "user" ? "active" : null,
|
||||
settledAt: null,
|
||||
updatedAt: payload.updatedAt,
|
||||
}),
|
||||
})),
|
||||
Effect.map((payload) => {
|
||||
const existing = nextBase.threads.find((thread) => thread.id === payload.threadId);
|
||||
return {
|
||||
...nextBase,
|
||||
threads: updateThread(nextBase.threads, payload.threadId, {
|
||||
settledOverride: payload.reason === "user" ? "active" : null,
|
||||
settledAt: null,
|
||||
// Re-entry stamp for active-list ordering. A thread already
|
||||
// pinned active keeps its stamp: the activity reset that clears
|
||||
// the pin is not a re-entry and must not reorder the list.
|
||||
unsettledAt:
|
||||
existing?.settledOverride === "active"
|
||||
? (existing.unsettledAt ?? null)
|
||||
: payload.updatedAt,
|
||||
updatedAt: payload.updatedAt,
|
||||
}),
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
case "thread.snoozed":
|
||||
|
||||
@@ -94,6 +94,7 @@ projectionRepositoriesLayer("Projection repositories", (it) => {
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
pinnedAt: null,
|
||||
@@ -157,6 +158,7 @@ projectionRepositoriesLayer("Projection repositories", (it) => {
|
||||
archivedAt: null,
|
||||
settledOverride: "settled",
|
||||
settledAt: "2026-03-25T00:00:00.000Z",
|
||||
unsettledAt: null,
|
||||
snoozedUntil: "2026-03-26T09:00:00.000Z",
|
||||
snoozedAt: "2026-03-25T00:00:00.000Z",
|
||||
pinnedAt: "2026-03-25T00:00:00.000Z",
|
||||
@@ -186,6 +188,7 @@ projectionRepositoriesLayer("Projection repositories", (it) => {
|
||||
...row,
|
||||
settledOverride: "active",
|
||||
settledAt: null,
|
||||
unsettledAt: "2026-03-26T00:00:00.000Z",
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
pinnedAt: null,
|
||||
@@ -196,6 +199,7 @@ projectionRepositoriesLayer("Projection repositories", (it) => {
|
||||
const updated = Option.getOrNull(repersisted);
|
||||
assert.strictEqual(updated?.settledOverride, "active");
|
||||
assert.strictEqual(updated?.settledAt, null);
|
||||
assert.strictEqual(updated?.unsettledAt, "2026-03-26T00:00:00.000Z");
|
||||
assert.strictEqual(updated?.snoozedUntil, null);
|
||||
assert.strictEqual(updated?.snoozedAt, null);
|
||||
assert.strictEqual(updated?.pinnedAt, null);
|
||||
@@ -231,6 +235,7 @@ projectionRepositoriesLayer("Projection repositories", (it) => {
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
pinnedAt: null,
|
||||
|
||||
@@ -47,6 +47,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
archived_at,
|
||||
settled_override,
|
||||
settled_at,
|
||||
unsettled_at,
|
||||
snoozed_until,
|
||||
snoozed_at,
|
||||
pinned_at,
|
||||
@@ -75,6 +76,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
${row.archivedAt},
|
||||
${row.settledOverride},
|
||||
${row.settledAt},
|
||||
${row.unsettledAt},
|
||||
${row.snoozedUntil},
|
||||
${row.snoozedAt},
|
||||
${row.pinnedAt},
|
||||
@@ -103,6 +105,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
archived_at = excluded.archived_at,
|
||||
settled_override = excluded.settled_override,
|
||||
settled_at = excluded.settled_at,
|
||||
unsettled_at = excluded.unsettled_at,
|
||||
snoozed_until = excluded.snoozed_until,
|
||||
snoozed_at = excluded.snoozed_at,
|
||||
pinned_at = excluded.pinned_at,
|
||||
@@ -138,6 +141,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
archived_at AS "archivedAt",
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt",
|
||||
snoozed_until AS "snoozedUntil",
|
||||
snoozed_at AS "snoozedAt",
|
||||
pinned_at AS "pinnedAt",
|
||||
@@ -175,6 +179,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
archived_at AS "archivedAt",
|
||||
settled_override AS "settledOverride",
|
||||
settled_at AS "settledAt",
|
||||
unsettled_at AS "unsettledAt",
|
||||
snoozed_until AS "snoozedUntil",
|
||||
snoozed_at AS "snoozedAt",
|
||||
pinned_at AS "pinnedAt",
|
||||
|
||||
@@ -55,6 +55,7 @@ import Migration0039 from "./Migrations/039_ProjectionProjectsDefaultThreadEnvMo
|
||||
import Migration0040 from "./Migrations/040_ProjectionProjectFaviconPath.ts";
|
||||
import Migration0041 from "./Migrations/041_AuthSessionClientConnection.ts";
|
||||
import Migration0042 from "./Migrations/042_ProjectionThreadLinkedPullRequest.ts";
|
||||
import Migration0043 from "./Migrations/043_ProjectionThreadsUnsettledAt.ts";
|
||||
|
||||
/**
|
||||
* Migration loader with all migrations defined inline.
|
||||
@@ -109,6 +110,7 @@ export const migrationEntries = [
|
||||
[40, "ProjectionProjectFaviconPath", Migration0040],
|
||||
[41, "AuthSessionClientConnection", Migration0041],
|
||||
[42, "ProjectionThreadLinkedPullRequest", Migration0042],
|
||||
[43, "ProjectionThreadsUnsettledAt", Migration0043],
|
||||
] as const;
|
||||
|
||||
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const columns = yield* sql<{ readonly name: string }>`
|
||||
PRAGMA table_info(projection_threads)
|
||||
`;
|
||||
|
||||
if (!columns.some((column) => column.name === "unsettled_at")) {
|
||||
yield* sql`
|
||||
ALTER TABLE projection_threads
|
||||
ADD COLUMN unsettled_at TEXT
|
||||
`;
|
||||
}
|
||||
});
|
||||
@@ -41,6 +41,7 @@ export const ProjectionThread = Schema.Struct({
|
||||
archivedAt: Schema.NullOr(IsoDateTime),
|
||||
settledOverride: Schema.NullOr(Schema.Literals(["settled", "active"])),
|
||||
settledAt: Schema.NullOr(IsoDateTime),
|
||||
unsettledAt: Schema.NullOr(IsoDateTime),
|
||||
snoozedUntil: Schema.NullOr(IsoDateTime),
|
||||
snoozedAt: Schema.NullOr(IsoDateTime),
|
||||
pinnedAt: Schema.NullOr(IsoDateTime),
|
||||
|
||||
@@ -807,6 +807,33 @@ describe("sortThreadsForSidebar", () => {
|
||||
|
||||
expect(sorted.map((thread) => thread.id)).toEqual(["a", "b"]);
|
||||
});
|
||||
|
||||
it("surfaces an un-settled thread at the top via its re-entry stamp", () => {
|
||||
const sorted = sortThreadsForSidebar([
|
||||
{
|
||||
id: "old-unsettled",
|
||||
createdAt: "2026-03-09T08:00:00.000Z",
|
||||
unsettledAt: "2026-03-09T13:00:00.000Z",
|
||||
},
|
||||
sortable({ id: "newest", createdAt: "2026-03-09T12:00:00.000Z" }),
|
||||
sortable({ id: "middle", createdAt: "2026-03-09T10:00:00.000Z" }),
|
||||
]);
|
||||
|
||||
expect(sorted.map((thread) => thread.id)).toEqual(["old-unsettled", "newest", "middle"]);
|
||||
});
|
||||
|
||||
it("ignores a re-entry stamp older than the thread's creation", () => {
|
||||
const sorted = sortThreadsForSidebar([
|
||||
{
|
||||
id: "stale-stamp",
|
||||
createdAt: "2026-03-09T10:00:00.000Z",
|
||||
unsettledAt: "2026-03-09T09:00:00.000Z",
|
||||
},
|
||||
sortable({ id: "newest", createdAt: "2026-03-09T12:00:00.000Z" }),
|
||||
]);
|
||||
|
||||
expect(sorted.map((thread) => thread.id)).toEqual(["newest", "stale-stamp"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("pinOrderKeyBetween", () => {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { defaultAnimateLayoutChanges, type AnimateLayoutChanges } from "@dnd-kit
|
||||
import type { ContextMenuItem } from "@t3tools/contracts";
|
||||
import type { SidebarProjectSortOrder, SidebarThreadSortOrder } from "@t3tools/contracts/settings";
|
||||
import {
|
||||
activeThreadAnchorTimestampMs,
|
||||
getThreadSortTimestamp,
|
||||
sortThreads,
|
||||
toSortableTimestamp,
|
||||
@@ -538,16 +539,23 @@ export function firstValidTimestamp(
|
||||
return null;
|
||||
}
|
||||
|
||||
// Sidebar sort: static creation order, newest thread on top. Activity NEVER
|
||||
// reorders the list — a row holds its position from open until settled, so
|
||||
// the screen only moves at lifecycle transitions. Status (including pending
|
||||
// approval) is carried by each card's edge strip, not by position.
|
||||
// Sidebar sort: static order, newest anchor on top. Activity NEVER reorders
|
||||
// the list — a row holds its position between lifecycle transitions, so the
|
||||
// screen only moves when a thread enters or leaves the active list. The
|
||||
// anchor is creation time until an un-settle re-anchors it (see
|
||||
// activeThreadAnchorTimestampMs), so an un-settled thread surfaces at the
|
||||
// top instead of sinking back to its creation-order slot. Status (including
|
||||
// pending approval) is carried by each card's edge strip, not by position.
|
||||
export function sortThreadsForSidebar<
|
||||
T extends { readonly id: string; readonly createdAt: string },
|
||||
T extends {
|
||||
readonly id: string;
|
||||
readonly createdAt: string;
|
||||
readonly unsettledAt?: string | null | undefined;
|
||||
},
|
||||
>(threads: readonly T[]): T[] {
|
||||
return [...threads].toSorted(
|
||||
(left, right) =>
|
||||
parseTimestampMs(right.createdAt) - parseTimestampMs(left.createdAt) ||
|
||||
activeThreadAnchorTimestampMs(right) - activeThreadAnchorTimestampMs(left) ||
|
||||
left.id.localeCompare(right.id),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export {
|
||||
activeThreadAnchorTimestampMs,
|
||||
getLatestThreadForProject,
|
||||
getThreadSortTimestamp,
|
||||
sortThreads,
|
||||
|
||||
@@ -7,6 +7,9 @@ one environment.
|
||||
Pinned threads still move to **Settled** when they become inactive. They also move when their pull
|
||||
request merges if **Auto-settle merged threads** is enabled.
|
||||
|
||||
When you un-settle a thread, it returns to the top of the active list so you can find it right
|
||||
away. Its timestamps do not change. Other threads keep their positions.
|
||||
|
||||
Right-click a pull request link in a thread and choose **Link to thread** to show that pull request
|
||||
in the sidebar. The thread settles when the linked pull request merges if **Auto-settle merged
|
||||
threads** is enabled. Right-click the same link and choose **Unlink from thread** to remove it.
|
||||
|
||||
@@ -92,6 +92,7 @@ export function applyThreadDetailEvent(
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
unsettledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
deletedAt: null,
|
||||
@@ -130,6 +131,7 @@ export function applyThreadDetailEvent(
|
||||
...thread,
|
||||
settledOverride: "settled",
|
||||
settledAt: event.payload.settledAt,
|
||||
unsettledAt: null,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
},
|
||||
};
|
||||
@@ -141,6 +143,12 @@ export function applyThreadDetailEvent(
|
||||
...thread,
|
||||
settledOverride: event.payload.reason === "user" ? "active" : null,
|
||||
settledAt: null,
|
||||
// A thread already pinned active keeps its re-entry stamp: the
|
||||
// activity reset that clears the pin must not reorder the list.
|
||||
unsettledAt:
|
||||
thread.settledOverride === "active"
|
||||
? (thread.unsettledAt ?? null)
|
||||
: event.payload.updatedAt,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -69,6 +69,24 @@ export function getThreadSortTimestamp(
|
||||
return getLatestUserMessageTimestamp(thread);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort anchor for the active thread list: creation time, re-anchored to
|
||||
* unsettledAt when the thread last re-entered the active list (an explicit
|
||||
* un-settle, or a settled thread waking on activity). The list stays static
|
||||
* between lifecycle transitions, but an un-settled thread surfaces at the
|
||||
* top instead of sinking back to its creation-order slot. Shared by web and
|
||||
* mobile so both render the same order. Malformed timestamps sink to 0.
|
||||
*/
|
||||
export function activeThreadAnchorTimestampMs(thread: {
|
||||
readonly createdAt: string;
|
||||
readonly unsettledAt?: string | null | undefined;
|
||||
}): number {
|
||||
return Math.max(
|
||||
toSortableTimestamp(thread.createdAt) ?? 0,
|
||||
toSortableTimestamp(thread.unsettledAt ?? undefined) ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
export function sortThreads<T extends { readonly id: string } & ThreadSortInput>(
|
||||
threads: readonly T[],
|
||||
sortOrder: SidebarThreadSortOrder,
|
||||
|
||||
@@ -415,6 +415,11 @@ export const OrchestrationThread = Schema.Struct({
|
||||
Schema.withDecodingDefault(Effect.succeed(null)),
|
||||
),
|
||||
settledAt: Schema.NullOr(IsoDateTime).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
|
||||
// When the thread last re-entered the active list (any thread.unsettled).
|
||||
// Anchors the active-list sort so an unsettled thread surfaces at the top
|
||||
// instead of sinking back to its creation-order slot. Cleared on settle.
|
||||
// Optional so payloads from pre-stamp servers still decode.
|
||||
unsettledAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
// Snooze is an overlay on the active lifecycle, not a fourth destination:
|
||||
// a snoozed thread stays "active" in the model and is only suppressed from
|
||||
// the inbox until snoozedUntil passes (or the thread raises its hand).
|
||||
@@ -486,6 +491,8 @@ export const OrchestrationThreadShell = Schema.Struct({
|
||||
Schema.withDecodingDefault(Effect.succeed(null)),
|
||||
),
|
||||
settledAt: Schema.NullOr(IsoDateTime).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
|
||||
// See OrchestrationThread.unsettledAt: last re-entry into the active list.
|
||||
unsettledAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
snoozedUntil: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
snoozedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
pinnedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
|
||||
|
||||
Reference in new issue
Block a user