diff --git a/packages/core/migrations/meta/0009_snapshot.json b/packages/core/migrations/meta/0009_snapshot.json index d1b56e7c..9c9a5fac 100644 --- a/packages/core/migrations/meta/0009_snapshot.json +++ b/packages/core/migrations/meta/0009_snapshot.json @@ -1219,6 +1219,12 @@ "type": "text", "primaryKey": false, "notNull": false + }, + "claim_token": { + "name": "claim_token", + "type": "text", + "primaryKey": false, + "notNull": false } }, "indexes": { @@ -2313,4 +2319,4 @@ "schemas": {}, "tables": {} } -} \ No newline at end of file +} diff --git a/packages/core/src/session/session.sql.ts b/packages/core/src/session/session.sql.ts index 9c4c31fc..8017f80f 100644 --- a/packages/core/src/session/session.sql.ts +++ b/packages/core/src/session/session.sql.ts @@ -62,7 +62,17 @@ export const SessionTable = pgTable( timeStarted: utc('time_started'), timeStopped: utc('time_stopped'), /** Why it ended badly, when it did. */ - errorMessage: text('error_message') + errorMessage: text('error_message'), + /** + * Which attempt holds this run. Null until an agent claims it, and never + * cleared afterwards — a terminal row still records who ran it, and a + * token that goes back to null lets a dead claim be replayed. + * + * Nothing writes it yet. It is declared here so the schema, the snapshot + * and the database agree; without it the next generated migration adds a + * column that already exists and fails wherever it has run once. + */ + claimToken: text('claim_token') }, (t) => [ index('session_box_idx').on(t.boxId),