Skip to content

Track live PostgreSQL readiness - #1602

Open
snevolin wants to merge 1 commit into
gonka-ai:upgrade-v0.2.15from
snevolin:sn/postgres-live-readiness
Open

Track live PostgreSQL readiness#1602
snevolin wants to merge 1 commit into
gonka-ai:upgrade-v0.2.15from
snevolin:sn/postgres-live-readiness

Conversation

@snevolin

@snevolin snevolin commented Aug 18, 2026

Copy link
Copy Markdown

Summary

This focused PR is based on the PostgreSQL live-readiness work originally implemented in the closed umbrella PRs #1517 and #1587.

Track the live PostgreSQL connection after devshard storage has started:

  • probe the pool periodically with bounded Ping calls;
  • mark storage unready after two consecutive failures;
  • restore readiness after two consecutive successful probes;
  • stop and join the monitor when PostgreSQL storage is closed;
  • keep SQLite-only storage behavior unchanged.

Why

Previously, PostgreSQL readiness represented only successful startup and completion of the initial session-index rebuild. If the database became unavailable later, devshardd stayed alive and could continue reporting ready from stale startup state.

The process should remain alive so a transient database outage does not cause a restart loop, while readiness-aware routing must be able to withdraw it until PostgreSQL recovers.

Behavior

This applies whenever a live PostgreSQL backend is attached. In fail-closed DEVSHARD_STORAGE_MODE=postgres, database loss makes /readyz unready without terminating devshardd, and readiness recovers automatically when the database returns. Hybrid storage uses the same PostgreSQL signal while attached. SQLite-only mode is unaffected.

This PR does not change storage-mode selection, compare database identities, migrate SQL data, or change the PostgreSQL data-directory layout.

Validation

  • go test -race ./storage
  • unit coverage for readiness hysteresis;
  • integration coverage for runtime PostgreSQL loss and recovery.

History

This focused PR extracts the PostgreSQL live-readiness work previously developed in the closed umbrella PRs #1517 and #1587 so it can be reviewed and merged independently.

Probe the devshard PostgreSQL pool in the background so readiness reflects a database outage that happens after startup instead of remaining latched forever.

Use two-sample failure and recovery hysteresis to avoid flapping, combine the result with session-index readiness, and stop the monitor cleanly when storage closes.

Add a unit test for the hysteresis state machine and a Docker test that verifies readiness withdrawal when the live database stops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant