Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR rewrites omarchy-crash-watch to watch the systemd-coredump directory via inotify (instead of following the journal), aiming to reduce idle memory usage while preserving crash notifications and dedupe behavior.
Changes:
- Switch crash detection from
journalctl -ftoinotifywaiton/var/lib/systemd/coredumpwith filename parsing +coredumpctllookup. - Add a shell-based test harness that stubs
inotifywait,coredumpctl, and notification commands to validate notification contents + dedupe/ignore behavior. - Add a migration to restart the crash watcher so the rewrite takes effect immediately after update; update docs accordingly.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/shell.d/crash-watch-test.sh | Adds end-to-end-ish shell tests for the rewritten crash watcher using stubbed helpers. |
| migrations/1786894219.sh | Restarts the user crash-watch service so the new inotify-based watcher is used right after upgrade. |
| docs/notifications.md | Updates documentation to reflect the new inotify-based implementation and memory characteristics. |
| bin/omarchy-crash-watch | Replaces journal tailing with inotify directory watching and transient coredumpctl lookups. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (2)
test/shell.d/crash-watch-test.sh:21
- This stub expands
$WATCH_ITEMSunquoted, so it performs word-splitting and glob expansion. That can make the test diverge from realinotifywaitbehavior (one filename per line) and can break if an item contains glob characters or spaces. Prefer passing items newline-separated and printing withprintf '%s\n' \"$WATCH_ITEMS\"(or otherwise ensure the stub emits exactly one item per line without word-splitting).
cat >"$TMPDIR/bin/inotifywait" <<'SH'
#!/bin/bash
printf '%s\n' $WATCH_ITEMS
SH
migrations/1786894219.sh:17
- This migration script uses bash-specific
[[ ... ]]syntax but has no shebang. If the migration runner executes scripts via/bin/sh(or a non-bash shell), this can fail. Add an explicit#!/bin/bash(and, if consistent with other migrations in this repo, considerset -euo pipefail) to make the interpreter and error-handling behavior unambiguous.
echo "Restart the crash watcher so it picks up the inotify rewrite"
# omarchy-crash-watch followed the journal with journalctl -f, mapping the
# whole journal into memory; the rewrite watches the systemd-coredump
# directory with inotify instead, at a few MB. pacman replaces the script on
# update, but the running service keeps the old one in memory until it
# restarts, so restart it here for the memory win to land during the update
# instead of at the next login.
# The unit's ConditionPathExists re-checks the same toggle flag at every
# start, so a watcher the user disabled stays off: honoring the flag here
# makes this migration a no-op for them. Only nudge a watcher that is
# actually running; a stopped one stays stopped.
[[ -f "$HOME/.local/state/omarchy/toggles/crash-capture-off" ]] && exit 0
systemctl --user is-active omarchy-crash-watch.service >/dev/null 2>&1 &&
systemctl --user restart omarchy-crash-watch.service >/dev/null 2>&1 || true
a59d8a2 to
02ca832
Compare
02ca832 to
cf518e1
Compare
|
Reviewed at cf518e1, on a disposable Omarchy VM, with real crashes and the suites run there. This needs a few changes before it can land, and the memory numbers need another look. Tests. Crashes dropped or misread:
The memory claim didn't reproduce at the stated size. With a 1 GB journal on the VM, the current watcher's service used 24 MB, and its What still works: Codex Medium reviewed it as a second opinion. It agreed on the test failures and the empty-comm drop, and found the executable/signal field shift, which I then checked in the source. Its independence from this review is not guaranteed. Also for the maintainer: #11569, #11782 and #13161 edit the same watcher, and #11782 adds a different This is waiting on the author for the fixes above and the measurement details. |
cf518e1 to
bb49ebd
Compare
[Medium impact] The PR appears safe to merge; both numbered findings are fixed. SummaryThe PR replaces crash journal events with short-lived markers from
Both numbered findings are fixed. No new actionable issues were found.
|
|
On the measurement questions: the figures were not measured. The ~400 MB was a single observation of the running watcher/ I have just updated the PR title and description to drop both claims and to state only what is verifiable, so the memory numbers no longer overstate the case. If settling the trade needs real numbers, I am happy to measure with your approach ( |
900443b to
84878e4
Compare
journalctl -f mapped the whole journal into memory (~200MB RSS with a 1.3GB journal): it opens every journal file, archived or active. The crash watcher only needs the four fields systemd-coredump already bakes into each core file's name (comm, uid, boot id, pid), so watch /var/lib/systemd/coredump with inotify instead — a few MB idle, and nothing retained between crashes. The name, executable, and signal for the toast come from one transient coredumpctl lookup per crash, matched by pid and boot id so a reused pid cannot resolve to the wrong crash. A failed lookup still announces, just with the truncated kernel comm and an unknown signal, and the diagnosis path is untouched: clicking the toast still runs omarchy-agent-crash, which re-derives everything from coredumpctl at click time. Behavior is preserved: the uid filter, ignore pattern, self-exclusion, and the per-minute dedupe window all work as before, and a restart misses only the crashes that happened while it was down, exactly like journalctl -n 0 never replayed old entries. inotify-tools was already a base dependency.
pacman replaces /usr/bin/omarchy-crash-watch on update, but the running service keeps the old script in memory until it restarts, so the memory win from the inotify rewrite would otherwise wait for the next login. A migration restarts the watcher during omarchy update instead. It only nudges a watcher that is actually running, and skips one the user disabled: the unit re-checks the same toggle flag at every start, so honoring it here makes the migration a no-op for them.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The stub expanded $WATCH_ITEMS unquoted to turn the space-separated list into one filename per line, which also glob-expands any glob character in a name. Split on spaces with tr instead so the mock only ever emits the names it was given.
systemd-coredump writes the core file before it journals the COREDUMP_* entry, so the watcher could fire on the file and miss the entry by a beat, falling back to the truncated comm and an unknown signal. Retry the lookup for up to two seconds before falling back, and only notify with less detail when the entry truly never lands. The test now covers a crash whose first two lookups fail and whose details arrive on the third.
Match an empty comm in the core filename so a crash whose process never set a name is still announced, and read the executable and signal on separate lines so a missing executable cannot shift the signal into its place. Give the self-exclusion fixture its own pid and cover both cases.
A requested restart is no longer masked with `|| true`, so a failure leaves the migration unmarked and omarchy-migrate retries it instead of recording a success the watcher did not get.
Emit ephemeral root-owned events from systemd-coredump ExecStopPost so notifications do not depend on retaining an external core. Resolve each event with a short-lived JSON journal query matched by InvocationID, avoiding reused PIDs, escaped filenames, and shifted empty fields. Port the existing crash capture fixtures to the event source, preserve mute and hostile-name coverage, and verify bounded retries, real inotify marker delivery, unit syntax, and migration failure/retry behavior.
Keep mocked and static checks unconditional. Skip native inotify and systemd verification independently when their host dependencies are missing, while preserving failures when available checks are broken.
Fold the crash-watch-test.sh assertions into crash-capture-test.sh, the existing suite for bin/omarchy-crash-watch, and drop the greps that restated the drop-in's contents instead of exercising it. Delete crash-watch-migration-test.sh: a migration is frozen once it ships, so its behaviour is tested where it lives, not in a suite of its own. Unwrap the crash capture paragraph in docs/notifications.md onto one line.
24d1d97 to
380889c
Compare
jq buffers its output into a pipe, and the OOM stream never ends, so a single kill stayed in the buffer until it filled or the watcher died: the user got no toast, and the OOM grace window never opened to suppress the crash that follows. --unbuffered makes jq write each event as it arrives. The test that comes with it holds the journal stream open until the toast has been seen, which the buffered version never manages.
…pdate A dev-linked checkout runs ahead of its packages, where neither the tmpfiles rule nor the coredump drop-in is installed under /etc yet, and an unguarded systemd-tmpfiles call then failed the whole update. Exit 75 with the paths it waits for, as the migration guide asks: the migration stays pending and the next update applies it.
tl;dr:
The crash watcher follows the system journal with
journalctl -f, which maps journal files and grows with the journal. This PR watches the systemd-coredump directory withinotifyinstead, resolving crash details from onecoredumpctllookup per crash.Problem.
journalctl -fopens and maps every journal file it can find, so the watcher's footprint grows with the journal. I once observed the watcher/journalctlreach roughly 400 MB, but I could not reproduce it, isolate a cause, or measure it methodically, so I cannot stand behind that number. The "1.3 GB journal" and "close to a gigabyte of page cache" figures I originally gave were worst-case estimates, not measurements, and are removed here.Change. systemd-coredump already writes one core file per crash, named core.comm.uid.bootid.pid.timestamp.zst. The watcher now watches that folder with inotify instead: a few MB idle, and nothing retained between crashes. The program name, executable, and signal shown in the notification come from a coredumpctl lookup per crash, matched by pid and boot id so a reused pid can never point at the wrong crash. systemd-coredump writes the core file before it journals the entry, so the lookup retries briefly (up to two seconds) to let the entry land; the toast only falls back to the truncated comm and an unknown signal when the entry truly never appears, and clicking it always runs a full diagnosis from coredumpctl regardless.
No behavior changes. The same critical notification with the click-to-diagnose action, the per-minute dedupe for crash loops, the uid filter, ignore patterns, and self-exclusion all work exactly as before. Clicking the notification still opens the AI diagnosis, which reads the crash details itself. A restart only misses crashes that happened while it was down, just like before. inotify-tools was already an Omarchy dependency.
Testing. A new crash-watch-test.sh covers the notification contents, the uid and ignore filters, self-exclusion, dedupe, and the lookup-failure fallback, using mocked inotifywait, coredumpctl, and notification scripts.