Repository navigation
feat(backends): add experimental explicit-only tern runtime backend - #7536
Conversation
|
Speaking as Kun's firstmate: thank you @chsong1. This is a thorough adapter: exact u64 ids, a refusal to close a hand-renamed tab, and a live run against a real tern 0.9.4 daemon with the GPU-dependent row honestly marked untested. What I checked on head Contract-class: new-default (my own read). This backend is not explicit-only. VISION.md: One captain aligns (no new captain-facing surface). Authority is in tension: auto-detection "assumes consent" where VISION asks for an option to enable, although main already auto-detects herdr and cmux the same way. Scripts vs agents aligns. Restart aligns (ids live in metadata, verified against the live tree). Delegation aligns (guarded kill refuses ambiguity). Vendor aligns (another session manager, version-gated at 0.9.4, behind the shared adapter contract). Scope aligns, but the timeout change is bundled in. Options, if you'd like this to take the auto-merge path instead of waiting on Kun's decision: make Status: waiting on CI. Nothing is needed from you unless CI comes back red or you choose one of the options above. |
|
Updated this PR to make Tern explicit-only and removed the unrelated timeout changes. The workflows for the latest head ( |
|
Speaking as Kun's firstmate: thank you @chsong1, that's exactly the shape I suggested. I re-read head
Fork CI approved: I read the diff (38 files). There are no Contract-class: opt-in (my own read, changed from new-default). Nothing changes unless Status: waiting on CI. Nothing is needed from you unless it comes back red. If it's green, this can take the opt-in auto-merge path. |
|
Updated this PR through no-mistakes at 36b04861721bd74424fa4a3bfae02ae321d94711.
Validation: both heads have matching fresh no-mistakes attestations, with Review/Test/Document/Lint completed. The final Tern evidence records passing focused Tern, backend-dispatch, teardown-safety and Paseo suites, plus live explicit/default selection and real-daemon capture/renamed-tab refusal. Live native agent state remains untested without a window control endpoint; JSON-envelope normalization has behavioral-test coverage, not a live JSON-producing backend on this host. The timeout suite and before/after stdout, exit-status and timeout-bound scenarios passed, including a real omp builtin reproduction. The earlier broad local portable attempt was not clean (fixture/environment failures and a one-hour timeout); the evidence does not claim a full local-suite pass. Latest-head GitHub CI and Require no-mistakes workflows for both PRs currently report action_required and await maintainer approval. The green checks on the earlier Tern head do not cover this new head. This now targets the opt-in auto-merge path described in your review, subject to the current head's checks and maintainer decision. No merge was performed. |
|
Speaking as Kun's firstmate: thank you @chsong1. Splitting the timeout fix into #7637 and keeping Tern explicit-only makes this a clean opt-in backend. I re-read head
Fork CI approved: I read the full diff (36 files). There are no Contract-class: opt-in (my own read, unchanged). Nothing changes unless Status: waiting on CI, not on you. If it comes back green and the PR stays mergeable, this takes the opt-in merge path. |
|
Speaking as Kun's firstmate: thanks @chsong1. Kun merged #7639 (Rex push events) to main as I can't resolve this for you without breaking the no-mistakes attestation, which binds your head Separately, Contract-class (my read, unchanged): opt-in. Tern is explicit-only. VISION: unchanged, every rule aligns. Status: waiting on you for the rebase. Once the new head is green and the attestation matches, this takes the opt-in merge path. |
|
Speaking as Kun's firstmate: thanks @chsong1 for rebasing past the I read head
Could you rebase onto My read is unchanged. Contract-class: opt-in. Tern is explicit-only: |
|
Speaking as Kun's firstmate: thanks @chsong1 for the re-raise. The new head One thing blocks it, and it sits with you: the branch is based on Could you rebase onto My read on this head is unchanged. I checked it myself, not just the description: contract class opt-in. Status: waiting on you for the rebase. Once the rebased head is green with a matching attestation, this takes the opt-in merge path. |
Tern is selected only by `--backend tern`, `FM_BACKEND=tern`, or `config/backend`; runtime auto-detection no longer routes a spawn into it. TERM_PROGRAM=tern and TERN_PANE reach every descendant process of a Tern block, including a tmux server or Herdr client started inside it, so an inherited marker never proves the captain chose Tern. - bin/fm-backend.sh: drop the tern arm from fm_backend_detect and the auto-detected tern NOTICE from fm_backend_name, which became unreachable with the arm. - Replace the tern detect-precedence and auto-detect-notice tests with test_backend_tern_is_never_autodetected, mirroring the Paseo case, and drop the Tern-marker unsets that only guarded detection hermeticity. - docs/tern-backend.md: replace "Runtime detection" with "Selection is explicit"; fm-spawn.sh and adapter headers, architecture, configuration, README, and the operational-home-layout skill now list tern beside zellij, orca, and Paseo as never auto-detected.
|
Speaking as Kun's firstmate: thank you @chsong1 for the rebase. That's exactly what was needed. What I checked on head CI: everything is green except serial 1, which hit main's 30-minute job cap. That cap comes from main, not from this branch, and it stays until main's own fix lands. I re-ran the failed job. Contract-class (mine): opt-in. Tern runs only when someone picks it with Next step: this isn't waiting on you. Once serial 1 is green and the branch is still clean against main, it takes the opt-in merge path. |
|
Speaking as Kun's firstmate: this is merged. Thank you @chsong1 — really appreciate you taking the time on this. Tern lands as an explicit-only experimental backend ( |
Intent
Update existing upstream PR #7536 to the maintainer's offered auto-merge path. Rebase the experimental Stencil Tern backend onto upstream main preserving Paseo integration. Make Tern explicit-only: only --backend tern, FM_BACKEND=tern, or config/backend select it; ambient TERM_PROGRAM=tern and TERN_PANE must not change the default. Update affected docs and behavior tests, retain existing backend safety, and remove the unrelated timeout library change and its test from this PR. The caller ships that timeout fix separately from fix/timeout-type-p; do not create its companion in this run. Supervisor explicitly superseded old run 01M5BHMM9VHBQ6M020PSPZ5W22 and authorized abort, guarded archive-backed custody recovery, rebuilding without obsolete-run fix commits, then exact-SHA archival and retirement of only the stale private mirror ref. Those steps are complete; archive refs remain preserved. Validate this revised head and let the pipeline push to chsong1/firstmate branch tern-backend, update existing upstream PR #7536 with a fresh head-bound attestation, and verify CI. No direct push outside the pipeline, no merge, no additional PRs or upstream comments. The caller posts exactly one review reply after both PRs exist. Local evidence: lint, docs, invariants and backend smoke pass; six focused backend/bootstrap/control/safety scripts pass, but the runner's nested session-lock fixture fails. Broad portable run had host/fixture failures and a one-hour timeout, not a clean pass; evaluate required targeted behavior honestly.
What Changed
bin/backends/tern.sh, an experimental Stencil Tern backend you can spawn tasks on. Each home gets one Tern session namedfm-<hometag>, and each task is a renamed keep-open tab. Metadata is validated aswindow=<session-id>:<block-id>plustern_session_id,tern_tab_idandtern_block_id, where every id is a decimal u64. The backend also supports visible-viewport capture withtern capture --surfaces, sending keys and text, and reading native agent state throughtern ctl; when that read is unavailable, state degrades instead of failing. Closing an endpoint is refused if the block is still present, the inventory can't be read, or the task tab was renamed.terninto the shared backend layer and its callers: the known/spawn lists, required tools (tern jq treehouse), and the spawn, control, busy-state, composer, supervise-daemon, bootstrap, AFK-launch and test-runner paths. Tern can only be selected explicitly, through--backend tern,FM_BACKEND=ternorconfig/backend.fm_backend_detectignores the inheritedTERM_PROGRAM=ternandTERN_PANEmarkers, so a tmux or Herdr session started inside a Tern block keeps its normal default.docs/tern-backend.mdand updates the README, architecture, configuration, scripts and runtime-backend verification docs, plus the harness and skill references. Adds tern unit and smoke tests (tests/fm-backend-tern*.test.sh) and atests/tern-test-safety.shguard that refuses to close a session hosting the caller's own block. Extends the existing backend, bootstrap, busy-state, control, daemon, teardown-safety and test-run tests to cover tern.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The Tern backend is experimental, explicit-only and well fenced: tests cover that fm_backend_detect ignores TERM_PROGRAM=tern and TERN_PANE, stop and relaunch verbs still refuse tern, kill refuses on an unreadable inventory, a moved block, a renamed tab, or a block that survives its close, and capture JSON normalization and the narrowed Carly projection are correctly implemented and tested. The timeout library and its test are unchanged from base, and the Paseo integration is intact.
Testing
Backend selection was driven against the real fm-backend dispatcher. Ambient TERM_PROGRAM=tern/TERN_PANE fall back to tmux; only FM_BACKEND=tern or config/backend selects tern. The Tern adapter was driven against the real tern 0.9.4 daemon in a disposable, guarded fm-test- session, which was removed afterwards; the user's Default and primary sessions were not touched. Capture returns screen text and target labels are verified. A hand-renamed task tab makes kill refuse and leaves the block open; once the title is restored, kill closes it and a repeat kill does nothing. The repo's real-Tern smoke test skips on this host because
tern ctl statehas no window endpoint, so live native agent state could not be proven (it readsunknown). The JSON.textcapture normalization was covered only by the fake-CLI behaviour suite, because this host's tern returned plain text. The timeout-exclusion and Paseo checks are a diff check plus a behaviour suite, not live runs. The focused tern, backend, teardown-safety and Paseo suites all pass. No artifacts were left in the worktree.tern capture --surfaces, so the JSON branch was only exercised through the fake-CLI behav…tern ctl statefails (/tmp/tern.sock connection refused): no Tern window ortern servecontrol endpoint runs on this headless host, and starting a GUI window is out of reach here. Live native stat…Evidence: Backend selection transcript (explicit-only Tern)
Source: Backend selection transcript (explicit-only Tern)
Evidence: Live real-tern adapter transcript (capture, rename refusal, kill, cleanup)
Source: Live real-tern adapter transcript (capture, rename refusal, kill, cleanup)
Evidence: tern behaviour suite log
Source: tern behaviour suite log
Evidence: backend dispatcher suite log
Source: backend dispatcher suite log
Evidence: teardown endpoint safety log
Source: teardown endpoint safety log
Evidence: Paseo suite log
Source: Paseo suite log
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
🔧 **Rebase** - 21 issues found → no changes applied ✅
.agents/skills/harness-adapters/references/harness/commandcode.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backend.agents/skills/operational-home-layout/SKILL.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backend.agents/skills/stuck-crewmate-recovery/SKILL.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendCONTRIBUTING.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendREADME.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendbin/fm-backend.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendbin/fm-bootstrap.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendbin/fm-control-lib.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendbin/fm-control.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendbin/fm-spawn.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendbin/fm-supervise-daemon.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendbin/fm-test-run.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backenddocs/architecture.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backenddocs/configuration.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backenddocs/documentation-audiences.json- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backenddocs/scripts.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backenddocs/verification/runtime-backends.md- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendtests/fm-backend.test.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendtests/fm-bootstrap.test.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendtests/fm-control.test.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backendtests/fm-teardown-endpoint-safety.test.sh- merge conflict rebasing onto refs/remotes/no-mistakes-push/tern-backend🔧 No changes applied.
✅ Re-checked - no issues remain.
✅ No issues found.
🔧 No changes applied.
✅ Re-checked - no issues remain.
bin/backends/tern.sh:491- The branch's own verification record contradicts how the adapter parsestern capture --surfacesoutput. docs/verification/runtime-backends.md:2298 records thattern capture <block> --surfaceson tern 0.9.4 returnedJSON {"block","text"}. But the adapter header (tern.sh:51-52) and both capture paths treat the output as plain screen text. fm_backend_tern_capture (tern.sh:491-492) pipes the raw output totail -n, and fm_backend_tern_visible_capture (tern.sh:503-507) trims it to the block's rows. The composer read (tern.sh:515, consumed by fm_backend_tern_composer_state at tern.sh:535-536) inherits that. If the recorded shape is right, every Tern capture is a JSON envelope whose transcript newlines are escaped. In that case the row trim cuts JSON rather than screen rows, the shared composer, dialog and harness-signature classifiers never see real lines, and peek and rendered-tail readers get JSON. None of this errors; it just silently reads as unknown, or shows the wrong text. The smoke test's substring check (tests/fm-backend-tern-smoke.test.sh:122-126) and the fake-CLI fixtures (plain text) cannot tell the two shapes apart. Smallest fix: in one shared helper, when the capture output parses as a JSON object with a string.text, use.text, otherwise use the raw output; apply it before thetail -nin both capture functions. Then make the adapter header or the verification row agree on the real shape.docs/tern-backend.md:45- The doc says a cleared-environment launch keepsTERM_PROGRAM"on abackend=terntask only". The launch floor in bin/fm-spawn.sh:6440 keepsTERM_PROGRAMfor every backend, with no tern condition. The sentence describes a tern-specific behaviour that does not exist; it should say the floor keeps whateverTERM_PROGRAMthe pane has, which isterninside a Tern block.🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 No changes applied.
2 issues (1 warning, 1 info) still open:
bin/backends/tern.sh:159- This conflicts with a recorded human decision, so it needs your call. On this branch the user chose to fix the earlier simplification finding: narrow FM_BACKEND_TERN_AGENTS_LUA to {pane = a.pane, state = a.state, alive = a.alive}, then update the docs/tern-backend.md Lua snippet and the agent_json fixture to match. The current head still requests eight fields (pane, session, tab, host, state, alive, busy, program). The only consumer, fm_backend_tern_native_state_raw (tern.sh:605-615), reads just pane, state and alive. The docs still describe the wide projection: docs/tern-backend.md:113 (Lua snippet) and docs/tern-backend.md:120 ("two short names (host,program)"). Concrete risk: ifhostorprogramis a user-chosen label that carries a raw newline, every native read degrades tounknown. That is the exact failure 6f5555de set out to prevent. The rebuild intent says obsolete-run fix commits were deliberately dropped, so this may be intentional. Confirm whether the narrowing decision still stands. If it does, narrow the projection plus the doc snippet and fixture. If not, record that it was superseded.docs/tern-backend.md:168- The Active limits bullet says the away-mode supervisor accepts "onlytmuxandherdrsupervisor panes". But bin/fm-supervise-daemon.sh:218 sets FM_SUPERVISOR_SUPPORTED_BACKENDS="tmux herdr rex", and docs/configuration.md lists rex as supported too. The tests/fm-daemon.test.sh:80 failure message has the same omission ("away mode supports only tmux and herdr"). Change both to name tmux, herdr and rex.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
tern ctl stateneeds a Tern window control endpoint. On this hostternreports 'no GPU adapter' and cannot open a window, and a headlesstern daemonhas no window, so the smoke test skipped. Run…bash tests/fm-backend.test.sh(includes test_backend_tern_is_never_autodetected and the paseo never-autodetected case)bash tests/fm-backend-tern.test.sh(includes fm_backend_tern_kill refusal when the tab title changed)bash tests/fm-backend-tern-smoke.test.sh(skipped cleanly: the host's Tern daemon has no window control endpoint)bash tests/fm-teardown-endpoint-safety.test.shLive:bin/fm-lab-home.sh createlab home with a private tmux socket, a real git project and a disposable origin; realbin/fm-spawn.shwith ambient TERM_PROGRAM=tern TERN_PANE=2, no TMUX, no FM_BACKEND and no config/backendLive: privatetern daemon --socket <lab>/ternsock/d.sockwith TERN_CONFIG_DIR inside the lab; realbin/fm-spawn.shwith FM_BACKEND=tern, then config/backend=tern, then--backend ternLive:tern rename <block> hand-renamed, thenbin/fm-teardown.sh <id>without --force (refuses, keeps records), with --force (refuses the close, removes records), and after restoring the title (closes exactly the task block)git diff --stat origin/main HEAD -- bin/fm-timeout-lib.sh <timeout tests>(empty) and merge-base == origin/main df9eb03a✅ No issues found.
tern capture --surfaces, so the JSON branch was only exercised through the fake-CLI behav…tern ctl statefails (/tmp/tern.sock connection refused): no Tern window ortern servecontrol endpoint runs on this headless host, and starting a GUI window is out of reach here. Live native stat…Backend selection throughfm_backend_name+fm_backend_validate_spawnwith a clean env: TERM_PROGRAM=tern TERN_PANE=7 alone; the same markers inside $TMUX; FM_BACKEND=tern; config/backend=tern; and config/backend=tmux alongside the Tern markersLive driver against the realtern0.9.4 daemon in a guardedfm-test-gate-<pid>session: container_ensure, create_task, target_exists with matching and mismatched labels, send_text_line, rawtern capture --surfacescompared with fm_backend_tern_capture/visible_capture, composer/agent/busy/native state,tern renameof the task tab thenfm_backend_kill, restore the title then kill, idempotent re-kill, guarded session cleanupbash tests/fm-backend-tern-smoke.test.sh(skipped: no window control endpoint)bash tests/fm-backend-tern.test.sh(72 ok)bash tests/fm-backend.test.sh(34 ok)bash tests/fm-teardown-endpoint-safety.test.sh(27 ok)bash tests/fm-backend-paseo.test.sh(48 ok)git diff --name-only 9fe25bca..HEAD | grep -i timeout(no timeout files)✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.