agent-native icon indicating copy to clipboard operation
agent-native copied to clipboard

[core/db] Retry transient 55P03 lock_timeout in ensureSchemaObject / runGuardedDdl during migrations

Open fogbreak-io opened this issue 2 weeks ago • 1 comments

Package: @agent-native/[email protected] (PostgreSQL / Neon)

Summary

During production migrations across a multi-app workspace against a shared PostgreSQL database with live traffic, ensureColumnExists on application_state can fail with a DDL lock timeout (55P03) instead of retrying after a brief backoff.

Verified source details (@agent-native/[email protected])

  • dist/db/ddl-guard.js:383: runGuardedDdl defaults lockTimeout to "3s" (SET LOCAL lock_timeout = '${lockTimeout}' at :391).
  • dist/db/ddl-guard.js:374-380,407-410: isLockTimeoutError catches 55P03 / canceling statement due to lock timeout and returns false.
  • dist/db/ddl-guard.js:270-290: ensureSchemaObject does not retry after runGuardedDdl returns false, re-probes once, and throws ensureSchemaObject: required schema "column application_state.writer" is still missing after a lock-timed-out DDL.
  • dist/db/runtime-facts.js:6-35: retryOnDdlRace (:6-14) only retries isPgCatalogRace (42P07, 42710, 23505 on pg_type/pg_class), not 55P03 / lock timeouts.

Suggested improvement

Retry transient 55P03 / lock_timeout DDL failures with bounded backoff (and/or allow configurable migration lock_timeout) inside ensureSchemaObject / runGuardedDdl or retryOnDdlRace, so transient read/transaction locks on active tables like application_state do not abort production migrations on the first 3-second contention window.

fogbreak-io avatar Nov 15 '26 12:11 fogbreak-io

Thanks — a change to retry transient migration lock timeouts is in review at https://github.com/BuilderIO/agent-native/pull/9194; the production cause remains unconfirmed.

builder-factory avatar Nov 15 '26 13:11 builder-factory