Skip to content

fix(bin): replace symlinked harness wiring files instead of writing through them - #6533

Open
Vaughan-g-aus wants to merge 2 commits into
kunchenguid:mainfrom
Vaughan-g-aus:fm/fm-spawn-no-symlink-write
Open

Vaughan-g-aus wants to merge 2 commits into
kunchenguid:mainfrom
Vaughan-g-aus:fm/fm-spawn-no-symlink-write

Conversation

@Vaughan-g-aus

Copy link
Copy Markdown

Problem

When a project worktree's harness settings file (for example .claude/settings.local.json) is a symlink into a shared folder, bin/fm-spawn.sh wrote the per-task hook file through the link.
That overwrote the shared file, so every worktree linked to it ran the last-spawned task's Stop hook and produced misattributed turn-ended signals.

Change

  • New write_wiring_file helper in bin/fm-spawn.sh writes stdin to a temp file beside the target and renames it into place, removing any symlink at the path first, so the link target is never touched.
  • Every per-task harness wiring write that used a plain redirect now goes through it: claude settings, opencode plugin, grok and kimi worktree pointers, and the state-resident pi/omp extensions, gemini settings, grok/kimi tokens, and muse/cursor session sidecars.
  • Relaunch already retired wiring with rm -f, which removes a link rather than its target, and then re-runs the same writes.

Tests

  • tests/fm-busy-adapter-wiring.test.sh adds a case where the worktree's .claude/settings.local.json is a symlink to a file outside the worktree: after spawn the shared file is byte-identical and the worktree holds a real file with the task's hooks.
  • Verified the new case fails with the old plain-redirect write and passes with the fix; the whole file passes.

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Changes how harness settings files are written during task spawning.

The PR is not safe to merge until sequence-claim cleanup works on macOS.

Reviews (3) · Last reviewed commit: "fix(bin): keep an existing wiring file's..."

Comment thread bin/fm-spawn.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: first look vs tip 1f3e7696. Diff reviewed (write_wiring_file mktemp+chmod+rm-symlink+mv for claude/gemini/opencode/pi/omp/grok/kimi/muse/cursor wiring; test that shared symlink target stays byte-identical).

Contract-class: restore — concrete existing spawn wiring path wrote through a worktree settings symlink and corrupted shared hook files across linked worktrees. Tip replaces the link with a real per-task file. Not a new default-on captain surface.

VISION (per /workspace/VISION.md):

  1. One captain, one interface — aligns (correct turn-ended attribution; less false noise).
  2. Authority is explicit and never inferred — aligns (no autonomy widen).
  3. Scripts own the mechanics, agents own the judgment — aligns (deterministic write helper).
  4. A restart is a non-event — aligns (relaunch already rm -f then re-writes via same helper).
  5. Delegation with a spine — n/a.
  6. The fleet outlives any vendor — aligns (per-harness wiring; no vendor lock-in).
  7. Scope — aligns (spawn wiring integrity).

Attestation MISSING — no no-mistakes-pipeline-attestation matching HEAD 87d750e5 in the PR body. Cannot auto-merge without MATCH. Greptile Review FAILURE with open P2 (not P1): write_wiring_file sets mode from umask (0666 & ~umask), so a previously 0600 settings file can become 0644 — security FYI (stamp only; not otherwise-ready). P2 does not alone force waiting-author under charter, but MISSING attestation does → waiting-author.

First-time fork workflows approved so NM/CI can run (expect NM may also fail without attestation). Please publish via no-mistakes (or rebind attestation to HEAD) and consider preserving existing regular-file mode bits when replacing. No linked Fixes/Closes. Firstmate-flag=no.

@Vaughan-g-aus
Vaughan-g-aus force-pushed the fm/fm-spawn-no-symlink-write branch from 87d750e to 3ec938a Compare October 4, 2026 05:56
@Vaughan-g-aus

Copy link
Copy Markdown
Author

Update after the first CI round:

  • Greptile P2 (mode widened): fixed in 3ec938a9. write_wiring_file now keeps the mode of the file the path resolves to and uses the umask default only for a new file. A new test in tests/fm-busy-adapter-wiring.test.sh checks that a 0600 settings file stays 0600 after spawn.
  • Behavior portable serial 6: the failure was tests/fm-calm-pi-extension.test.sh ("grep disappeared from /export calm.html HTML"), which this change doesn't touch. test: support Pi 1.0.1 export renderer API in Calm fixture #6530 fixed it on main, and the branch is now rebased onto that.
  • PR must be raised via no-mistakes: expected. The author account can't push to this repo, so the no-mistakes pipeline (review, tests, docs) ran locally but couldn't push. The branch was published from the fork by hand, so there's no pipeline attestation for this head.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: RELOOK (author reply ~05:56Z + rebase onto #6530) vs tip fede6197556c188dd2f451809d17851760d1ef46. Diff reviewed (write_wiring_file mktemp+chmod+rm-symlink+mv; mode preserved from resolved path / umask only for new file; 0600 regression; calm-pi rebase onto fede619).

Contract-class: restore — concrete existing spawn wiring path wrote through a worktree settings symlink and corrupted shared hook files. Tip replaces the link with a real per-task file and keeps restrictive modes. Not a new default-on captain surface.

VISION: aligns (honest turn-ended attribution; Scripts own mechanics; Restart relaunch already rm -f then re-writes; fleet-outlives-vendor per-harness wiring; Scope).

Author update reviewed: Greptile P2 mode-widen fixed in 3ec938a9 (security FYI cleared). Serial-6 calm-pi failure attributed to main tip drift fixed by #6530 rebase — accepted pending CI.

Attestation still MISSING for HEAD 3ec938a9 — no no-mistakes-pipeline-attestation in body. Author notes fork cannot push via no-mistakes remote; hand-push leaves NM body-compliance failing. Repo rule (CONTRIBUTING / Require no-mistakes action) still requires attestation matching HEAD — cannot waive for auto-merge. Workflows re-approved this pass (37181315060 / 37181315077) so CI/NM can re-run on the rebased head. → waiting-author for a MATCH attestation on this head (or maintainer-path publish). No Firstmate flag (not otherwise-ready).

…hrough them

fm-spawn wrote per-task hook files such as .claude/settings.local.json with a
plain redirect, so a project that symlinks that file into a shared folder had
the shared file overwritten and every linked worktree ran the last-spawned
task's hooks. Wiring files are now written to a temp file beside the target and
renamed into place after removing any symlink, leaving the link target intact.
Renaming a fresh temp file into place took the umask default, which could widen
a restrictive 0600 settings file to 0644. The replacement now copies the mode
of the file the path resolves to and falls back to the umask default only for a
new file.
@Vaughan-g-aus
Vaughan-g-aus force-pushed the fm/fm-spawn-no-symlink-write branch from 3ec938a to 44c0aad Compare October 5, 2026 06:13
@Vaughan-g-aus

Copy link
Copy Markdown
Author

On the latest Greptile summary for 44c0aad ("not safe to merge until sequence-claim cleanup works on macOS"):

That concern is about the remote-job sequence-claim cleanup in bin/fm-remote-job-lib.sh, which came from #6575 (f470a01), already on main. This PR's diff against its base (f470a01) touches only bin/fm-spawn.sh and tests/fm-busy-adapter-wiring.test.sh and doesn't change that code. Greptile probably reviewed the force-push range, which included the main commits brought in by the rebase. There are no new inline findings on this PR's files. The earlier P2 about file permissions was fixed in the mode-preserving commit.

This head was published through the no-mistakes pipeline (push to the fork, then a PR update).

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.

2 participants