feat(adf-setup): root-privileged worktree sweep for systemd ExecStartPre (Layer 3) Refs #1571 (Gitea)#873
Merged
Merged
Conversation
…tartPre
Layer 3 of the four-layer ADF worktree lifecycle plan (epic #1567).
This commit introduces the hot-shippable defence: a POSIX `sh` script
that systemd invokes as root via `ExecStartPre=` before the
orchestrator starts. Layers 1 and 2 prevent new residue from
accumulating but cannot reclaim root-owned trees written by
container-build agents; Layer 3 is the only layer that can.
Files:
* `scripts/adf-setup/adf-cleanup.sh` -- POSIX `sh` (verified with
`dash -n`), `set -eu`. Sweeps `${ADF_WORKTREE_ROOT}/review-*` and
`${ADF_AGENT_TMP_ROOT}/*` via `git worktree remove --force` with a
`/bin/rm -rf` fallback, finishes with `git worktree prune
--verbose` and a single summary line `adf-cleanup: swept=N
failed=M repo=PATH`. Three environment variables overridable.
* `scripts/adf-setup/tests/test_adf_cleanup.sh` -- POSIX shell test
driver. Seeds a real git repo under `mktemp -d`, creates three
`review-test-*` worktrees plus a `keep-me/` directory, asserts the
review entries are removed and `keep-me/` is preserved, and a
second run is a no-op. Exits 0 on PASS, 1 on FAIL.
* `docs/operations/adf-orchestrator-systemd.md` -- operator-facing
doc with the systemd drop-in, the `install` commands (mode 0750,
owner root:root), verification recipe (cross-referencing §8.4 of
the design), and rollback steps.
Deviations from the design verbatim (small portability hardenings):
* Test driver passes `-c init.defaultBranch=main` to `git init` to
silence the default-branch hint, and `-c user.email/-c user.name`
to `git commit --allow-empty` so the test survives on hosts
without a global git identity.
Verification:
* `./scripts/adf-setup/tests/test_adf_cleanup.sh` -- PASS.
Output: `adf-cleanup: swept=3 failed=0 ...` then
`adf-cleanup: swept=0 failed=0 ...` then `PASS: test_adf_cleanup`.
* `dash -n` on both scripts -- POSIX syntax clean.
* `shellcheck` not installed locally; skipped.
* `git diff --check` -- clean.
No Rust files touched; `cargo fmt --check` does not fire.
Refs #1571 (Gitea)
Contributor
Documentation PreviewYour documentation changes have been deployed to: This preview will be available until the PR is closed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Layer 3 of the ADF worktree-lifecycle hardening epic (Gitea #1567). Defence in depth: a POSIX
shscript run as root via systemdExecStartPre=so worktree residue owned by root-elevated agents (sccache, container builds) gets reaped at the next service restart even if Layers 1 (RAII guard) and 2 (orchestrator-side sweep) miss it.Three new files:
scripts/adf-setup/adf-cleanup.sh-- the sweep script.scripts/adf-setup/tests/test_adf_cleanup.sh-- shell test driver (creates a real git repo in a TempDir, seeds review-/keep-me, asserts review- removed and keep-me preserved, idempotency on second run).docs/operations/adf-orchestrator-systemd.md-- operator install/rollback runbook.No Rust changes. Hot-shippable: install via
sudo install -m 750 -o root -g root scripts/adf-setup/adf-cleanup.sh /opt/ai-dark-factory/bin/adf-cleanup.shplus the systemd drop-in snippet in the ops doc.Test plan
./scripts/adf-setup/tests/test_adf_cleanup.sh--PASS: test_adf_cleanup(first run sweeps 3 worktrees, second run is no-op).dash -nPOSIX syntax check -- clean.Refs terraphim/terraphim-ai#1571 (Gitea)
Refs terraphim/terraphim-ai#1567 (Gitea epic)