@devries-cameron20 / t3code Mirror · read-only / commits / 570640b160
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 21, 11:00 UTC

perf(server): active thread reads filter on the archived_at column (#28992)

Mahir Taha Özdin committed Nov 15, 2026 at 11:02 UTC 570640b1605e7f52cbaeed41940961b0dc946b51
4 files changed +39 -18
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+22 -11
@@ -8470,21 +8470,32 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
8470 const [originalRow] = yield* sql<{
8471 payload_json: string;
8472 }>`SELECT payload_json FROM orchestration_v2_projection_threads WHERE thread_id = ${threadId}`;
8473 - for (const [field, value] of [
8474 - ["archivedAt", DateTime.formatIso(now)],
8475 - ["settledOverride", "settled"],
8476 - ]) {
8477 - yield* sql`UPDATE orchestration_v2_projection_threads
8478 - SET payload_json = json_set(payload_json, ${`$.${field}`}, ${value})
8479 - WHERE thread_id = ${threadId}`;
8480 - assert.isUndefined(
8481 - (yield* store.getLimitRecoveryCandidates({ now, autoResume: true, snooze: false })).find(
8473 + const limitThread = (yield* store.getThreadProjection(threadId)).thread;
8474 + for (const archivedAt of [now, null]) {
8475 + yield* store.apply({
8476 + id: EventId.make(`event:limit-shell:archived:${archivedAt !== null}`),
8477 + type: archivedAt === null ? "thread.unarchived" : "thread.archived",
8478 + threadId,
8479 + occurredAt: now,
8480 + payload: { ...limitThread, archivedAt },
8481 + });
8482 + assert.strictEqual(
8483 + (yield* store.getLimitRecoveryCandidates({ now, autoResume: true, snooze: false })).some(
8484 (row) => row.id === threadId,
8485 ),
8486 + archivedAt === null,
8487 );
8485 - yield* sql`UPDATE orchestration_v2_projection_threads
8486 - SET payload_json = ${originalRow!.payload_json} WHERE thread_id = ${threadId}`;
8488 }
8489 + yield* sql`UPDATE orchestration_v2_projection_threads
8490 + SET payload_json = json_set(payload_json, '$.settledOverride', 'settled')
8491 + WHERE thread_id = ${threadId}`;
8492 + assert.isUndefined(
8493 + (yield* store.getLimitRecoveryCandidates({ now, autoResume: true, snooze: false })).find(
8494 + (row) => row.id === threadId,
8495 + ),
8496 + );
8497 + yield* sql`UPDATE orchestration_v2_projection_threads
8498 + SET payload_json = ${originalRow!.payload_json} WHERE thread_id = ${threadId}`;
8499 yield* sql`UPDATE orchestration_v2_projection_threads SET deleted_at = ${DateTime.formatIso(now)} WHERE thread_id = ${threadId}`;
8500 assert.isUndefined(
8501 (yield* store.getLimitRecoveryCandidates({ now, autoResume: true, snooze: false })).find(
apps/server/src/orchestration-v2/ProjectionStore.ts
+4 -4
@@ -4666,7 +4666,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
4666 WHERE failure.type = 'error' AND failure.status = 'failed'
4667 AND json_extract(failure.payload_json, '$.failure.class') = 'usage_limit'
4668 )
4669 - AND json_extract(t.payload_json, '$.archivedAt') IS NULL
4669 + AND t.archived_at IS NULL
4670 AND json_extract(t.payload_json, '$.settledOverride') IS NOT 'settled'
4671 AND json_extract(item.payload_json, '$.failure.class') = 'usage_limit'
4672 AND json_extract(item.payload_json, '$.failure.resetAt') IS NOT NULL
@@ -8459,7 +8459,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
8459 SELECT thread_id, json_extract(payload_json, '$.worktreePath') AS worktree_path
8460 FROM orchestration_v2_projection_threads
8461 WHERE deleted_at IS NULL
8462 - ${options?.includeArchived === true ? sql`` : sql`AND json_extract(payload_json, '$.archivedAt') IS NULL`}
8462 + ${options?.includeArchived === true ? sql`` : sql`AND archived_at IS NULL`}
8463 AND json_extract(payload_json, '$.worktreePath') IS NOT NULL
8464 `.pipe(
8465 Effect.map((rows) =>
@@ -8911,7 +8911,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
8911 SELECT thread_id
8912 FROM orchestration_v2_projection_threads
8913 WHERE deleted_at IS NULL
8914 - AND json_extract(payload_json, '$.archivedAt') IS NULL
8914 + AND archived_at IS NULL
8915 AND json_extract(payload_json, '$.lineage.relationshipToParent') = 'subagent'
8916 `;
8917 return rows.map((row) => ThreadId.make(row.thread_id));
@@ -9131,7 +9131,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
9131 json_extract(t.payload_json, '$.settledAt') AS settled_at
9132 FROM orchestration_v2_projection_threads t
9133 WHERE t.deleted_at IS NULL
9134 - AND json_extract(t.payload_json, '$.archivedAt') IS NULL
9134 + AND t.archived_at IS NULL
9135 AND json_extract(t.payload_json, '$.lineage.relationshipToParent') IS NOT 'subagent'
9136 AND json_extract(t.payload_json, '$.lineage.sideChat') IS NOT 1
9137 AND json_extract(t.payload_json, '$.settledOverride') = 'settled'
apps/server/src/orchestration-v2/ThreadSearch.test.ts
+11 -1
@@ -1149,12 +1149,22 @@ it.layer(layerTest)("ThreadSearch.searchOlderSettled", (it) => {
1149 thread(id("elsewhere"), other, { title: "Kestrel nest", settledAt: old }),
1150 thread(id("note"), project, { title: "Unrelated", settledAt: old }),
1151 thread(id("new-note"), project, { title: "Unrelated", settledAt: at(50) }),
1152 + thread(id("archived"), project, {
1153 + title: "Kestrel nest",
1154 + settledAt: old,
1155 + archivedAt: old,
1156 + }),
1157 + thread(id("archived-note"), project, {
1158 + title: "Unrelated",
1159 + settledAt: old,
1160 + archivedAt: old,
1161 + }),
1162 ],
1163 projections.apply,
1164 { discard: true },
1165 );
1166 const before = DateTime.formatIso(at(30));
1157 - const messageThreadIds = [id("new-note"), id("note"), id("old")];
1167 + const messageThreadIds = [id("new-note"), id("note"), id("archived-note"), id("old")];
1168 assert.sameMembers(
1169 [...(yield* search.searchOlderSettled({ query: "kestrel", before, messageThreadIds }))],
1170 [id("old"), id("elsewhere"), id("note")],
apps/server/src/orchestration-v2/ThreadSearch.ts
+2 -2
@@ -450,7 +450,7 @@ export const make = Effect.gen(function* () {
450 INNER JOIN projection_projects AS projects
451 ON projects.project_id = threads.project_id
452 WHERE threads.deleted_at IS NULL
453 - AND json_extract(threads.payload_json, '$.archivedAt') IS NULL
453 + AND threads.archived_at IS NULL
454 AND projects.deleted_at IS NULL
455 AND json_extract(threads.payload_json, '$.lineage.relationshipToParent')
456 IS NOT 'subagent'
@@ -474,7 +474,7 @@ export const make = Effect.gen(function* () {
474 FROM orchestration_v2_projection_threads AS threads
475 WHERE threads.thread_id IN (SELECT value FROM json_each(${threadIds}))
476 AND threads.deleted_at IS NULL
477 - AND json_extract(threads.payload_json, '$.archivedAt') IS NULL
477 + AND threads.archived_at IS NULL
478 AND json_extract(threads.payload_json, '$.lineage.relationshipToParent')
479 IS NOT 'subagent'
480 AND json_extract(threads.payload_json, '$.lineage.sideChat') IS NOT 1