Skip to content

fix(spawn): re-export PWD after worktree entry to prevent gate path failures - #192

Closed
briceparrott1 wants to merge 8 commits into
kunchenguid:mainfrom
briceparrott1:fm/fix-gate-pwd-env-h2r
Closed

briceparrott1 wants to merge 8 commits into
kunchenguid:mainfrom
briceparrott1:fm/fix-gate-pwd-env-h2r

Conversation

@briceparrott1

Copy link
Copy Markdown

Intent

The developer directed a crewmate agent to fix a firstmate bug where crewmate shells inherited a broken $PWD="." environment variable from treehouse's worktree-entry chain, causing the no-mistakes gate's post-receive hook to fail with "invalid gate path: .". Requirements: confirm the bug empirically, add a minimal, targeted re-export of PWD (via pwd -P) in bin/fm-spawn.sh right after worktree entry for ship/scout launches (not necessarily secondmates), add a matching bash-style test following existing test conventions, and document the diagnosis/rationale in AGENTS.md, without touching the external no-mistakes tool or treehouse binary. After discovering mid-session PWD corruption could recur beyond spawn time, the developer explicitly asked for the fix to be strengthened by also having bin/fm-brief.sh instruct crewmates to re-export PWD immediately before any git push to a no-mistakes gate, with that limitation likewise noted in AGENTS.md. The developer also gave explicit unblocking instructions for a wedged no-mistakes run (re-export PWD, delete-and-repush the branch) and, once genuinely confirmed by a 403 error, directed the agent to push to the captain's own fork (briceparrott1/firstmate) and open the PR from there since the agent lacked direct write access to the upstream template repo (kunchenguid/firstmate).

What Changed

  • bin/fm-spawn.sh re-exports PWD="$(pwd -P)" right after the isolation guard passes for ship/scout launches, fixing a stale $PWD="." inherited from treehouse's worktree-entry chain that broke the no-mistakes gate's post-receive hook with invalid gate path: ..
  • bin/fm-brief.sh adds mid-session guidance instructing crewmates to re-run export PWD="$(pwd -P)" immediately before any push to the no-mistakes gate, since the corruption can recur later in a long-lived session, not just at spawn time.
  • bin/backends/tmux.sh and bin/backends/herdr.sh are updated to route the PWD re-export command through each backend's own send/exec abstraction rather than a raw call.
  • AGENTS.md, docs/architecture.md, docs/scripts.md, and docs/herdr-backend.md document the diagnosis and the PWD re-export as a fixed spawn-time (and pre-push) command.
  • tests/fm-spawn-pwd-export.test.sh (new) and tests/fm-backend.test.sh cover the re-export behavior against the backend abstraction.

Risk Assessment

✅ Low: The change is a small, well-scoped defensive re-export of PWD mirroring the existing GOTMPDIR pattern, correctly guarded to non-secondmate launches and routed through the existing backend abstraction (tmux/herdr) rather than raw send-keys; the brief/AGENTS.md/docs updates and the incidental empty-array quoting fix in fm-pr-merge.sh/fm-spawn.sh (needed for bash 3.2 compatibility under set -u) are all consistent and verified, and the accompanying test, while structural rather than behavioral, matches the repo's established test conventions (e.g. fm-gotmp.test.sh).

Testing

