heal.sh's healer lock path is hard-coded, so concurrent suite runs red heal-test.sh #102

Closed
opened 2026-08-26 19:49:11 +00:00 by ben · 3 comments
Owner

Symptom

Two tests/heal-test.sh runs on one host cannot both pass. The loser prints
another healer holds the lock — exiting and posts no diagnosis, so the
first run should post the diagnosis scenario reds. It looks exactly like a
real regression in the healer, and it is not — the same test passes 3/3
standalone on a quiet box.

Observed 2026-08-26 while two agents ran the offline suite concurrently in
separate worktrees. Both hit it; one initially mis-attributed it to its own
diff, the other reproduced it on pristine origin/main. Neither was true —
they were colliding with each other.

Cause

heal.sh:104:

exec 8>"/tmp/matou-healer-$REPO_TAG.lock"

The path is hard-coded with no env override. $REPO_TAG is the fixture tag
under test, so every concurrent run of the suite on a host — two agents, two
worktrees, a developer beside a cron tick — contends for one /tmp file.

tests/heal-test.sh already does the right thing everywhere it can: it pins
CLAUDE_LIMIT_MARKER, CLAUDE_ACTIVE_MARKER and HOST_CAPACITY_DRIVE_WANTED.
It cannot pin this one, because the lock path is not a variable. No test can.

This is the GOTCHAS 29 class (suite state leaking through /tmp), but a
distinct instance with its own fix.

Rule / proposed fix

Give the lock the same treatment the markers already have — an env-overridable
path with today's value as the default, e.g.:

HEALER_LOCK="${HEALER_LOCK:-/tmp/matou-healer-$REPO_TAG.lock}"
exec 8>"$HEALER_LOCK"

then set it per-run in tests/heal-test.sh alongside the marker pins, and add
a scenario that proves two concurrent healers with distinct lock paths both
post their diagnosis while two with the same path do not.

Production behaviour must not change: on a real host the default keeps the
existing one-healer-per-repo-tag mutual exclusion, which is the point of the
lock and is correct.

Why it matters beyond the test

A red suite that depends on who else is on the box teaches everyone to
re-run until green, which is how a real red gets waved through. It also cost
real diagnosis time today: one agent spent part of its budget proving a
failure was not its own.

## Symptom Two `tests/heal-test.sh` runs on one host cannot both pass. The loser prints `another healer holds the lock — exiting` and posts no diagnosis, so the `first run should post the diagnosis` scenario reds. It looks exactly like a real regression in the healer, and it is not — the same test passes 3/3 standalone on a quiet box. Observed 2026-08-26 while two agents ran the offline suite concurrently in separate worktrees. Both hit it; one initially mis-attributed it to its own diff, the other reproduced it on pristine `origin/main`. Neither was true — they were colliding with each other. ## Cause `heal.sh:104`: ```sh exec 8>"/tmp/matou-healer-$REPO_TAG.lock" ``` The path is hard-coded with no env override. `$REPO_TAG` is the fixture tag under test, so every concurrent run of the suite on a host — two agents, two worktrees, a developer beside a cron tick — contends for one `/tmp` file. `tests/heal-test.sh` already does the right thing everywhere it can: it pins `CLAUDE_LIMIT_MARKER`, `CLAUDE_ACTIVE_MARKER` and `HOST_CAPACITY_DRIVE_WANTED`. It cannot pin this one, because the lock path is not a variable. No test can. This is the GOTCHAS 29 class (suite state leaking through `/tmp`), but a distinct instance with its own fix. ## Rule / proposed fix Give the lock the same treatment the markers already have — an env-overridable path with today's value as the default, e.g.: ```sh HEALER_LOCK="${HEALER_LOCK:-/tmp/matou-healer-$REPO_TAG.lock}" exec 8>"$HEALER_LOCK" ``` then set it per-run in `tests/heal-test.sh` alongside the marker pins, and add a scenario that proves two concurrent healers with distinct lock paths both post their diagnosis while two with the same path do not. Production behaviour must not change: on a real host the default keeps the existing one-healer-per-repo-tag mutual exclusion, which is the point of the lock and is correct. ## Why it matters beyond the test A red suite that depends on who else is on the box teaches everyone to re-run until green, which is how a real red gets waved through. It also cost real diagnosis time today: one agent spent part of its budget proving a failure was not its own.

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime. Category bug, state ready-for-agent.

Verified against the code: the report holds. heal.sh's healer lock is opened on a hard-coded /tmp/matou-healer-<repo-tag>.lock path with no env override, while the line immediately below it (HEALER_DRIVE_DEFER_COUNT) already follows the env-overridable-with-default idiom — so the fix is idiomatic and the marker-pinning discipline tests/heal-test.sh already applies to CLAUDE_LIMIT_MARKER / CLAUDE_ACTIVE_MARKER / HOST_CAPACITY_DRIVE_WANTED simply cannot reach this one path. Why a two-way door: it is a lib+test change gated by the offline suite and reverted by a later commit; production mutual-exclusion is preserved by keeping today's value as the default; nothing on the one-way-door list is touched.

Agent Brief

Category: bug
Summary: The healer's advisory-lock path is hard-coded, so two concurrent offline-suite runs on one host collide on a single /tmp file and the loser posts no diagnosis — reddening heal-test.sh as a false regression.

Current behavior:
The healer opens its exclusive lock on a fixed /tmp/matou-healer-<repo-tag>.lock path. The repo-tag is the fixture tag under test, so every concurrent run of the offline suite on one host (two agents, two worktrees, a dev beside a cron tick) contends for the same file. The loser prints another healer holds the lock — exiting and posts no diagnosis, so the "first run should post the diagnosis" scenario fails even though the healer is correct — it passes 3/3 standalone on a quiet box. This is the GOTCHAS 29 class (suite state leaking through /tmp), a distinct instance.

Desired behavior:
The lock path becomes env-overridable with today's value as the default — the same treatment the marker paths already have. tests/heal-test.sh pins a per-run, unique lock path alongside its existing marker pins, so concurrent suite runs no longer collide. Production behavior is unchanged: on a real host the default preserves the existing one-healer-per-repo-tag mutual exclusion, which is the point of the lock.

Key interfaces:

  • The healer's lock acquisition should read its path from an environment variable (e.g. HEALER_LOCK) defaulting to the current /tmp/matou-healer-<repo-tag>.lock value — mirroring the sibling HEALER_DRIVE_DEFER_COUNT pattern in the same file.
  • tests/heal-test.sh should set that variable per scenario to a unique path under its scratch dir, next to the marker pins it already sets.

Acceptance criteria:

  • The healer lock path is overridable via an environment variable; with the variable unset, the path is byte-identical to today's (mutual exclusion on a real host is unchanged).
  • A new heal-test.sh scenario proves two concurrent healers with distinct lock paths both post their diagnosis, and two with the same path do not (the loser exits on the lock).
  • The full offline suite passes when two copies run concurrently on one host.
  • The lib change and its test change land in the same commit (per CLAUDE.md).

Out of scope:

  • Changing the locking mechanism itself (still an advisory flock on fd 8) or the one-healer-per-repo-tag semantics on a real host.
  • Refactoring the other /tmp marker paths (GOTCHAS 29) — this ticket is the lock path only.
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** Category `bug`, state `ready-for-agent`. **Verified against the code:** the report holds. `heal.sh`'s healer lock is opened on a hard-coded `/tmp/matou-healer-<repo-tag>.lock` path with no env override, while the line immediately below it (`HEALER_DRIVE_DEFER_COUNT`) already follows the env-overridable-with-default idiom — so the fix is idiomatic and the marker-pinning discipline `tests/heal-test.sh` already applies to `CLAUDE_LIMIT_MARKER` / `CLAUDE_ACTIVE_MARKER` / `HOST_CAPACITY_DRIVE_WANTED` simply cannot reach this one path. **Why a two-way door:** it is a lib+test change gated by the offline suite and reverted by a later commit; production mutual-exclusion is preserved by keeping today's value as the default; nothing on the one-way-door list is touched. ## Agent Brief **Category:** bug **Summary:** The healer's advisory-lock path is hard-coded, so two concurrent offline-suite runs on one host collide on a single `/tmp` file and the loser posts no diagnosis — reddening `heal-test.sh` as a false regression. **Current behavior:** The healer opens its exclusive lock on a fixed `/tmp/matou-healer-<repo-tag>.lock` path. The repo-tag is the fixture tag under test, so every concurrent run of the offline suite on one host (two agents, two worktrees, a dev beside a cron tick) contends for the same file. The loser prints `another healer holds the lock — exiting` and posts no diagnosis, so the "first run should post the diagnosis" scenario fails even though the healer is correct — it passes 3/3 standalone on a quiet box. This is the GOTCHAS 29 class (suite state leaking through `/tmp`), a distinct instance. **Desired behavior:** The lock path becomes env-overridable with today's value as the default — the same treatment the marker paths already have. `tests/heal-test.sh` pins a per-run, unique lock path alongside its existing marker pins, so concurrent suite runs no longer collide. Production behavior is unchanged: on a real host the default preserves the existing one-healer-per-repo-tag mutual exclusion, which is the point of the lock. **Key interfaces:** - The healer's lock acquisition should read its path from an environment variable (e.g. `HEALER_LOCK`) defaulting to the current `/tmp/matou-healer-<repo-tag>.lock` value — mirroring the sibling `HEALER_DRIVE_DEFER_COUNT` pattern in the same file. - `tests/heal-test.sh` should set that variable per scenario to a unique path under its scratch dir, next to the marker pins it already sets. **Acceptance criteria:** - [ ] The healer lock path is overridable via an environment variable; with the variable unset, the path is byte-identical to today's (mutual exclusion on a real host is unchanged). - [ ] A new `heal-test.sh` scenario proves two concurrent healers with **distinct** lock paths both post their diagnosis, and two with the **same** path do not (the loser exits on the lock). - [ ] The full offline suite passes when two copies run concurrently on one host. - [ ] The lib change and its test change land in the same commit (per CLAUDE.md). **Out of scope:** - Changing the locking mechanism itself (still an advisory `flock` on fd 8) or the one-healer-per-repo-tag semantics on a real host. - Refactoring the other `/tmp` marker paths (GOTCHAS 29) — this ticket is the lock path only.

