Skip to content

🤖 fix: claim remote background record names with an atomic mkdir - #5486

Merged
ThomasK33 merged 4 commits into
mainfrom
fix/bg-remote-record-names-pr
Oct 2, 2026
Merged

ThomasK33 merged 4 commits into
mainfrom
fix/bg-remote-record-names-pr

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

On runtimes whose background records are not on this host (SSH/Coder, Docker, devcontainer, multi-project), a second backend no longer reinitialises a record directory that another backend still tracks. Spawn now claims the name with an atomic mkdir (no -p) on the runtime, and any existing directory, including a settled one with exit_code, counts as taken. Fixes the reproduced part of #4889 (finding from the background-processes model, #5464).

Background

Host-local names are serialised by the .spawn-name.lock file lock (MC_name_host holds). Non-host runtimes had no cross-backend lock, and runtimeSpawnDirMayHoldLiveProcess called a directory free when it held exit_code. So backend B reinitialised the directory backend A still tracked, even when the spawns never overlapped (TLC MC_name_remote_serial), and two concurrent same-name spawns could share one directory (MC_name_remote). A's later output and status reads then described B's command.

Implementation

  1. claimRuntimeSpawnDir replaces the probe: mkdir -p <workspace dir>, then mkdir <record dir>. Success means this spawn owns the directory. If it exists (or a dangling symlink sits there), the name is held and the existing suffix loop picks the next name. Any other failure aborts the spawn, as before. No new persisted state, no remote lock. Names, bash:<name> task IDs and monitors keep the existing suffix contract.
  2. The claim creates the directory before spawnProcess runs, so two early failures must not leave an empty directory behind (it would hold the name and fail the remote crash-orphan probe closed):
  3. Model: BgSpawnName.tla gets an AtomicClaim fix probe (a Claim step that creates the directory only when absent). New MC_name_remote_fixed holds all invariants. The faithful remote rows stay as they are, because they describe the old code.

Validation

All with bun 1.3.12.

  • #4889 … B does not reinitialise the record directory A still tracks is now a plain test. With backgroundProcessManager.ts and backgroundProcessExecutor.ts reverted to main, it fails at its target (Expected: false, Received: true); the host-local control passes.
  • New tests, each failing with its production change reverted: concurrent same-name spawns from two backends on a non-host runtime get distinct directories; a cwd-check failure removes the claimed directory; an unclaimed existing record survives a cwd-check failure; a seal refusal removes the claimed directory. The existing settled-record test now expects settled-job (2) and an untouched exit_code.
  • bun test src/node/services/backgroundProcess*.test.ts src/node/services/tools/bash*.test.ts: 268 pass, 0 fail.
  • TLA_JAVA_OPTS=-Xmx6g formal/background-processes/check.sh: exit 0.
  • make static-check: exit 0.

Risks

Low to medium, limited to background spawns on non-host runtimes. A display name used in an earlier session now gets a suffix on those runtimes until /tmp/mux-bashes/<ws> on the runtime is cleared, and each taken candidate costs one exec round-trip. Tracked in #5485 (a remote prune needs a lock or a race-free design). Host-local spawns are unchanged.

Refs #4889 (stays open: its cross-backend evidence requirements are broader), #5464.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $7.74

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T15:28:04.140563Z a029a6f Manual request
🔒 Security Review ✅ Completed 2026-10-02T15:31:35.398830Z a029a6f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afe6067511

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: afe6067511

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: a029a6ff37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: a029a6ff37

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit eaead8d Oct 2, 2026
32 of 33 checks passed
@ThomasK33
ThomasK33 deleted the fix/bg-remote-record-names-pr branch October 2, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant