From dba56bafa3119833e0497177defcb8760f6ddd21 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sat, 25 Jul 2026 23:17:36 -0700 Subject: [PATCH] Mirror the server's turn-id guard when settling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Self-review of the settle path, which has been the source of every regression in this branch. The server filters `turnId !== null && state === "running"` before settling; this filtered only on state. No row is both null-id and running today — the sole null-id insert writes 'pending' — so this changes no behavior. It is the invariant the UPDATE already depends on, written down where it is relied upon, and it keeps the two predicates directly comparable if a null-id running row ever becomes possible. Co-Authored-By: Claude Opus 5 (1M context) --- scripts/lib/dev-seed.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/lib/dev-seed.ts b/scripts/lib/dev-seed.ts index 0819408e1c..b111292162 100644 --- a/scripts/lib/dev-seed.ts +++ b/scripts/lib/dev-seed.ts @@ -256,6 +256,12 @@ function settleRunningTurns( const setCompletedAt = hasColumn(target, "projection_turns", "completed_at") ? `, completed_at = requested_at` : ""; + // `turn_id IS NOT NULL` mirrors the server's own settle filter + // (ProjectionPipeline, on the session leaving "running"). No writer produces + // a row that is both null-id and running today — the only null-id insert + // writes 'pending' — so this is guarding the invariant rather than a case, + // and it keeps the two predicates comparable if that ever changes. + // // 'running' is inlined, not bound: `--threads` is capped at SQLite's variable // ceiling, so every binding beyond one per thread puts the maximum over the // limit. Safe to interpolate — an internal literal, never input. @@ -263,6 +269,7 @@ function settleRunningTurns( .prepare( `UPDATE projection_turns SET state = 'interrupted'${setCompletedAt} WHERE state = 'running' + AND turn_id IS NOT NULL AND thread_id IN (${placeholders(threadIds.length)})`, ) .run(...threadIds);