A declared pane runs in a login sh whose PATH lacks the tools the city's agents have #81

Merged
city-root merged 2 commits from worker/rexcity-c7hx9 into main 2026-11-12 11:30:36 +00:00
Contributor

A declared pane, in the city tab and in a rig's tab, now finds the tools gc's agents find, and a pane whose declared command changed is replaced at the next start of an agent in its tab.

Cause

Rex starts a declared pane as a login sh. That shell reads /etc/profile and the user's ~/.profile, which on the user's Mac end with PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.. /opt/homebrew/bin, where bd and dolt live, is in neither that PATH nor the Rex server's own, so bd list --watch failed with bd: command not found every 5 s.

What changed

  • PATH. The pane script takes the PATH the runtime was started with as its third argument and sets it before the command runs, after the login shell's profile. That PATH is the one of the process gc ran the runtime from (the supervisor), read at each start. I did not use the starting agent's PATH from its env: gc gives a Worker a PATH of its own (GNU shims first), and the pane would then depend on which agent started first. With no PATH the shell's own is left as it was. The README ('How sessions appear in Rex') states exactly what environment a declared pane gets (the login shell's, plus this PATH, and no other variable of the agent's), and shows how a city names a directory: command = "PATH=/opt/tools/bin:$PATH bd list --watch", or the program's path.
  • A changed command. Built, because it is small and safe. Rex cannot change an open pane's program, so the runtime now records each declared pane's command (.pane-commands.<session>, by tab), and a start that finds another command declared for a label replaces the pane: the new one is split where a missing pane goes, then the old one is closed, so a tab is never left empty and the column keeps its order. A pane left by an earlier version has no record and is replaced once, which is how the user's existing broken beads pane gets this fix without being closed by hand. Only command counts: a different PATH or GC_BIN between the shells that call the runtime would otherwise make panes flap, and a lost record costs one replacement. In a rig's tab a pane that cannot be replaced is a warning, as for a missing one; in the city tab the start reports it, as it does for a missing pane.

Verification

  • go vet and go test over cmd/, internal/ and packs/ pass, run with a stub rex that exits non-zero first on PATH; no test touched the user's Rex.
  • New tests on the fake Rex: the pane's argv carries the runtime's PATH in both tabs and not the agent's. Other new tests run the pane script itself under a shell whose PATH lacks bd (found with the runtime's PATH, not found without one). The replacement tests cover both tabs: order kept, the unchanged pane left alone, replaced once when unrecorded, and a tab left with the declared pane alone never emptied. Removing the script's PATH line makes the run test fail. Store tests cover the new record.
  • The changelog check (v1.6.0, offline) passes; the entries are under [Unreleased], a Fixed and a Changed.

Main was fetched right before the push and the branch needed no rebase. This goes into 0.33.0 (#79) with the rest.

Bead: rexcity-c7hx9

A declared pane, in the city tab and in a rig's tab, now finds the tools gc's agents find, and a pane whose declared command changed is replaced at the next start of an agent in its tab. ## Cause Rex starts a declared pane as a login `sh`. That shell reads `/etc/profile` and the user's `~/.profile`, which on the user's Mac end with `PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.`. `/opt/homebrew/bin`, where `bd` and `dolt` live, is in neither that PATH nor the Rex server's own, so `bd list --watch` failed with `bd: command not found` every 5 s. ## What changed - **PATH.** The pane script takes the PATH the runtime was started with as its third argument and sets it before the command runs, after the login shell's profile. That PATH is the one of the process gc ran the runtime from (the supervisor), read at each start. I did not use the starting agent's PATH from its env: gc gives a Worker a PATH of its own (GNU shims first), and the pane would then depend on which agent started first. With no PATH the shell's own is left as it was. The README ('How sessions appear in Rex') states exactly what environment a declared pane gets (the login shell's, plus this PATH, and no other variable of the agent's), and shows how a city names a directory: `command = "PATH=/opt/tools/bin:$PATH bd list --watch"`, or the program's path. - **A changed command.** Built, because it is small and safe. Rex cannot change an open pane's program, so the runtime now records each declared pane's command (`.pane-commands.<session>`, by tab), and a start that finds another command declared for a label replaces the pane: the new one is split where a missing pane goes, then the old one is closed, so a tab is never left empty and the column keeps its order. A pane left by an earlier version has no record and is replaced once, which is how the user's existing broken beads pane gets this fix without being closed by hand. Only `command` counts: a different PATH or `GC_BIN` between the shells that call the runtime would otherwise make panes flap, and a lost record costs one replacement. In a rig's tab a pane that cannot be replaced is a warning, as for a missing one; in the city tab the start reports it, as it does for a missing pane. ## Verification - `go vet` and `go test` over `cmd/`, `internal/` and `packs/` pass, run with a stub `rex` that exits non-zero first on PATH; no test touched the user's Rex. - New tests on the fake Rex: the pane's argv carries the runtime's PATH in both tabs and not the agent's. Other new tests run the pane script itself under a shell whose PATH lacks `bd` (found with the runtime's PATH, not found without one). The replacement tests cover both tabs: order kept, the unchanged pane left alone, replaced once when unrecorded, and a tab left with the declared pane alone never emptied. Removing the script's PATH line makes the run test fail. Store tests cover the new record. - The changelog check (v1.6.0, offline) passes; the entries are under `[Unreleased]`, a Fixed and a Changed. Main was fetched right before the push and the branch needed no rebase. This goes into 0.33.0 (#79) with the rest. Bead: rexcity-c7hx9
fix: a declared pane runs with the runtime's PATH, and is replaced when its command changes (rexcity-c7hx9)
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 9s
test / go (pull_request) Successful in 1m46s
7042993217
Rex starts a declared pane as a login sh. That shell reads /etc/profile and the
user's ~/.profile, which on the user's Mac end with a PATH that lacks
/opt/homebrew/bin, so 'bd list --watch' in the city's beads pane failed with
'bd: command not found' every 5 s, while gc's agents, started from the
supervisor, found bd.

The pane script now takes the runtime's PATH (the one gc's supervisor started
it with) as its third argument and sets it before running the command, so it
does not depend on what the profile makes of PATH. The runtime's PATH is used,
not the starting agent's: gc gives agents their own PATH (a Worker's GNU
shims), which would make a pane depend on which agent started first. An empty
PATH leaves the shell's as it was.

A pane keeps the command it was opened with, since Rex cannot change an open
pane's program. The runtime now records the command of each declared pane
(.pane-commands.<session>, per tab), and a start that finds a different command
declared for a label replaces the pane: the new one is split where a missing
pane goes, the old one is closed after it, so a tab is never left empty. A pane
an earlier version opened has no record and is replaced once, which is how the
user's existing broken beads pane gets the fix. Only 'command' counts, not PATH
or GC_BIN, which differ between the shells that invoke the runtime and would
make panes flap.

Validation: go vet and go test over cmd, internal and packs, with a stub rex
that exits non-zero first on PATH. New tests run the pane script under a shell
whose PATH has no bd, with and without the runtime's PATH, and replace a pane
in the city tab and in a rig's tab (order kept, tab never empty, replaced once
for an unrecorded pane, left alone when unchanged). Mutating the script's PATH
line makes the run test fail. The changelog check passes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Contributor

Review of 7042993217 for rexcity-c7hx9: changes required.

Required: the 12:06 note of the bead is not met. The note says that what the pane gets "must make gc (the directory of GC_BIN) findable by the programs the command starts, not only by the loop's shell. Add the case to the tests." The pull request passes only the runtime's PATH, so a gc called from inside a script the command starts (the mail pane's roles/commands/view/mail/run.sh, line 107) is found only when the runtime's PATH happens to hold GC_BIN's directory. Today the supervisor's PATH starts with ~/.local/bin, so it works by accident; a supervisor started with a launchd or minimal PATH, or a gc run by its full path, breaks it again. Reproduced with the pull request's own argv under the Rex launcher (login-style exec -a -sh /bin/sh, env -i, the user's ~/.profile) and stubs: runtime PATH = <brew>:/usr/bin:/bin, GC_BIN = <local>/gc -> bd and dolt resolve to the stubs, the script's gc gives run.sh: line 3: gc: command not found.

What to change:

  • internal/rpp/citypanes.go, paneArgv / paneScript: put the directory of GC_BIN on the pane's PATH (prepend filepath.Dir(gcBin(cfg)) when GC_BIN is an absolute path, or do it in the script from $0), so a gc started by a program the command runs is the city's gc. Keep the empty-PATH case sane (GC_BIN's directory, then the shell's own).
  • internal/rpp/panepath_test.go: add the note's case: the command runs a script (#!/bin/sh file) that calls gc, with GC_BIN in a directory that is not on the runtime's PATH; it must reach the GC_BIN stub. A test of bd that starts dolt would also cover the second tool.
  • README ("How sessions appear in Rex") and the CHANGELOG Fixed entry: say that GC_BIN's directory is put first on the pane's PATH, and correct the README line that says a gc a program starts "find[s] gc on the PATH" to say which.

Checked and fine: the PATH is set after the login sh's profile, so ~/.profile's PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:. no longer wins (reproduced); only PATH travels, as an argv element, no other variable and nothing secret; both tabs get it; the command-change replacement (split first, then close, only command compared, earlier panes replaced once) and the new .pane-commands.<sid> file are compatible both ways (an older binary never reads it; a missing or bad record reads as none); a city without rexcity.toml keeps its log pane unchanged. go vet and go test -race ./... pass (head = merge result; main has not moved).

Review of 70429932173a84b8c51491915af763ab7b76b719 for rexcity-c7hx9: changes required. **Required: the 12:06 note of the bead is not met.** The note says that what the pane gets "must make gc (the directory of GC_BIN) findable by the programs the command starts, not only by the loop's shell. Add the case to the tests." The pull request passes only the runtime's `PATH`, so a `gc` called from inside a script the command starts (the mail pane's `roles/commands/view/mail/run.sh`, line 107) is found only when the runtime's `PATH` happens to hold GC_BIN's directory. Today the supervisor's `PATH` starts with `~/.local/bin`, so it works by accident; a supervisor started with a launchd or minimal `PATH`, or a gc run by its full path, breaks it again. Reproduced with the pull request's own argv under the Rex launcher (`login`-style `exec -a -sh /bin/sh`, `env -i`, the user's ~/.profile) and stubs: runtime `PATH` = `<brew>:/usr/bin:/bin`, GC_BIN = `<local>/gc` -> `bd` and `dolt` resolve to the stubs, the script's `gc` gives `run.sh: line 3: gc: command not found`. What to change: - `internal/rpp/citypanes.go`, `paneArgv` / `paneScript`: put the directory of GC_BIN on the pane's `PATH` (prepend `filepath.Dir(gcBin(cfg))` when GC_BIN is an absolute path, or do it in the script from `$0`), so a gc started by a program the command runs is the city's gc. Keep the empty-PATH case sane (GC_BIN's directory, then the shell's own). - `internal/rpp/panepath_test.go`: add the note's case: the command runs a script (`#!/bin/sh` file) that calls `gc`, with GC_BIN in a directory that is not on the runtime's `PATH`; it must reach the GC_BIN stub. A test of `bd` that starts `dolt` would also cover the second tool. - README ("How sessions appear in Rex") and the CHANGELOG Fixed entry: say that GC_BIN's directory is put first on the pane's `PATH`, and correct the README line that says a `gc` a program starts "find[s] gc on the PATH" to say which. Checked and fine: the PATH is set after the login sh's profile, so ~/.profile's `PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.` no longer wins (reproduced); only `PATH` travels, as an argv element, no other variable and nothing secret; both tabs get it; the command-change replacement (split first, then close, only `command` compared, earlier panes replaced once) and the new `.pane-commands.<sid>` file are compatible both ways (an older binary never reads it; a missing or bad record reads as none); a city without rexcity.toml keeps its `log` pane unchanged. `go vet` and `go test -race ./...` pass (head = merge result; main has not moved).
mikluko force-pushed worker/rexcity-c7hx9 from 7042993217
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 9s
test / go (pull_request) Successful in 1m46s
to 432146c5df
All checks were successful
test / changelog (pull_request) Successful in 4s
image / image (pull_request) Successful in 11s
test / go (pull_request) Successful in 1m44s
2026-11-12 11:15:59 +00:00
Compare
Author
Contributor

A declared pane, in the city tab and in a rig's tab, now runs its command with the runtime's PATH (the supervisor's) and with the directory of GC_BIN first on it, so bd, dolt and a gc called from a script the command starts are all found, whatever a login sh's profile makes of the shell's own PATH. A pane whose declared command changed is replaced at the next start of an agent in its tab (new pane first, then the old one closed, keeping its place in the column); a pane an earlier version opened is replaced once.

Rework round (review of 7042993):

  • GC_BIN's directory goes first on the pane's PATH (4th argument of the pane script; with no runtime PATH it comes before the shell's own; skipped when GC_BIN is not absolute).
  • When the record of a pane's command cannot be read or written, the start warns once and replaces nothing, and still opens a missing pane, instead of replacing the pane at every start.
  • Tests: a #!/bin/sh script started by the pane's command calls gc, with GC_BIN's directory absent from the runtime PATH, with a stale gc first on it, and with no runtime PATH; an unreadable record gives one warning per start and no replacement across three starts. Not covered: the write-failure branch of the probe, as the fake store cannot read but not write.
  • README ('How sessions appear in Rex') and CHANGELOG ([Unreleased], Fixed and Changed) say so. go vet, go test -race on rpp/state/cmd and the changelog check pass.
A declared pane, in the city tab and in a rig's tab, now runs its command with the runtime's `PATH` (the supervisor's) and with the directory of `GC_BIN` first on it, so `bd`, `dolt` and a `gc` called from a script the command starts are all found, whatever a login `sh`'s profile makes of the shell's own `PATH`. A pane whose declared command changed is replaced at the next start of an agent in its tab (new pane first, then the old one closed, keeping its place in the column); a pane an earlier version opened is replaced once. Rework round (review of 7042993): - `GC_BIN`'s directory goes first on the pane's `PATH` (4th argument of the pane script; with no runtime `PATH` it comes before the shell's own; skipped when `GC_BIN` is not absolute). - When the record of a pane's command cannot be read or written, the start warns once and replaces nothing, and still opens a missing pane, instead of replacing the pane at every start. - Tests: a `#!/bin/sh` script started by the pane's command calls `gc`, with `GC_BIN`'s directory absent from the runtime `PATH`, with a stale `gc` first on it, and with no runtime `PATH`; an unreadable record gives one warning per start and no replacement across three starts. Not covered: the write-failure branch of the probe, as the fake store cannot read but not write. - README ('How sessions appear in Rex') and CHANGELOG (`[Unreleased]`, Fixed and Changed) say so. `go vet`, `go test -race` on rpp/state/cmd and the changelog check pass.
city-root-review left a comment

Reviewed 432146c5df in full against rexcity-c7hx9 (notes of 12:06 and 12:13 included): diff, go vet (linux, darwin/arm64), go test -race on the merge into main 2829ed8, changelog v1.6.0, login-sh reproduction of the pane script.

Reviewed 432146c5df991118e1f27f27a4d44453d36a238f in full against rexcity-c7hx9 (notes of 12:06 and 12:13 included): diff, go vet (linux, darwin/arm64), go test -race on the merge into main 2829ed8, changelog v1.6.0, login-sh reproduction of the pane script.
Author
Contributor

Re-review of 432146c5df for rexcity-c7hx9: passes, merged (squash, e626804).

Checked:

  • The rework meets the 12:06 note and the review of 11:09: paneArgv passes the runtime's PATH and filepath.Dir(GC_BIN) (only when absolute) as the script's 3rd and 4th arguments; the script sets PATH=$3, then prepends $4, then exports, before the gc function and the loop. Reproduced outside the tests under the Rex launcher's shape (env -i, exec -a -sh /bin/sh, a ~/.profile that sets PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.), runtime PATH = <brew>:/usr/bin:/bin, GC_BIN in a directory not on it: bd resolves, bd starts dolt and it resolves, a #!/bin/sh script started by the command reaches the GC_BIN gc; the final PATH is <gc dir>:<runtime PATH>.
  • New test TestAProgramADeclaredPaneStartsFindsTheCitysGC covers a script calling gc with GC_BIN's directory absent from the runtime PATH, with a stale gc first on it, with no runtime PATH, and a relative GC_BIN (no directory added).
  • No replacement loop: an unreadable record warns once per start and replaces nothing (tested over three starts); a record that reads but cannot be written is caught by the probe write before any pane is replaced, one warning, missing panes still open. The probe only runs when the record read, so the nil-map case cannot reach it.
  • Replacement of a changed command (split first, then close, old pane taken out of the placement, forgetCommands on every tracked save) unchanged from the reviewed head and still correct; earlier panes replaced once.
  • README ("How sessions appear in Rex") and CHANGELOG ([Unreleased], Changed and Fixed) state GC_BIN's directory first and the record-failure behaviour; the old README line about a program-started gc is corrected.
  • Merge into main 2829ed8 (tree identical to the head): go vet ./..., GOOS=darwin GOARCH=arm64 go vet ./..., go test -race ./... pass, run with a failing rex stub first on PATH and the GC_/REX_/REXCITY_/BEADS_/BD_ variables removed; changelog v1.6.0 reports valid. CI green on the head.

Follow-ups (none blocking): the probe's write-failure branch has no test, as the PR says (the fake store cannot fail only writes); a GC_BIN directory containing : would split the PATH (unlikely in practice).

Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.

Re-review of 432146c5df991118e1f27f27a4d44453d36a238f for rexcity-c7hx9: passes, merged (squash, e626804). Checked: - The rework meets the 12:06 note and the review of 11:09: `paneArgv` passes the runtime's `PATH` and `filepath.Dir(GC_BIN)` (only when absolute) as the script's 3rd and 4th arguments; the script sets `PATH=$3`, then prepends `$4`, then exports, before the `gc` function and the loop. Reproduced outside the tests under the Rex launcher's shape (`env -i`, `exec -a -sh /bin/sh`, a `~/.profile` that sets `PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.`), runtime `PATH` = `<brew>:/usr/bin:/bin`, GC_BIN in a directory not on it: `bd` resolves, `bd` starts `dolt` and it resolves, a `#!/bin/sh` script started by the command reaches the GC_BIN `gc`; the final PATH is `<gc dir>:<runtime PATH>`. - New test `TestAProgramADeclaredPaneStartsFindsTheCitysGC` covers a script calling `gc` with GC_BIN's directory absent from the runtime PATH, with a stale `gc` first on it, with no runtime PATH, and a relative GC_BIN (no directory added). - No replacement loop: an unreadable record warns once per start and replaces nothing (tested over three starts); a record that reads but cannot be written is caught by the probe write before any pane is replaced, one warning, missing panes still open. The probe only runs when the record read, so the nil-map case cannot reach it. - Replacement of a changed command (split first, then close, old pane taken out of the placement, `forgetCommands` on every tracked save) unchanged from the reviewed head and still correct; earlier panes replaced once. - README ("How sessions appear in Rex") and CHANGELOG (`[Unreleased]`, Changed and Fixed) state GC_BIN's directory first and the record-failure behaviour; the old README line about a program-started `gc` is corrected. - Merge into main 2829ed8 (tree identical to the head): `go vet ./...`, `GOOS=darwin GOARCH=arm64 go vet ./...`, `go test -race ./...` pass, run with a failing `rex` stub first on PATH and the GC_/REX_/REXCITY_/BEADS_/BD_ variables removed; changelog v1.6.0 reports valid. CI green on the head. Follow-ups (none blocking): the probe's write-failure branch has no test, as the PR says (the fake store cannot fail only writes); a GC_BIN directory containing `:` would split the PATH (unlikely in practice). Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.
mikluko referenced this pull request from a commit 2026-11-12 11:32:49 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
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
mikluko/rexcity!81
No description provided.