Skip to content

fix: alert before sqlite filesystem exhaustion - #350

Merged
ecarreras merged 7 commits into
mainfrom
fix/issue-344-disk-full
Nov 27, 2026
Merged

ecarreras merged 7 commits into
mainfrom
fix/issue-344-disk-full

Conversation

@giscebot

@giscebot giscebot commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • measure available capacity on the filesystem that contains the SQLite database
  • alert when either configurable threshold is crossed (default: 5 GiB or 10% available), and fail closed when capacity cannot be measured
  • deduplicate recurring alerts by stable alert fingerprint while preserving current capacity values in notifications
  • probe filesystem capacity before SQLite reads and preserve the capacity report when inspection or observability persistence fails
  • keep due alert delivery best-effort when state-directory/resend-state I/O or stale-job reconciliation fails because the database filesystem is exhausted
  • propagate thresholds through the monitor alert service and document the systemd environment settings

Incident evidence

At 2026-11-11 17:12:28 CET, heartbeat commits failed with database or disk is full; all executor workers then hit disk I/O error and the executor restarted. A read-only check with this branch currently reports only 2.6 GiB / 0.9% available on the database filesystem, so host cleanup remains an urgent operational action. This PR adds the missing early warning; it does not reclaim disk space.

Validation

  • pytest -q -p no:cacheprovider — 729 passed
  • focused monitor alert tests — 28 passed
  • temporary database CLI smoke test — monitor JSON returned ok=true with the expected database filesystem path
  • live read-only monitor check — emitted monitor.database_filesystem_low with 2.6 GiB / 0.9% available

Addresses #343
Addresses #344
Addresses #345
Addresses #346

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolved database path, threshold checks, and systemd wiring look appropriate. Two delivery issues need fixing before merge:

  1. A continuing low-space alert bypasses the resend interval. The report includes changing free-space values, and should_send_alert hashes the entire report. I reproduced three sends at 2-minute intervals as the reading changed from 2.6 to 2.5 to 2.4 GiB, despite a 900-second resend interval. Deduplicate on stable alert identity while keeping current values in the message, and test consecutive low-space samples with different readings.
  2. A SQLite write failure can suppress the disk warning itself. The systemd invocation uses default observability persistence, and the CLI only prints the report after record_monitor_observation returns. If that write raises SQLITE_FULL (for example, the first sample after a burst fills the disk), the low-space result is dropped. Preserve the capacity warning when persistence fails and test that path. Also, inspect_db runs before the capacity probe, so a read failure can prevent the probe from running at all.

Reviewed the monitor, CLI/service integration, docs and test changes at 88a3ab5; git diff --check passed and the resend behavior was reproduced locally.

Co-authored-by: pilipilisbot <pilipilisbot@users.noreply.github.com>
@giscebot

Copy link
Copy Markdown
Collaborator Author

Addressed both requested delivery fixes in 2f88d4d:

  • recurring low-space samples now deduplicate on the stable monitor alert fingerprint, while the notification still renders the current free-space values;
  • filesystem capacity is probed before SQLite inspection, and SQLite read/persistence failures are converted into monitor alerts instead of suppressing the capacity warning.

Added regressions for changing consecutive readings, failed DB inspection, and SQLITE_FULL during observability persistence. Validation: full suite 723 passed; focused monitor suite 63 passed; temporary-DB CLI smoke test passed.

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the filesystem probe, thresholds, CLI/systemd wiring, and the fixes for SQLite errors and changing capacity readings. The earlier issues are addressed at the report level, but one blocker remains in notification delivery.

In monitor_alert.py, should_send_alert writes monitor-alert.state before main calls send_alert. By default that file and SQLite share the same directory. If the filesystem fills between samples, the CLI can produce the right low-space report, but ENOSPC writing the resend state still prevents notification. I reproduced this by injecting ENOSPC into save_state and verifying send_alert was never called. Please make the resend-state write best effort: log the error, still send the due alert, and add a wrapper-level regression that verifies delivery when the state write fails.

GitHub Actions passed for Python 3.11, Python 3.12, and dashboard; git diff --check passed.

Co-authored-by: pilipilisbot <pilipilisbot@users.noreply.github.com>

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier fixes now preserve the capacity report through SQLite inspection/persistence errors, throttle changing readings by alert identity, and allow delivery if writing the resend state fails. Two filesystem-error paths still bypass delivery entirely:

  1. In monitor_alert.py, should_send_alert() calls load_state() outside the new error handler. If reading the existing resend file raises EIO, a low-space report that the CLI already produced is printed but never sent. Treat unreadable or malformed resend state as a cache miss, log the failure, and test that the wrapper still calls send_alert().
  2. main() runs maybe_unlock_stale() before sending. When stale-job handling and child inspection are enabled, a low-space report can coincide with a stale job and sample_executor_activity() can raise ENOSPC while writing its process-state file. Keep reconciliation failures visible without letting them suppress an otherwise due alert, and add a combined low-space/stale-job regression.

Reviewed the filesystem probe, threshold defaults and docs, CLI/systemd wrapper, and regression coverage. A local wrapper-level fault-injection check confirmed that both exceptions currently prevent send_alert(). GitHub Actions passed on Python 3.11, Python 3.12, and dashboard; git diff --check passed.

@giscebot

Copy link
Copy Markdown
Collaborator Author

Addressed the remaining notification-delivery blocker in 76a0346:

  • resend-state persistence is now best effort: an OSError is logged to stderr, but the due alert still reaches send_alert;
  • added a wrapper-level regression that injects ENOSPC from save_state and verifies both delivery and the warning.

Validation: pytest -q -p no:cacheprovider (724 passed), focused monitor-alert tests (24 passed), and git diff --check. GitHub Actions are also green for Python 3.11, Python 3.12, and dashboard.

Co-authored-by: pilipilisbot <pilipilisbot@users.noreply.github.com>
@giscebot

Copy link
Copy Markdown
Collaborator Author

Addressed both remaining delivery paths in 0738468:

  • unreadable or malformed resend state is now treated as a cache miss, with the failure logged, so a due alert is still sent;
  • stale-job reconciliation is isolated from alert delivery, with failures kept visible on stderr and in the outgoing notification;
  • wrapper-level regressions cover EIO while loading resend state, malformed state, and ENOSPC during combined low-space/stale-job reconciliation.

Validation: pytest -q -p no:cacheprovider (727 passed), focused monitor-alert tests (27 passed), and git diff --check.

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier fixes for resend-state reads/writes and stale-job reconciliation are in place, but one database I/O path still drops the capacity report.

Blocking — monitor.py, DB inspection exception handler: When inspect_db() raises EIO while checking whether the DB exists, the handler calls database_path.exists() on the same path. That raises again before the monitor returns the capacity report. I reproduced this on 0738468 with a successful low-capacity probe and persistent EIO from Path.stat() only for the SQLite file. Treat existence as unknown in the handler without touching that filesystem again, and add a regression asserting that both alerts survive a failed stat.

Test isolation: test_monitor_ok_on_empty_initialized_db also failed locally because the pytest temp mount had 109 MiB / 0.2% free. Stub healthy capacity in tests unrelated to disk thresholds so a correctly initialized DB does not fail those tests based on the host mount.

Reviewed the threshold and probe logic, CLI/systemd wiring and docs, and notification resend and reconciliation paths. GitHub CI was green on Python 3.11, Python 3.12 and dashboard; git diff --check passed.

Co-authored-by: pilipilisbot <pilipilisbot@users.noreply.github.com>
@giscebot

Copy link
Copy Markdown
Collaborator Author

Addressed the remaining database-I/O blocker in 8961688:

  • after database inspection raises an I/O error, the monitor now records database existence as unknown instead of touching the same path again, so the already-collected capacity warning survives;
  • added a regression that fails the database existence check, verifies there is no retry, and asserts that both the low-capacity and inspection-failure alerts are returned;
  • isolated monitor tests from host disk capacity with a healthy-capacity fixture.

Validation in a clean Python 3.12 environment: tests/test_monitor.py (41 passed), full suite (727 passed, 1 skipped), and git diff --check.

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8961688, including the filesystem probe, threshold configuration and systemd wiring, and the alert resend/reconciliation paths. I confirmed that an EIO on the SQLite file now preserves both the low-capacity and database-inspection alerts. GitHub Actions passed for Python 3.11, Python 3.12, and dashboard; git diff --check passed.

Blocking: a resend-state directory error still prevents the monitor from running. monitor_alert.main() calls config.state_dir.mkdir(...) before run_monitor(). If that directory is missing and the filesystem is full, or accessing the directory itself fails with EIO, the wrapper exits before it can probe capacity or send an alert. I injected ENOSPC at that call and confirmed neither run_monitor() nor send_alert() ran. Remove the eager mkdir (the state writers already create their parent directories under the best-effort handling), or make it best effort. Please add a wrapper regression that verifies a due alert is delivered when creating the state directory fails.

Co-authored-by: pilipilisbot <pilipilisbot@users.noreply.github.com>

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 3be3277. The last blocker is resolved: the wrapper runs the monitor before attempting to create the resend-state directory. The new regression injects ENOSPC at directory creation and verifies that the monitor runs, the write failure is logged, and the due low-space alert still reaches send_alert().

I checked the resolved SQLite filesystem probe, threshold defaults and CLI/systemd wiring, and the earlier SQLite I/O and resend/reconciliation fixes. The capacity warning survives those failures, and changing free-space readings no longer reset the resend interval. No schema migration is required.

GitHub Actions passed for Python 3.11, Python 3.12, and dashboard on this head; git diff --check passed. The PR adds early warning; freeing capacity on the host is still a separate operational task.

@giscebot

Copy link
Copy Markdown
Collaborator Author

Addressed the latest state-directory blocker in 3be3277:

  • removed the eager state_dir.mkdir() that ran before the capacity probe;
  • state writers still create their parent directory inside the existing best-effort persistence path, so an ENOSPC/EIO there is logged without suppressing a due alert;
  • added a wrapper regression that injects ENOSPC from directory creation and verifies that both run_monitor() and send_alert() still execute.

Validation: tests/test_monitor_alert.py (28 passed), full suite (729 passed), and git diff --check. The PR description now reflects the final scope and validation counts.

@ecarreras
ecarreras merged commit 9e03482 into main Nov 27, 2026
4 checks passed
@ecarreras
ecarreras deleted the fix/issue-344-disk-full branch November 27, 2026 11:47

Copy link
Copy Markdown
Member

Post-merge cleanup complete. Verified the merge into main at 9e03482 and removed the clean github-agent-bridge-pr-350 worktree at the approved head 3be3277. Confirmed its directory and Git worktree registration are both gone; the canonical checkout was left untouched.

@giscebot

Copy link
Copy Markdown
Collaborator Author

Post-merge follow-up: PR merged as 9e034820798ad23a11677b26e9986f2e805c020d. The dedicated worktree was clean and has been removed. Final CI was green for Python 3.11, Python 3.12, and dashboard; the remaining pending bridge-agent status contexts are external job contexts, not code-check failures. Operationally, this adds early warning and resilient delivery, but host capacity recovery/observation remains a separate rollout task.

@giscebot

Copy link
Copy Markdown
Collaborator Author

Independent post-merge verification completed on current origin/main (0067171, including merged PR 9e03482): focused monitor coverage passes (69 passed), including the ENOSPC/EIO database-filesystem, resend-state, state-directory, and stale-reconciliation paths. I found no new code-review findings.

The remaining operational concern is unchanged: host disk recovery and a clean observation window are still required separately from this code merge.

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.

3 participants