Refuse a tracked build whose checkout is on another machine - #1
Merged
Conversation
bb supports a server with enrolled Macs, so a thread's environment can live on a host that is not the one running this plugin. The tracked-build path never knew that: `confinedBuildCwd` calls `realpath` with `node:fs` on THIS machine, so a thread whose worktree lives on another Mac died with ENOENT: no such file or directory, realpath '/Users/<other>/.../Checkout' naming a directory that plainly exists on the machine the user was looking at. `bb xcode run --host <that machine>` did not help either, because the path is resolved where the plugin is hosted, not on the host named in the flag. `src/sim/hostcheck.ts` already states the rule for Stills — "a checkout on another host is a real refusal with a real sentence rather than a mysterious 'no such file'" — and derives the server's own host id. That rule simply never reached tracked builds. This applies it there, reusing `locateCheckout` and `resolveServerHostId` rather than adding a second mechanism. - `ThreadScope` carries `hostId`; `ScopeSync` reads it off the environment DTO (bb already returned it, the dep type just narrowed it away). - `checkoutHostMismatch` turns the mismatch into the sentence, and fails OPEN when either host is unknown so single-machine setups are untouched. - Both entry points — `bb xcode run` and the `xcode_build` tool — consult it before any filesystem work. Note this refuses; it does not route the build. Executing on the environment's host would need the run tracking (a local lsof process probe) to work cross-machine too, which is a larger change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The bug
Running a tracked build from a thread whose environment lives on an enrolled Mac (not the machine running bb) fails with:
The directory plainly exists on the machine the user is looking at, and
node -e 'fs.realpathSync(p)'succeeds there — so the message reads as a broken checkout rather than a topology mismatch.bb xcode run --host <that machine>does not work around it: the path is resolved in the process where the plugin is hosted, not on the host named in the flag, so the flag is silently misleading.Root cause
ThreadScopecarriedpathbut no host identity.ScopeSynctookenv.pathat face value as a local path, andconfinedBuildCwd→realpaththen rannode:fsagainst another machine's filesystem.Diagnosis evidence:
fs.realpathSync(path)on the owning hostbb file paths --host <owning host>bb file paths --host <primary>bb settings showprimaryHostId= the primary, not the env's hostbb environment show --jsonhostIdThe fix
src/sim/hostcheck.tsalready states this exact rule for Stills — "a checkout on another host is a real refusal with a real sentence rather than a mysterious 'no such file'" — and already derives the server's own host id via the nonce +hosts.pathsExisttrick. That rule just never reached tracked builds. This applies it there, reusinglocateCheckoutandresolveServerHostIdinstead of introducing a second mechanism.ThreadScopegainshostId;ScopeSyncreads it off the environment DTO. bb already returned it — the dep type had narrowed it away, so noserver.tsdata plumbing was needed.checkoutHostMismatch()produces the sentence, and fails open when either host id is unknown, so no existing single-machine setup can be newly refused.bb xcode runand thexcode_buildtool — consult it before any filesystem work.Scope
This refuses clearly; it does not route the build. Executing on the environment's host would also require the run tracking (a local
lsofprocess probe, DerivedData scanning, the shim) to work cross-machine — a much larger change. Happy to follow up if that is wanted.Verification
npm run check(typecheck + full suite): 67 files, 825 passed, 7 skipped, 0 failurestest/checkout-host.test.tscovers same-host, other-host, unknown-host fallback, and the fail-open casestest/agent-scope-security.test.tsassert the agent tool refuses before touching the filesystem, and that a local checkout still passes the gateNote:
better-sqlite3needs its native binary built for the suite to run (npm install-scripts approve better-sqlite3 && npm rebuild better-sqlite3); without it 126 tests fail for unrelated reasons.🤖 Generated with Claude Code