Skip to content

fix(db): clear the ready marker when the database starts - #5421

Merged
yannickmonney merged 1 commit into
mainfrom
fix/db-ready-marker
Nov 12, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/db-ready-marker

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Summary

The database entrypoint only ever created the ready marker /tmp/.db_ready; nothing cleared it. /tmp outlives a stop whenever the runtime keeps the container's filesystem, as docker restart does, so a restarted database read the previous start's marker and reported ready (HEALTHCHECK, compose waits, CLI and CI waits) as soon as Postgres answered, before this start's init scripts and migrations had run.

The fix clears the marker with a top-level rm -f /tmp/.db_ready before the background init block, so the marker only exists once this start's init has finished. services/db gains a test script and a Bun test for the entrypoint.

Checklist

  • bun run check passes — the new and touched parts pass; on the test VM the remaining failures (@tale/cli#test, @tale/platform#test:ui, @tale/session-manager#test) are the same on a clean origin/main worktree there (VM environment: no docker compose plugin, memory, timing) and none depends on @tale/db. CI is the reference.
  • bun run lint:sast — N/A: a shell line and a test; no SAST-relevant surface.
  • Translations — N/A: no user-visible string.
  • Docs — N/A: the documented behaviour ("Wait for initialization": wait for /tmp/.db_ready) stays true and now also holds after a restart.
  • README — N/A: no change in usage.

Test plan

  • bun test services/db: 2 tests pass (run 3 times). A structural test checks that the clear is a top-level line before the background block and its touch; a behavioural test runs the real entrypoint twice under bash with a fake server: on the restart the server starts with no marker, and the marker returns once init has finished. With the fix reverted, both tests fail (the restart reads the stale marker).
  • shellcheck, oxfmt, oxlint and a strict ad hoc tsc on the new test: clean. knip, format:check, lint:conflicts, lint:links: clean. commitlint: clean.
  • Real container: built the db image from main and from this branch, ran each, then docker restart. On main the marker was present in every sample taken while pg_isready answered and before the second Database ready.; with the fix it was absent in every such sample and present after init finished.

The entrypoint only ever touched /tmp/.db_ready. /tmp outlives a stop
whenever the runtime keeps the container's filesystem, as `docker
restart` does, so a restarted database read the previous start's marker
and reported ready as soon as Postgres answered, before this start's
init scripts and migrations ran. Clear the marker before the background
init block.

services/db gains a test script. Its Bun test checks that the clear is a
top-level line before the background block and its touch, and runs the
real entrypoint twice with a fake server: on the restart the server
starts with no marker, and the marker returns once init has finished.
@yannickmonney
yannickmonney enabled auto-merge (squash) November 12, 2026 15:51
@yannickmonney
yannickmonney merged commit b682881 into main Nov 12, 2026
85 checks passed
@yannickmonney
yannickmonney deleted the fix/db-ready-marker branch November 12, 2026 16:22
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