Ran the full baseline test suite (all tests/*.test.sh, tmux 3.7 present) which passed cleanly, then specifically re-ran tests/fm-spawn-pwd-export.test.sh (new structural test asserting the PWD re-export is present, correctly ordered between GOTMPDIR and launch, and scoped to non-secondmate) and tests/fm-backend.test.sh (updated conformance test verifying the real tmux command log fm-spawn.sh produces now includes the PWD re-export send at the right point) — both passed. Because the structural tests only assert the source contains the right lines, I additionally drove a real tmux session (the actual mechanism fm-spawn.sh uses) reproducing the documented bug: simulated a pane whose real cwd is correct but whose $PWD env var is stale ("PWD=.", matching the "invalid gate path: ." failure), confirming a child process inherits the broken value, then sent the exact line bin/fm-spawn.sh now sends (export PWD=\"$(pwd -P)\") and confirmed the pane's PWD env var and any child process's inherited PWD are corrected to the real absolute path. This end-to-end tmux transcript is stronger evidence than the unit tests alone since it exercises the real send-keys mechanism and the real bug/fix behavior. Overall result: fix behaves as intended, no issues found.

Evidence: tmux transcript reproducing the stale-$PWD bug and confirming the fix

BEFORE_FIX_ENV: PWD=. child-inherited-PWD=. (after sending the exact line bin/fm-spawn.sh now sends into the pane) AFTER_FIX_ENV: PWD=/private/tmp/fm-pwd-evidence-test/worktree-real child-inherited-PWD=/private/tmp/fm-pwd-evidence-test/worktree-real


The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ cd '/tmp/fm-pwd-evidence-test/worktree-real' && export PWD=.
bash-3.2$ echo BEFORE_FIX_ENV:; env | grep ^PWD=; bash -c 'echo child-inherited-PWD=$PWD'
BEFORE_FIX_ENV:
PWD=.
child-inherited-PWD=.
bash-3.2$ export PWD="$(pwd -P)"
bash-3.2$ echo AFTER_FIX_ENV:; env | grep ^PWD=; bash -c 'echo child-inherited-PWD=$PWD'
AFTER_FIX_ENV:
PWD=/private/tmp/fm-pwd-evidence-test/worktree-real
child-inherited-PWD=/private/tmp/fm-pwd-evidence-test/worktree-real
bash-3.2$

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • command -v tmux >/dev/null; for t in tests/*.test.sh; do bash "$t"; done (baseline, all passing)
  • bash tests/fm-spawn-pwd-export.test.sh
  • bash tests/fm-backend.test.sh
  • manual tmux session: reproduced stale PWD=. bug, confirmed child process inherits broken PWD, applied the exact fm-spawn.sh PWD re-export line via tmux send-keys, confirmed PWD env var and child-inherited PWD corrected to the real physical path
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Thanks for the PR! It looks like this branch has a merge conflict with the base branch right now. When you get a chance, could you rebase onto (or merge in) the latest base branch, resolve the conflict, and push? Once GitHub shows the PR as mergeable again, it'll be picked back up for review.

Noted for firstmate#192 at 5d269a85.

@briceparrott1
briceparrott1 force-pushed the fm/fix-gate-pwd-env-h2r branch from 5d269a8 to 46e2428 Compare July 4, 2026 21:49
Brice Parrott and others added 8 commits July 4, 2026 18:54
treehouse get's subshell reliably chdir()s the crewmate pane into its
worktree but has been observed to leave $PWD stale, which every child
process (including git push's post-receive hook chain) inherits
verbatim. Re-export PWD from pwd -P, which forces physical resolution
via getcwd() instead of trusting the possibly-stale env var.
…d with the PWD re-export fix and spawn/brief changes
@briceparrott1
briceparrott1 force-pushed the fm/fix-gate-pwd-env-h2r branch from 46e2428 to e6f9b59 Compare July 4, 2026 23:01
@kunchenguid

Copy link
Copy Markdown
Owner

Thanks for the PR! It looks like this branch has a merge conflict with the base branch right now. When you get a chance, could you rebase onto (or merge in) the latest base branch, resolve the conflict, and push? Once GitHub shows the PR as mergeable again, it'll be picked back up for review.

Noted for firstmate#192 at e6f9b59e.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: this PR still looks blocked on a rebase or merge conflict fix.

If you are still interested, please rebase onto the current base branch, resolve the conflict, and push.

If I do not hear back, I may close this as inactive.

@kunchenguid

Copy link
Copy Markdown
Owner

I am closing this because it has been waiting on a rebase or merge-conflict fix since 2026-07-06, and I have not seen a comment or push since then.

If you still want to keep working on this, please reopen it or open a new PR and mention this one.

Happy to take another look when there is an update.

@pedromuller-del

Copy link
Copy Markdown
Contributor

Fixed in 45b951b2: the focused regression keeps the main lifecycle route unchanged and proves the generated status command executes the remote root's writer.
FM_TEST_REMOTE_STATUS_WRITER_ONLY=1 bin/fm-test-run.sh tests/fm-remote-secondmate-lifecycle-e2e.test.sh passed: 1 total, 0 failed.

Red evidence before the production root fix:

not ok - remote charter did not use the timestamped reply writer
FM_TEST_SUMMARY total=1 failed=1 skipped_gate=0

Separate finding, not changed by this commit: bin/fm-test-run.sh tests/fm-remote-secondmate-lifecycle-e2e.test.sh exited 1 after 594360 ms in a later cleanup phase:

REFUSED: cannot resolve the primary home for marked task areopagus-codex; refusing cleanup without its durable parent binding.
not ok - safe remote retirement failed after handoff serialization
FM_TEST_SUMMARY total=1 failed=1 skipped_gate=0

bin/fm-lint.sh completed with exit code 0.

@pedromuller-del

Copy link
Copy Markdown
Contributor

This comment was published to the wrong repository. Please disregard it.

fritznoff pushed a commit to fritznoff/starship that referenced this pull request Nov 2, 2026
…unchenguid#192)

* feat(desk-floater): smaller button, voice controls, hotkeys and dictation

The floater's talk button is half its former size and sits beside four
small controls: Stop talking, Repeat the last reply, Mute voice, and Type.
Holding Right Option talks to Firstmate like holding the button; tapping
Right Command, or clicking Type, starts and finishes dictation, which
pastes the transcript into the focused text box and restores the
clipboard, never touching Firstmate's mailbox.

bin/fm-speak.sh gains --stop, --repeat, --mute, --unmute and --muted to
back the voice controls.

* no-mistakes(review): Treat mouse clicks during hotkeys as shortcut chords

* no-mistakes(review): Skip concealed clipboard items; show muted status on Repeat

* no-mistakes(ci): I fixed the failing "Declared fork surface" check. Its "Fail on changed source without test ownership" step stopped with `no changed-test mapping for source path: desk-floater/Sources/DeskFloater.swift`. **Cause:** PR kunchenguid#155 added a rule in `bin/fm-test-run.sh` that sent `desk-floater/Package.swift` and `desk-floater/Sources/*` to `tests/fm-deepgram-desk.test.sh`. The re-base in kunchenguid#160 (70082c3) removed that rule. Since then, test ownership for fork-only paths has been declared in `tests/fork-test-registry.conf`, but nobody moved the floater rule there. No test mentions the Swift sources by name, so the runner's fallback search finds no owner either. This PR is the first change to `DeskFloater.swift` since the re-base, so it is the first to hit the gap. **Fix** (two files, not yet committed): - `tests/fork-test-registry.conf`: added `covers` rows so that `desk-floater/Package.swift` and `desk-floater/Sources/*` both map to `tests/fm-deepgram-desk.test.sh`. That is the same owner as before, now declared where fork paths belong. - `fork-surface.conf`: added `modifies = tests/fork-test-registry.conf` to the `desk-floater-voice` capability, since the capability now edits that file. **Checks run locally:** - `bin/fm-fork-surface.sh check` passes: `FORK_SURFACE OK capabilities=76 owned_paths=232`. - `bin/fm-test-run.sh --list --changed --base 62182cb…` now exits 0 and includes `tests/fm-deepgram-desk.test.sh`. The CI log is the before case: that same command stopped with exit code 2. - `tests/fm-deepgram-desk.test.sh`, `tests/fm-fork-surface.test.sh` and `tests/fm-test-run.test.sh` all pass. The last one checks the registry's no-shadow rules. **Not handled:** "Behavior portable parallel 1" was cancelled without a result. It still needs a decision from you, not a code fix

* fix(desk-floater): turn hotkeys back on after a rebuild

macOS ties the floater's Accessibility grant to the exact build, so every
rebuild left Right Option and Right Command silently off: the floater only
ever asked for the permission once, and the only sign was a small
"(keys off)" label. It now asks once per build, shows an orange ! badge
and an orange status line while keys are off, and the badge asks again and
opens the Accessibility settings.
@acthelen

Copy link
Copy Markdown

Phase 2, item C9: Schwab's seven features, governed by the account's three-layer approval check. One PR.

What it does

  • The real-money rule follows the owner's words. "the broker's published documentation plus the account's own approval check are enough; recordings stay useful but optional" (round 2) and "No: the account's approval check is enough" (C9): DOCUMENTED and TESTED capabilities are both usable with real money; NONE never is. TESTED stays as recorded evidence (its record still required). BrokerProfile.orders_tested becomes takes_real_orders (a broker that cannot report each fill gets no real order and no trading session; liquidate still reaches it, only to reduce).
  • The three-layer approval check (the owner's "Yes"): (1) what the broker reports at login (reported_capabilities, unchanged: Schwab reports the type); (2) the owner's answers for the rest: the asset-class question now offers future, crypto, bond, mutual_fund beside the option level; (3) the broker's preview as the final word: every live opening that relies on a capability the broker only documents, or trades a bond, fund, future or crypto, is previewed right before it is sent and refused loudly on any reject (needs_preview). The guard's new approval rule holds every opening to the record (asset class, short sale, option opening level, a spread's spreads level); not read, it refuses; a close never needs it.
  • Schwab's features, built from Schwab's published order schema and third-party documentation (none recorded on the account; the facts table in streamside/brokers/schwab/README.md says which is unverified):
    • spreads and multi-leg options (SpreadOrder, NET_DEBIT/NET_CREDIT/NET_ZERO, complexOrderStrategyType);
    • bracket and one-cancels-other (BracketOrder as TRIGGER + OCO, OcoOrder);
    • replace a working order (already built; now usable, so the live lane moves protective stops in one request instead of cancel+place);
    • trailing stops resting at Schwab (OrderType.TRAILING_STOP, dollars or percent, held to the stop band, closing only);
    • extended-hours trading (TradingSession: AM/PM/SEAMLESS, LIMIT and DAY only);
    • bonds and treasuries (AssetClass.BOND by CUSIP, priced in percent of face, contract terms required so the cap values it at face);
    • mutual funds (AssetClass.MUTUAL_FUND, MARKET at NAV, quantityType: SHARES).
  • What the Trader API does not do, said plainly: third-party guides say it takes no bond order (built as the schema says; Schwab's preview refuses it loudly if so); no futures or crypto order entry (refused before sending); a mutual-fund purchase by dollars is not built.
  • Broker ports: OrderPort.place_combo / preview_combo; LiveOrderGuard.check_combo. Single-leg features flow through the existing OrderSubmitter (recorded intent-first, guarded, recovered). Orders of several parts are exposed through the ports and judged by the guard, but the engine sends none yet: their event-history record and backtest/paper parity are phase 3 (C8), as the plan orders it.
  • Event history migration 23: orders.session, trail, trail_unit (recovery matches on them); instruments rebuilt to take BOND and MUTUAL_FUND (instrument_ids set aside and put back unchanged; the lossless-migration proof passes).
  • Data fixes: Schwab is asked for a share class as BRK/B (price history, quotes, orders) and read back as BRK.B; SPDR holdings drop futures lines (SPSM's RTYZ6, E-MINI RUSS 2000 DEC26, no SEDOL) and report them.
  • IBKR: what its adapter does not build is now NONE (extended hours, trailing stops, combos, and its id-keeping modify, which is not streamside's replace); its port refuses each before anything reaches IB Gateway.

Scope of this PR, and what phase 3 builds

Firstmate's decision on the review: this PR delivers the Schwab adapter, the guard and the preview for the seven features. Built in phase 3 (C8), for backtest, paper and live together on one code path:

  • the engine, an OrderSubmitter combo path with an event-history record and the RiskGate for spreads, brackets and one-cancels-other;
  • the planner, tickets and CLI producing trailing-stop, extended-hours, bond, fund and combo intents (nothing produces them yet, so none can be traded end to end today);
  • a source of bond contract terms (Schwab's instrument lookup): until then every live bond order is refused unknown_contract;
  • liquidate closing fund and bond positions (its sellable classes are still shares and ETFs).

Two consequences of the real-money rule, accepted as following the owner's rules (no attended tests; live always ready):

  • Schwab live short sales are no longer held back by a capability level: the live short switch, live arm-shorts, the account's approval record and Schwab's preview remain.
  • IBKR takes real orders once it is connected, switched on by the owner (broker_live) and the account's record approves them.

Where the owner's words and other text disagreed

  • The brokers README, ARCHITECTURE and the Schwab fixtures README said only TESTED is used with real money and that capabilities wait on attended tests; the owner's round-2 and C9 answers say documentation plus the approval check are enough. Followed the owner; those docs are rewritten.

Tests

43 test functions written (12 of them replace tests of the old attended-test rule; net +31), many parametrized, including the review round's fixes (a hand-written TRIGGER + OCO report, hand-written expected JSON per feature, the stream's share-class round trip). Highlights: the adapter contract gains promise 6, run as one shared suite over Schwab and FakeBroker for each of the seven features, with IBKR required to refuse each loudly; guard tests for approval, trailing stops, extended hours, funds and bonds, and check_combo; preview-gate tests for the third layer; core shape rules; the Schwab mapping (class shares, spread kinds, refusals); the fake broker's OCO and bracket behaviour; recovery matching on session and trail; the SPDR futures line. Golden event histories regenerated (only the three new orders columns differ). scripts/check.sh: 11412 passed, 4 skipped, about 2 minutes.

Vision fit

Accept lines advanced

  • "checks the account's approval and fails loudly when a broker behaves differently than documented": the three-layer check is the core of the change; every refusal is recorded and alerted, an unreadable reply raises.
  • "strengthens a refusal path or a fail-closed default": a new approval rule (unread record refuses openings), previews for every documentation-only opening, bonds refused without contract terms, IBKR refusing what it does not build.
  • "lets the owner look away for longer at no more risk": protective stops move by one replace, with no unprotected moment between cancel and place.
  • Scope: "Options cover everything the connected account is approved for, spreads and multi-leg orders included"; "A broker is integrated from its published API documentation; the account's own approval check decides what it may trade".

Resist lines it could touch, and why it does not

  • "lets an order reach a broker around the gates": single-leg features go through OrderSubmitter, the RiskGate and LiveOrderGuard; combos exist only on the OrderPort (held by the submitter alone, registry-checked) and are judged by check_combo; nothing in the engine sends them yet.
  • "lets anyone but the owner put a strategy live / skips the password": untouched.
  • "changes a live strategy's capital or parameters": none; replace changes how a stop is moved, not where.
  • "works in only one mode": see tension below.
  • "uses margin beyond a strategy's own declared limit": no margin logic changed.
  • "hides a failure instead of raising it": preview rejects, broker refusals and unreadable replies all fail loudly; no catch-all added.
  • "lands undocumented": brokers, Schwab, core, marketdata READMEs, ARCHITECTURE, USER_GUIDE, the fixtures README and the ERD are updated.

Tension

  • One code path: these features reach the broker ports in this PR, while backtest and paper parity (trailing stops, extended hours, combos and replace in the simulator) is phase 3 (C8), as the owner's agreed phase order puts it. Until then no strategy can emit them; they are reachable only through the broker ports.
  • The real-money rule now applies to every broker: IBKR's documented capabilities become usable once the owner switches IBKR on (it still ships switched off and no config selects it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants