Repository navigation
feat(bin): add Polytoken crewmate/scout worker adapter - #7321
Conversation
…mposer; tests mid-iteration)
Add polytoken 0.8.19 as a verified crewmate/scout adapter on the captain-approved TUI-pane-plus-REST hybrid: the pane keeps inspection and backend parity while the control verbs ride the session daemon's typed REST API. Detection is ancestry alone on the anchored polytoken comm (a tool subprocess's parent is the session daemon, verified live), with the launch boundary clearing every foreign ORCA_/FM_ marker plus the fixed harness-identity set. The launch generates the per-task worker config dir (mirrored operator config with the unattended permission posture enforced, because a project config.yaml fully replaces the global config), the worker role-contract facet (no model pin, delegation and facet switching denied at the tool registry), and the worktree hook layer binding the verified busy pair - pre_user_prompt and pre_model_turn open, stop closes - to a no-argv generated writer. The readiness gate binds the session id, port, and credential into task metadata through sessions --format json and fails loudly on any first-start dialog, because the license terms are a blocker by captain decision and --accept-license-terms is never passed. Interrupt is POST /turn/cancel with its typed settle (the TUI has no interrupt chord, so no key is ever improvised), exit is /quit, and a cancelled turn's busy close is written by the control plane because no stop hook fires. The composer is the verified separated shape with polytoken as its second owner, and Enter mid-turn queues, so the busy-queued conversion applies. Crewmate and scout only: a secondmate launch is refused, and a project's own .polytoken/hooks.json is refused rather than clobbered.
…n-stdin invariant
…test env clearing
…cked polytoken files
The refused relaunch onto polytoken resolves the polytoken binary before its hook-layer refusal, so the case failed on CI hosts without the real CLI installed. A no-op stub on the fixture PATH stands in; it is never launched.
… whitespace refusal
…e stopping the worker
…opping the worker
|
Speaking as Kun's firstmate: thank you @sjennings for bringing Polytoken back on current main without a version pin, and for re-validating live on 0.9.0. The adversarial relaunch-refusal runs, where the worker, session and daemon profile survive every bad profile, are exactly the evidence that makes a new adapter easy to trust. Diff review and CI: I read the full diff against main Contract-class (my own read of the unconfigured path): new-default. The Polytoken lane itself is opt-in. But two changes reach every home's existing harnesses, even when Polytoken is never dispatched:
Both look sensible and protective, but they change existing default paths, so this can't take the auto-merge lane as-is. Once CI is green, it goes to Kun as a merge-or-leave decision. If you'd rather keep it on the auto-merge path, scoping those two changes to VISION.md: all seven rules align. Scope is noted only because of the two fleet-wide deltas above. Status: waiting on the approved CI. Nothing is required from you unless you want to make the scoping change. |
|
Speaking as Kun's firstmate: a quick heads-up, @sjennings. #6679 (the Command Code adapter) just landed on main, and it edits the same harness lists, so GitHub now reports this PR as conflicting. When you rebase onto current main, a fresh |
Intent
have firstmate grant Polytoken access to that folder at launch.
also have the launch script clean up after itself if we are making changes
Context for those words. "That folder" is the firstmate task directory,
<FM_HOME>/data/<task-id>/, where every worker brief tells the worker to keep proof, scratch output, evidence and landing-gate results. Polytoken workers' file tools (file_read, file_write and similar) are scoped to the worker's worktree and refuse paths in that directory, while shell commands reach it; two AugustStorm Polytoken workers hit this on 2026-10-15 and had to be told to fall back to shell."The launch script clean up after itself": on 2026-10-15 a
bin/fm-spawn.shlaunch on polytoken was refused after it had claimed a treehouse pool slot (refusal: the project tracked its own.polytoken/hooks.json). A retry of the same task on claude then launched into that slot, but the pool afterwards still treated the slot as free, so the next spawn of a different task was handed the same worktree, and two task records claimed one copy (teardown then refused both until one record was retired). A refused or failed launch must leave the pool and task records exactly as before it started.and add them to the pr if ci has not already run
"The pr" is #7321 ("feat(bin): add Polytoken crewmate/scout worker adapter", head branch fm/fm-polytoken-worker-adapter-v2 on the fork sjennings/firstmate, currently at 5da1709 after a metadata-only re-push that corrected commit author emails). Its CI has not run on that head: both workflows are waiting for maintainer approval (action_required).
do we need to split it? just change it to polytoken-only as the pr comment suggests
Context for that line: the maintainer reclassified the PR as new-default because spawn_abort_cleanup in bin/fm-spawn.sh (closing the endpoint, clearing wiring, removing temp root and staged launch file, dropping the late Treehouse slot claim after a failed pre-launch spawn) and the added "Running for s" match in FM_DELIVERY_BUSY_REGEX_DEFAULT apply to every harness; a Polytoken-only change keeps the PR opt-in.
What Changed
polytokenas an opt-in crewmate/scout harness, refused for--secondmate. The newbin/fm-polytoken-lib.shgenerates the per-task artifacts: a config dir that copies the operator's config and forcesdefault_permission_matcher: bypass, a sessions dir, thefirstmate-workerfacet, and a worktree.polytoken/hooks.jsonbusy wiring with a no-argv writer.bin/fm-spawn.shlaunches the TUI with--prompt, folds effort into the model ref, never passes--accept-license-terms, clears foreignORCA_*/FM_*and harness-identity env vars, and records the session port and credential in task metadata. Detection is wired intofm-harness.sh,fm-busy-lib.sh(polytoken-hook),fm-tmux-lib.sh, andfm-composer-lib.sh, andfm-control.shinterrupts over the daemon'sPOST /turn/cancel, writing the busy close itself. Relaunch refuses a bad Polytoken profile or a hook layer Firstmate didn't generate before it stops the old worker.file_read/file_writedirectly or the shell, nottool_flow. The live evidence is indocs/verification/polytoken.md.fm-polytoken-harness, live signals e2e, relaunch, teardown, pool-freshen).🤖 Generated with Claude Code
Risk Assessment
✅ Low: The round-1 fix (0099856) correctly mirrors the GIT_HOOKS_DIR pattern: the Polytoken-only abort deletions now run only after retaking SPAWN_TASK_LOCK (set globally at bin/fm-spawn.sh:2037, before any flagged path is created, and already released at :1553 so the retake succeeds uncontended) with a meta re-check, skip with a warning on contention, keep endpoint close and slot release outside the lock, and leave non-polytoken paths untouched; the new test drives a real contended lock through the spawn and the existing test at line 868 still covers the uncontended removal.
Testing
I drove six live scenarios against the real product, each in a disposable lab home with a private tmux socket and a real Treehouse pool, plus a real Polytoken 0.9.0 worker where needed. All six passed. I also ran the two targeted test files that cover the changed code, and both passed. A refused Polytoken spawn returned its slot, closed its window, and published no record. A same-id retry and a second task then each got their own slot, with no double claim. An adversarial run raced a holder onto the per-id spawn lock during the abort. The abort printed the contention warning, kept /tmp/fm-<id>, and still closed the window and returned the slot. The full live worker lifecycle passed: launch, brief, busy hooks, fm-send steer and acknowledgement, REST interrupt, relaunch, exit and teardown. The worker read and wrote proof in the task directory with its file tools. The harness-less busy union is unchanged from base. A seventh scenario, the non-Polytoken refused launch, is covered only by a fixture-driven unit test, so it is marked untested. The labs were torn down and the worktree is clean. This is a CLI/TUI change with no rendered UI surface, so the evidence is CLI transcripts and logs.Evidence: Refused Polytoken spawn leaves the real Treehouse pool clean (lab log)
Source: Refused Polytoken spawn leaves the real Treehouse pool clean (lab log)
Evidence: Refused-spawn pool lab script
Source: Refused-spawn pool lab script
Evidence: Contended per-id spawn lock: abort spares per-id paths, still returns the slot (lab log)
Source: Contended per-id spawn lock: abort spares per-id paths, still returns the slot (lab log)
Evidence: Contended-lock lab script
Source: Contended-lock lab script
Evidence: Real Polytoken worker lifecycle e2e
Source: Real Polytoken worker lifecycle e2e
Evidence: Real Polytoken worker file tools reach the task directory
Source: Real Polytoken worker file tools reach the task directory
Evidence: Busy union scoped to polytoken on a real tmux pane
Source: Busy union scoped to polytoken on a real tmux pane
union line main vs head: identical harness-less fm_pane_busy_state: idle polytoken fm_pane_busy_state: busy claude fm_pane_busy_state: idleEvidence: fm-spawn-pool-base-freshen test log
Source: fm-spawn-pool-base-freshen test log
Evidence: fm-polytoken-harness test log
Source: fm-polytoken-harness test log
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
bin/fm-spawn.sh:1593- The Polytoken abort branch in spawn_abort_cleanup deletes per-task-id paths without holding the per-id spawn lock, which this trap releases earlier, at bin/fm-spawn.sh:1553. The paths arerm -rf $TASK_TMP(/tmp/fm-$ID, which the comment at ~5108 calls a shared per-id root), the$STATE/$ID.polytoken-config,-sessionsand-sessions-v1dirs plus$ID.polytoken-busy.shvia clear_relaunch_harness_wiring (1590), and the staged launch file (1597). Concrete sequence: a refused Polytoken spawn prints its error before the EXIT trap runs, and the trap then spends time in fm_backend_kill. The intent's own scenario is an immediate retry of the same task id on another harness. That retry takes the per-id lock, finds /tmp/fm-$ID already present and owned by the same user, and reuses it (the mkdir-else branch at ~5111). The first process's trap then runsrm -rf /tmp/fm-$IDand deletes the retry's temp root. The same trap already guards against exactly this race for the git-hooks strip dir at bin/fm-spawn.sh:1660-1668, where it retakes SPAWN_TASK_LOCK with fm_lock_try_acquire and re-checks that$STATE/$ID.metais absent. Fix: put the Polytoken removals (TASK_TMP, the clear_relaunch_harness_wiring call, the staged launch file) under the same retaken SPAWN_TASK_LOCK and meta re-check, and skip them on contention. Endpoint close and slot release can stay where they are.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash refused-spawn-pool-lab.sh <worktree>: real bin/fm-spawn.sh + real treehouse pool + private tmux socket; refused polytoken spawn, then same-id retry on raw bash, then a second taskbash contended-lock-pool-lab.sh <worktree>: same real lab, with a PATH tmux shim that takes $FM_HOME/state/.spawn-pt1.lock at kill-window to stand in for a concurrent retryFM_POLYTOKEN_SIGNALS_LIVE=1 bash tests/fm-polytoken-signals-live-e2e.test.sh(real polytoken 0.9.0 worker, zai/glm-5.3-flash low)WT_ROOT=$PWD FM_POLYTOKEN_SIGNALS_LIVE=1 bash polytoken-taskdir-live.sh(real worker file_read/file_write into $FM_HOME/data/<id>/)bash busy-union-scope-live.sh <worktree>(real tmux pane rendering 'Running for 3.03s'; union diffed against base ce697402)bash tests/fm-spawn-pool-base-freshen.test.sh(includes the new contended-lock test and the non-polytoken keeps-its-window test)bash tests/fm-polytoken-harness.test.sh(submit-core ack and stale-hint coverage)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.