Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): avoid completed-item scans when starting turns #23557

Closedjuliusmarmingewants to merge 3 commits intomain fromfix/issue-21578opened View on GitHub

Showing 4 changed files with 40 additions and 1 deletion (loading 1).

x
0 of 4 viewed, 4 left
24 additions and 1 deletionapps/server/src/orchestration-v2/ProjectionStore.test.tsModified
View file
@@ -3115,7 +3115,30 @@
assert.include(recoveryThreadIds, childThreadId);
assert.notInclude(recoveryThreadIds, settledThreadId);
assert.notInclude(recoveryThreadIds, rolledBackThreadId);
- const memberRecovery = yield* projectionStore.getRuntimeRecoveryProjection(memberThreadId);
+ const { statements, tracer } = traceSqlStatements();
+ const memberRecovery = yield* projectionStore
+ .getRuntimeRecoveryProjection(memberThreadId)
+ .pipe(Effect.withTracer(tracer));
+ // Completed history grows without bound, so the provider-thread read's
+ // unfinished-item lookups must stay on a partial index.
+ const providerThreadRead = statements.find((query) =>
+ query.includes("SELECT provider_thread.payload_json"),
+ );
+ assert.isDefined(providerThreadRead);
+ const sql = yield* SqlClient.SqlClient;
+ const itemLookups = (yield* sql.unsafe<{ readonly detail: string }>(
+ `EXPLAIN QUERY PLAN ${providerThreadRead}`,
+ ))
+ .map((row) => row.detail)
+ .filter((detail) => /^(SEARCH|SCAN) item /.test(detail));
+ assert.isNotEmpty(itemLookups);
+ for (const detail of itemLookups) {
+ const indexName = /INDEX (\S+)/.exec(detail)?.[1] ?? "";
+ const [index] = yield* sql<{ readonly sql: string }>`
+ SELECT sql FROM sqlite_master WHERE type = 'index' AND name = ${indexName}
+ `;
+ assert.match(index?.sql ?? "", /WHERE[\s\S]*status/, detail);
+ }
const childRecovery = yield* projectionStore.getRuntimeRecoveryProjection(childThreadId);