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 22, 10:45 UTC
fix(server): cache absent legacy transcripts for V2 threads (#24707)
Scott Norteman committed
Oct 30, 2026 at 17:07 UTC
e6fcceea59a062657421e3cf1c68772c66d4bff3
2 files changed
+67
-4
apps/server/src/orchestration-v2/legacy/LegacyV1ThreadImporter.test.ts
+65
@@ -2,6 +2,8 @@ import { assert, it } from "@effect/vitest";
2
import {
3
ComposerContextId,
4
EventId,
5
+ ProjectId,
6
+ ProviderInstanceId,
7
type OrchestrationMessageContext,
8
ThreadId,
9
} from "@t3tools/contracts";
@@ -150,6 +152,69 @@ it.effect("propagates interruption from transcript reads and retry-marker writes
152
}).pipe(Effect.provide(layerTest)),
153
);
154
155
+it.effect("caches the absent legacy transcript for a native V2 thread", () =>
156
+ Effect.gen(function* () {
157
+ const importer = yield* LegacyV1ThreadImporter.LegacyV1ThreadImporter;
158
+ const eventSink = yield* EventSink.EventSinkV2;
159
+ const projections = yield* ProjectionStore.ProjectionStoreV2;
160
+ const threadId = ThreadId.make("thread:v2-born");
161
+ const providerInstanceId = ProviderInstanceId.make("codex");
162
+ const now = DateTime.makeUnsafe("2026-01-01T00:00:00.000Z");
163
+ yield* eventSink.write({
164
+ events: [
165
+ {
166
+ id: EventId.make("event:v2-born"),
167
+ type: "thread.created",
168
+ threadId,
169
+ occurredAt: now,
170
+ payload: {
171
+ id: threadId,
172
+ projectId: ProjectId.make("project:v2-born"),
173
+ title: "Native V2 thread",
174
+ providerInstanceId,
175
+ modelSelection: { instanceId: providerInstanceId, model: "gpt-6" },
176
+ createdBy: "user",
177
+ creationSource: "web",
178
+ runtimeMode: "full-access",
179
+ interactionMode: "default",
180
+ branch: null,
181
+ worktreePath: null,
182
+ activeProviderThreadId: null,
183
+ lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
184
+ forkedFrom: null,
185
+ createdAt: now,
186
+ updatedAt: now,
187
+ archivedAt: null,
188
+ settledOverride: null,
189
+ settledAt: null,
190
+ lastVisitedAt: null,
191
+ deletedAt: null,
192
+ },
193
+ },
194
+ ],
195
+ });
196
+ const before = yield* projections.getThreadProjection(threadId);
197
+ let legacyLookups = 0;
198
+ for (let read = 0; read < 3; read++) {
199
+ const summary = yield* importer.ensureTranscript(threadId).pipe(
200
+ Effect.provideService(Statement.CurrentTransformer, (statement) => {
201
+ const [query, parameters] = statement.compile();
202
+ if (
203
+ query.includes("FROM orchestration_v2_legacy_imports") &&
204
+ parameters[0] === threadId
205
+ ) {
206
+ legacyLookups++;
207
+ }
208
+ return Effect.succeed(statement);
209
+ }),
210
+ );
211
+ assert.deepStrictEqual(summary, { importedThreadCount: 0, importedMessageCount: 0 });
212
+ }
213
+ assert.equal(legacyLookups, 1);
214
+ assert.deepStrictEqual(yield* projections.getThreadProjection(threadId), before);
215
+ }).pipe(Effect.provide(layerTest)),
216
+);
217
+
218
it.layer(layerTest)("LegacyV1ThreadImporter", (it) => {
219
it.effect("imports lightweight shells, hydrates transcripts, and remains idempotent", () =>
220
Effect.gen(function* () {
apps/server/src/orchestration-v2/legacy/LegacyV1ThreadImporter.ts
+2
-4
@@ -677,7 +677,7 @@ const make = Effect.gen(function* () {
677
),
678
);
679
680
- // transcript_imported_at never resets; cache confirmed imports for the process lifetime to skip repeated locks and reads.
680
+ // Both results are final for this process: transcript_imported_at never resets, and only startup shell reconciliation creates legacy rows.
681
const confirmedTranscriptThreadIds = new Set<ThreadId>();
682
683
const ensureTranscriptBase = (threadId: ThreadId) =>
@@ -692,9 +692,7 @@ const make = Effect.gen(function* () {
692
`.pipe(NodeSqliteClient.readOnly);
693
const imported = imports[0];
694
if (imported === undefined || imported.transcript_imported_at !== null) {
695
- if (imported !== undefined) {
696
- confirmedTranscriptThreadIds.add(threadId);
697
- }
695
+ confirmedTranscriptThreadIds.add(threadId);
696
return { importedThreadCount: 0, importedMessageCount: 0 };
697
}
698
const messages = yield* listMessages(threadId);