Skip to content

Stop privileged helpers failing at random on the environment scan's wait - #17536

Open
Hamza0101 wants to merge 1 commit into
omacom:quattrofrom
Hamza0101:env-scan-without-wait
Open

Hamza0101 wants to merge 1 commit into
omacom:quattrofrom
Hamza0101:env-scan-without-wait

Conversation

@Hamza0101

Copy link
Copy Markdown
Contributor

What changes

omarchy_security_sanitize_bash_environment reads env -0 through a process substitution and then runs wait on the substitution's PID to make sure the listing completed. Bash sometimes reaps that child first and then answers the wait with:

omarchy-security-functions: line 46: wait: pid 257563 is not a child of this shell

wait then returns 127, the sanitizer returns 1, and the privileged entrypoint that called it (omarchy-update-stay-awake, omarchy-sudo-passwordless) exits under set -e before doing anything. For a user that means an update's sleep inhibitor sometimes fails to start or stop. In CI it shows up as an unrelated test file failing at random.

This drops the wait. The producer now writes an end record after env -0 succeeds, and the reader requires that record to be the last one it saw. A failed or truncated listing still fails closed, and nothing depends on bash's child bookkeeping anymore.

Where it was seen

Two of the last 40 failed Tests runs fail with exactly this message, each in a different file:

Run File Step that died
41797333267 (push to quattro) update-lock-test.sh omarchy-update-stay-awake stop, right after "first upgrade cleans old inhibitor state"
41496951388 (launcher-activation-token) update-stay-awake-security-test.sh the helper call right after "malformed, multiline, reused-PID, and wrong-identity records are harmless"

QA report

All runs below were on GitHub runners in my fork. Each one ran quattro (9b525a935) and this branch side by side.

1. Race stress. A minimal #!/bin/bash -p entrypoint, started as a fresh process each time, does what omarchy-update-stay-awake does before its first command. It checks the Bash startup, sources the helper, and sanitizes the environment.

Load Distro, bash quattro failed this branch failed
Sequential, idle Arch, 5.3.20 0 of 4,000 0 of 4,000
Sequential, 8 yes hogs Arch, 5.3.20 0 of 4,000 0 of 4,000
Sequential, idle Ubuntu, 5.2.21 0 of 4,000 0 of 4,000
Sequential, 8 yes hogs Ubuntu, 5.2.21 0 of 4,000 0 of 4,000
8 parallel workers, 4 fork-churn loops Arch, 5.3.20 0 of 24,000 0 of 24,000
8 parallel workers, 4 fork-churn loops Ubuntu, 5.2.21 1 of 24,000 0 of 24,000

I could not reproduce the "not a child" message outside the CI VM. The single quattro failure on Ubuntu printed something else, and my harness did not keep its output. So this table shows the change adds no failures, not that it removes the CI one. The fix stands on the code path: the only wait that could print that message is gone.

2. The check still fails closed.

Case quattro this branch
BASH_ENV and an exported BASH_FUNC_x%% in the environment stripped, re-exec, exit 0 stripped, re-exec, exit 0
env fails before listing anything not tested exit 1
env lists everything, then fails not tested exit 1

The last two rows swap the producer for a failing command in a patched copy of the helper.

3. Every test file that covers the helper's three callers, three runs each. Arch container, run as a non-root user:

File quattro this branch
security-bash-startup 3 ok, 1 skip (no user namespaces) same
security-entrypoint-symlink 1 ok same
security-source-root 5 ok same
nopasswd-sudo-expiry 27 ok same
passwordless-grant-lifecycle 4 ok, 1 skip same
passwordless-sudo-indicator 8 ok same
update-boot-verify 6 ok same
update-hook-security 9 ok same
update-sequence 7 ok same
bin-style 2 ok same
update-stay-awake-security 15 ok, 1 skip, 5 of 5 runs same
update-lock 2 ok, then fails at "waits for its sleep inhibitor to stop", 5 of 5 runs same

The last two rows needed /run/user/$UID created, which a container doesn't provide. update-lock fails on both trees at the same step in the container. It passes that step in this repo's CI VM, so the failure comes from the container.

4. Static checks. bash -n and git diff --check are clean.

Not added: a regression test. The race doesn't reproduce on demand, so no test can fail on quattro. Testing the fail-closed path means replacing /usr/bin/env, which the helper calls by absolute path. The full Tests run on this PR covers the rest.

Screenshots

No visible change: this fixes a startup check in privileged shell helpers.

Bash can reap the substitution before wait runs and then report it is not
a child of this shell, so privileged entrypoints failed at random. An end
record written only after env succeeds proves the scan read everything.
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

omarchy_security_sanitize_bash_environment now checks for a final record instead of waiting on the process substitution's PID.

  • Privileged helpers confirm environment scans with a final record.

Reviews (1) · Last reviewed commit: "Stop waiting on the environment scan's p..." · Reviewed by Greptile

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by GPT-6 in Codex (effort not exposed): I read the environment scan, its privileged callers, and the current quattro implementation. #19096 already removed the same process-substitution wait using lastpipe and PIPESTATUS; this head conflicts with quattro.

I classified this as a bug fix, but the second classifier, deepseek-v4p1-flash (effort not reported), returned no classification. Classification therefore remains unsettled. No substantive second review or worker tests ran; the unused worker was destroyed. The existing CI checks passed at 3dd982c3b82e70e333df74a7fd3fca9b23d80d5c. This is left for the maintainer with no verification labels.

@omarchybot omarchybot added the bug Something isn't working label Nov 22, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

The bug classification is now agreed. At 3dd982c3b82e70e333df74a7fd3fca9b23d80d5c, ./test/cli and five focused test files (security-bash-startup, security-source-root, security-entrypoint-symlink, update-stay-awake-security, and nopasswd-sudo-expiry) completed successfully on a disposable Omarchy ISO worker, which has been destroyed. These checks do not reproduce the intermittent wait race.

Current quattro already removes that wait through #19096, commit 07460209733354e3ea9b2b4aa3eaae4e7a307210, and a merge check confirms a conflict in bin/omarchy-security-functions. This is an alternative implementation of the same fix, with no remaining change identified that needs carrying over. It is left open for the maintainer to decide its disposition.

Checked by GPT-6 in Codex (effort not exposed), with source review by Opus 5.5 High and muse-wonder via pi, thinking high. Both reviewers agreed that #19096 covers the fix; independence is not guaranteed. A worker probe ruled out the panel’s proposed raw-environment sentinel spoof: Bash discards the no-= entry before the scan. No actionable code defect remains from this review. No branch changes or verification labels were added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants