Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Set lock_timeout in Postgres migrations so waiting DDL fails fast.

debajyoti-truefoundry63b4e5f16e96
diff --git a/packages/server/src/db/postgres/AGENTS.md b/packages/server/src/db/postgres/AGENTS.md
index 4ad5a6dce..e6bc31ffd 100644
--- a/packages/server/src/db/postgres/AGENTS.md
+++ b/packages/server/src/db/postgres/AGENTS.md
@@ -1,3 +1,4 @@
- Temporal columns MUST use `timestamptz` (`timestamp with time zone`). Do not use `timestamp` without time zone.
- Application timestamps MUST be treated as UTC instants. Serialize with `Date.prototype.toISOString()` (always `...Z` with milliseconds).
- Do not run DB queries inside loops (N+1). Prefer a single batched query, a join, or an `IN`/`ANY` lookup over per-item round-trips.
+- Postgres migrations MUST start `up`/`down` with `SET LOCAL lock_timeout = '5s'` so waiting DDL fails fast instead of blocking later queries (including `SELECT`s) behind it in the lock queue.
diff --git a/packages/server/src/db/postgres/migrations/20260727_000001_init.ts b/packages/server/src/db/postgres/migrations/20260727_000001_init.ts
index d7dfc8500..b220d4a9d 100644
--- a/packages/server/src/db/postgres/migrations/20260727_000001_init.ts
+++ b/packages/server/src/db/postgres/migrations/20260727_000001_init.ts
@@ -1,9 +1,11 @@
import { type Kysely, sql } from 'kysely';
export async function up(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await sql`SELECT 1`.execute(db);
}
export async function down(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await sql`SELECT 1`.execute(db);
}
diff --git a/packages/server/src/db/postgres/migrations/20260728_000001_session_store.ts b/packages/server/src/db/postgres/migrations/20260728_000001_session_store.ts
index 0e4505b2d..616da8415 100644
--- a/packages/server/src/db/postgres/migrations/20260728_000001_session_store.ts
+++ b/packages/server/src/db/postgres/migrations/20260728_000001_session_store.ts
@@ -18,6 +18,7 @@ import { sql, type Kysely } from 'kysely';
* store-owned, `custom` is caller-owned.
*/
export async function up(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema
.createTable('session')
// key
@@ -237,6 +238,7 @@ export async function up(db: Kysely<unknown>): Promise<void> {
}
export async function down(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema.dropTable('thread_capability_state').ifExists().cascade().execute();
await db.schema.dropTable('thread_context_log').ifExists().cascade().execute();
await db.schema.dropTable('session_event').ifExists().cascade().execute();
diff --git a/packages/server/src/db/postgres/migrations/20260803_000001_mcp_oauth.ts b/packages/server/src/db/postgres/migrations/20260803_000001_mcp_oauth.ts
index 002f8a30e..4b775b647 100644
--- a/packages/server/src/db/postgres/migrations/20260803_000001_mcp_oauth.ts
+++ b/packages/server/src/db/postgres/migrations/20260803_000001_mcp_oauth.ts
@@ -1,6 +1,7 @@
-import type { Kysely } from 'kysely';
+import { sql, type Kysely } from 'kysely';
export async function up(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema
.createTable('mcp_server')
.addColumn('id', 'text', c => c.notNull())
@@ -40,6 +41,7 @@ export async function up(db: Kysely<unknown>): Promise<void> {
}
export async function down(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema.dropTable('oauth_pending_authorization').ifExists().cascade().execute();
await db.schema.dropTable('oauth_token').ifExists().cascade().execute();
await db.schema.dropTable('mcp_server').ifExists().cascade().execute();
diff --git a/packages/server/src/db/postgres/migrations/20260803_000001_model_provider.ts b/packages/server/src/db/postgres/migrations/20260803_000001_model_provider.ts
index 26e3630a1..6904c13b2 100644
--- a/packages/server/src/db/postgres/migrations/20260803_000001_model_provider.ts
+++ b/packages/server/src/db/postgres/migrations/20260803_000001_model_provider.ts
@@ -1,4 +1,4 @@
-import type { Kysely } from 'kysely';
+import { sql, type Kysely } from 'kysely';
/**
* Configured model providers (canonical DDL owner).
@@ -9,6 +9,7 @@ import type { Kysely } from 'kysely';
* so future manifest fields are schema changes, not migrations.
*/
export async function up(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema
.createTable('model_provider')
// key
@@ -24,5 +25,6 @@ export async function up(db: Kysely<unknown>): Promise<void> {
}
export async function down(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema.dropTable('model_provider').ifExists().cascade().execute();
}
diff --git a/packages/server/src/db/postgres/migrations/20260803_000002_session_scoped_keys.ts b/packages/server/src/db/postgres/migrations/20260803_000002_session_scoped_keys.ts
index 6be84da88..88719fa98 100644
--- a/packages/server/src/db/postgres/migrations/20260803_000002_session_scoped_keys.ts
+++ b/packages/server/src/db/postgres/migrations/20260803_000002_session_scoped_keys.ts
@@ -1,7 +1,8 @@
-import type { Kysely } from 'kysely';
+import { sql, type Kysely } from 'kysely';
/** Drop tenant_id from turn-scoped tables; session_id is globally unique with cascade FKs. */
export async function up(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
// Index includes tenant_id; drop before reshaping turn.
await db.schema.dropIndex('turn_list_idx').execute();
diff --git a/packages/server/src/db/postgres/migrations/20260808_000001_skill.ts b/packages/server/src/db/postgres/migrations/20260808_000001_skill.ts
index 2dc58f6d3..ad0ad0da8 100644
--- a/packages/server/src/db/postgres/migrations/20260808_000001_skill.ts
+++ b/packages/server/src/db/postgres/migrations/20260808_000001_skill.ts
@@ -1,4 +1,4 @@
-import type { Kysely } from 'kysely';
+import { sql, type Kysely } from 'kysely';
/**
* Configured skills (canonical DDL owner).
@@ -9,6 +9,7 @@ import type { Kysely } from 'kysely';
* the Zod layer — so future manifest fields are schema changes, not migrations.
*/
export async function up(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema
.createTable('skill')
.addColumn('tenant_id', 'text', col => col.notNull())
@@ -21,5 +22,6 @@ export async function up(db: Kysely<unknown>): Promise<void> {
}
export async function down(db: Kysely<unknown>): Promise<void> {
+ await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema.dropTable('skill').ifExists().cascade().execute();
}