Skip to content

fix(events): raise a database outage from record_queued_in - #78

Merged
joaovitoriasilva merged 1 commit into
mainfrom
fix/event-log-database-outage
Nov 24, 2026
Merged

joaovitoriasilva merged 1 commit into
mainfrom
fix/event-log-database-outage

Conversation

@joaovitoriasilva

@joaovitoriasilva joaovitoriasilva commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

EventLogRecorder.record_queued_in writes the durable queued event-log row on the producer's session, inside a savepoint. It logged and swallowed every error, including a lost connection.

The savepoint protects the producer's transaction from a bad event-log write, but not from losing the connection. When PostgreSQL reset the connection mid-write:

  1. SQLAlchemy invalidated the connection.
  2. The OperationalError was logged as a warning and swallowed.
  3. The producer's commit then raised PendingRollbackError.

is_database_unavailable returns false for PendingRollbackError, so a host can't tell it from a bug. Endurain answered 500 with an ERROR log where every other request hit by the same reset got a 503. The Endurain load test's postgres_faults scenario found this on 0.24.0.

Now, when is_database_unavailable is true for the error, record_queued_in re-raises it. publish_committing, publish_on_commit and their batch forms then raise the original OperationalError, which hosts already treat as an outage. Any other event-log error is still logged and swallowed. publish with a db still logs and swallows the error, as documented.

This PR also releases 0.24.1. The version is bumped in pyproject.toml, uv.lock, README.md and docs/index.md, with a CHANGELOG.md entry.

Related issue

None is open. This comes from an Endurain load-test hand-off.

Type of change

  • Bug fix
  • New feature (exception during freeze; link prior discussion/acknowledgment)
  • Documentation
  • Refactor / code quality
  • Translation
  • Other (describe below)

Checklist

  • This PR is focused on a single concern
  • An issue was opened and acknowledged before writing this code (if not a small fix)
  • If this PR introduces a new feature during freeze, it was discussed and explicitly acknowledged first
  • The PR is under ~300 lines changed, excluding lock files, migrations, and generated code
  • Tests have been added or updated where applicable
  • Documentation has been updated where applicable
  • Commit messages follow Conventional Commits format

Notes for the reviewer

  • The test raises the dialect's own driver OperationalError on the jasil_event_log insert. A handle_error hook marks it as a disconnect, so SQLAlchemy wraps it and invalidates the connection the way it does for a real reset. It should work on every database in the CI matrix. Without the fix, it reproduces the reported sequence: a warning, then PendingRollbackError on the caller's commit.
  • The other best-effort writes (audit, dead-letter delivery, relay, reaper, retention) open their own sessions, so a failure there cannot leave the caller's session unusable.
  • Patch, not minor: no API changes. On the durable route these calls already raised in this situation, and now they raise the outage error itself.

Ran locally on SQLite: ruff check, ruff format --check, lint-imports, mypy, pytest (4,364 passed, 149 skipped, coverage 97.95%), check_module_coverage.py and check_docs_api.py. The version bump came after that run. uv lock --check passed on the bumped version.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Database-unavailability errors during queued event-log recording now propagate to the producer. Other event-log errors continue to be logged and swallowed.
  • Documentation
    • Updated release notes and observability guidance to describe the queued event-log error behavior.
    • Updated the displayed project version to 0.24.1.

A lost connection during the savepoint write of the queued event-log row
was logged and swallowed, but the producer's transaction was gone with
the connection, so its commit raised PendingRollbackError, which hosts
cannot tell from a bug. An error is_database_unavailable reports is now
raised as itself; other event-log errors are still swallowed.

Release 0.24.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The queued event-log recorder now re-raises errors classified as database unavailability. Other event-log errors remain logged and swallowed. The change also updates the release version and documents the behavior.

Changes: Queued event-log error handling

Layer / File(s) Summary
Propagate database-unavailability errors
jasil/event_log/recorder.py, tests/test_event_log.py, docs/observability.md, CHANGELOG.md
record_queued_in re-raises errors classified as database unavailability and continues to log and swallow other errors. A regression test checks that a simulated disconnect raises OperationalError with an invalidated connection. Documentation and the changelog describe the behavior.
Update release version
pyproject.toml, README.md, docs/index.md
The project version and displayed status versions change from 0.24.0 to 0.24.1.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • endurain-project/jasil#74: Adds the database-unavailability classifier used by record_queued_in to decide which errors to re-raise.
Merge Risk: Minimal · up to a1a57 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(events): raise a database outage from record_queued_in" matches the main change. The PR makes EventLogRecorder.record_queued_in re-raise errors that is_database_unavailable classifies a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(events): raise a database outage from record_queued_in" matches the main change. The PR makes EventLogRecorder.record_queued_in re-raise errors that is_database_unavailable classifies as a database outage, while other event-log errors stay logged and swallowed. The title names the affected method and the behavior change. It uses a conventional commit prefix and is one concise sentence. The version bump and docs updates are secondary and need no mention in the title.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9de112c8-1edb-4b77-9d93-6293871fba5f
Commits

Reviewing files that changed from the base of the PR and between da44a1d and a1a5786.

Files ignored due to path filters: 1

  • uv.lock is excluded by !**/*.lock
Files selected for processing: 7

  • CHANGELOG.md
  • README.md
  • docs/index.md
  • docs/observability.md
  • jasil/event_log/recorder.py
  • pyproject.toml
  • tests/test_event_log.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@joaovitoriasilva
joaovitoriasilva merged commit 4316d7f into main Nov 24, 2026
22 checks passed
@joaovitoriasilva
joaovitoriasilva deleted the fix/event-log-database-outage branch November 24, 2026 08:42
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