Skip to content

Reset database state before replacement workers fork - #56

Merged
knifecake merged 1 commit into
mainfrom
fix/reset-before-replacement-fork
Sep 6, 2026
Merged

knifecake merged 1 commit into
mainfrom
fix/reset-before-replacement-fork

Conversation

@knifecake

Copy link
Copy Markdown
Owner

When a supervised worker dies, replace_fork() queries the database to recover its claimed jobs. This reopens the PostgreSQL connection and pool after the startup cleanup, and start_process() previously forked before resetting that state in the parent.

Reset database connections and pool caches immediately before each os.fork(). Keep the existing startup, parent, and child cleanup, and preserve pooling configuration.

Add PostgreSQL transaction tests that use real connections and pools and intercept only os.fork(). They verify cleanup at the fork boundary for direct starts and replacements following claimed-job recovery, preservation of pooling options, and successful recovery of the dead worker's job. Both tests failed on the prior implementation with an open psycopg connection at the fork boundary.

Validation:

  • Full suite on isolated PostgreSQL 17.4: 166 tests passed (uv run python runtests.py with database URLs on port 55439).
  • make lint and commit hooks passed.
  • Manual macOS/Python 3.12 smoke test with a real supervisor: killed its idle worker, observed a replacement register and successfully execute a job, then confirmed graceful supervisor exit with status 0.

Related to #48; intentionally leaves it open. This fixes a demonstrated cleanup-ordering gap, not a reproduced macOS SIGSEGV. It does not establish that forking alongside background threads is safe or eliminate every possible source of inherited state.

@knifecake
knifecake marked this pull request as ready for review September 6, 2026 18:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T18:17:35.649071Z a2fef57 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@knifecake
knifecake merged commit 2e1c328 into main Sep 6, 2026
3 checks passed
@knifecake
knifecake deleted the fix/reset-before-replacement-fork branch September 6, 2026 18:21
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