swarm-claim host=matou-dev-server-01 run=2645
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=2645 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #102 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 102,
  "status": "success",
  "commits": [
    "59627de"
  ],
  "changed_files": [
    "heal.sh",
    "tests/heal-test.sh",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/heal-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Lock path is env-overridable with today's value as the default": "heal.sh: HEALER_LOCK=\"${HEALER_LOCK:-/tmp/matou-healer-$REPO_TAG.lock}\"; exec 8>\"$HEALER_LOCK\" (commit 59627de)",
    "Set per-run in tests/heal-test.sh alongside the marker pins": "tests/heal-test.sh: HEALER_LOCK=\"$work/healer.lock\" added to run_heal and run_heal_ci env blocks",
    "Scenario proving two concurrent healers with distinct lock paths both post their diagnosis while two with the same path do not": "tests/heal-test.sh 16th scenario: with a held lock, HEALER_LOCK=held bails ('another healer holds the lock', no CLASS, no ledger write); HEALER_LOCK=other.lock proceeds and posts CLASS: harness-infra",
    "Production behaviour unchanged (default keeps one-healer-per-repo-tag mutual exclusion)": "default equals the prior hard-coded /tmp/matou-healer-$REPO_TAG.lock path; flock semantics untouched",
    "Full offline suite passes": "all tests/*.sh + onboarding/tests/*.sh green; heal-test.sh reports '16 scenarios passed'"
  },
  "summary": "Made heal.sh's healer lock path env-overridable (HEALER_LOCK) so concurrent offline-suite runs on one host stop contending for a single /tmp file, with a scenario proving distinct lock paths both diagnose.",
  "reason": "",
  "blockers": []
}
**close-report** for #102 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 102, "status": "success", "commits": [ "59627de" ], "changed_files": [ "heal.sh", "tests/heal-test.sh", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "bash tests/heal-test.sh", "exit_code": 0 } ], "criteria": { "Lock path is env-overridable with today's value as the default": "heal.sh: HEALER_LOCK=\"${HEALER_LOCK:-/tmp/matou-healer-$REPO_TAG.lock}\"; exec 8>\"$HEALER_LOCK\" (commit 59627de)", "Set per-run in tests/heal-test.sh alongside the marker pins": "tests/heal-test.sh: HEALER_LOCK=\"$work/healer.lock\" added to run_heal and run_heal_ci env blocks", "Scenario proving two concurrent healers with distinct lock paths both post their diagnosis while two with the same path do not": "tests/heal-test.sh 16th scenario: with a held lock, HEALER_LOCK=held bails ('another healer holds the lock', no CLASS, no ledger write); HEALER_LOCK=other.lock proceeds and posts CLASS: harness-infra", "Production behaviour unchanged (default keeps one-healer-per-repo-tag mutual exclusion)": "default equals the prior hard-coded /tmp/matou-healer-$REPO_TAG.lock path; flock semantics untouched", "Full offline suite passes": "all tests/*.sh + onboarding/tests/*.sh green; heal-test.sh reports '16 scenarios passed'" }, "summary": "Made heal.sh's healer lock path env-overridable (HEALER_LOCK) so concurrent offline-suite runs on one host stop contending for a single /tmp file, with a scenario proving distinct lock paths both diagnose.", "reason": "", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#102
No description provided.