Skip to content

test: capture Herdr fallback focus synchronously in Part C - #8378

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
tiago-peixoto:fm/up-8004-herdr-partc
Nov 12, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
tiago-peixoto:fm/up-8004-herdr-partc

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Intent

The captain asked (2026-11-12) to start contributions where an open upstream issue has a better chance of merging.
Fix https://github.com/kunchenguid/firstmate/issues/8004: tests/fm-backend-herdr-focus-flash-e2e.test.sh Part C fails when its focus sampler misses the short wrong-focus window, so the test fails on commits that do not touch the Herdr backend. The maintainer assistant confirmed it on main, labelled it ready-for-pr and classed it a contract-class restore. Fixes #8004.

What Changed

  • Part C of tests/fm-backend-herdr-focus-flash-e2e.test.sh now wraps fm_backend_herdr_cli so that it writes a focus snapshot to a file right after the real pane close call returns, before the restore backstop runs. A failed herdr call or a failed snapshot now fails the wrapper.
  • On a defective release, the test asserts that this at-close snapshot differs from the anchor. This replaces the old assertion that the background sampler caught at least one wrong-focus sample, which failed whenever the sampler missed the short window.
  • On a focus-preserving release, the test additionally asserts that the at-close snapshot equals the anchor. The existing checks stay: zero wrong-focus samples on that path, and final focus equal to the anchor on both paths.

Risk Assessment

✅ Low: The change touches one test file and replaces a timing-dependent sampler assertion with a synchronous focus snapshot taken inside the test's CLI override right after the real pane close, which is the same instant the production restore in bin/backends/herdr.sh reads focus, while the final exact-anchor assertion and the focus-preserving-release assertions are kept.

Testing

I drove the real test through bin/fm-test-run.sh against real Herdr 0.7.4 and 0.9.3 servers inside a disposable bwrap sandbox, with a sandbox-local default session and the bin/fm-herdr-lab.sh named lab session. The changed test passed on both releases and passed ten consecutive rounds on 0.7.4. With a ten-second sampler delay injected in sandbox scratch, the base-commit test failed with the issue 8004 message and the changed test passed on both releases. With the production restore call removed in sandbox scratch, the changed test failed at the exact-focus assertion. No baseline commands ran before this step, the worktree stayed clean, and the two pre-existing host Herdr servers were not touched. This is a test-only change, so there is no visual evidence.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Run the changed focus-flash test on real Herdr 0.7.4 (a release whose explicit close steals focus): Part C passes by observing stolen focus right after the close and the exact anchor after the restore ✅ pass live target-herdr-0.7.4.log: all seven assertions ok, 'evidence: herdr=0.7.4 protocol=16 steal_live=1', final exit status 0
Run the changed focus-flash test on real Herdr 0.9.3 (a focus-preserving release): Part C passes with focus unchanged at the close checkpoint and in every background sample ✅ pass live target-herdr-0.9.3.log: 'ok - fallback on a focus-preserving release: the plain explicit close preserved exact focus throughout', final exit status 0
Reproduce issue 8004: the base-commit test with its Part C sampler delayed ten seconds fails on Herdr 0.7.4 with the 'sampler proved nothing' message ✅ pass live slow-sampler-base-0.7.4.log: 'not ok - Part C reached the fallback on a defective release but observed no wrong-focus sample at all, so the sampler proved nothing', final exit status 1
The changed test with the same ten-second sampler delay passes on Herdr 0.7.4 and on Herdr 0.9.3 ✅ pass live slow-sampler-target-0.7.4.log and slow-sampler-target-0.9.3.log: both final exit status 0
Adversarial: remove the production restore call after the fallback close; the changed test must still fail on Herdr 0.7.4 at the exact-focus assertion ✅ pass live no-restore-mutation-0.7.4.log: 'not ok - the fallback close left focus off the anchor (w8 w8:t1 -> wA wA:t1)', final exit status 1
Run the changed test ten consecutive times on Herdr 0.7.4: every round passes Part C ✅ pass live repeat10-target-0.7.4.log: ten 'ok - fallback on a defective release' lines, final exit status 0
Evidence: Changed test on Herdr 0.7.4

Source: Changed test on Herdr 0.7.4

herdr version: herdr 0.7.4
Validation round 1
FM_TEST_BEGIN 2026-11-12T05:22:23Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:27Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3158 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3230
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3158 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3158
final exit status 0
Evidence: Changed test on Herdr 0.9.3

Source: Changed test on Herdr 0.9.3

herdr version: herdr 0.9.3
Validation round 1
FM_TEST_BEGIN 2026-11-12T05:22:35Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path note: this Herdr release preserves focus across the explicit close; continuing with outcome-only assertions
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a focus-preserving release: the plain explicit close preserved exact focus throughout
ok - version floor: herdr 0.9.3 protocol 22 is at or above the floor and preserves focus
ok - version floor: an unconfigured home stays projected on herdr 0.9.3 and the explicit opt-in agrees
evidence: herdr=0.9.3 protocol=22 steal_live=0 floor_verdict=0 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:38Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3191 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3263
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3191 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3191
final exit status 0
Evidence: Issue 8004 reproduced: base test with delayed sampler on 0.7.4

Source: Issue 8004 reproduced: base test with delayed sampler on 0.7.4

not ok - Part C reached the fallback on a defective release but observed no wrong-focus sample at all, so the sampler proved nothing final exit status 1

herdr version: herdr 0.7.4
scratch mutation applied: slow-base
Validation round 1
FM_TEST_BEGIN 2026-11-12T05:23:26Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
not ok - Part C reached the fallback on a defective release but observed no wrong-focus sample at all, so the sampler proved nothing
FM_TEST_END 2026-11-12T05:23:39Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=1 duration_ms=12350 gate_skip=false
FM_TEST_SUMMARY total=1 failed=1 skipped_gate=0 duration_ms=12422
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=12350 failed=1
FM_TEST_SLOWEST rank=1 script=/tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=12350
round 1 exit status 1
final exit status 1
Evidence: Changed test with delayed sampler on 0.7.4

Source: Changed test with delayed sampler on 0.7.4

ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor final exit status 0

herdr version: herdr 0.7.4
scratch mutation applied: slow-target
Validation round 1
FM_TEST_BEGIN 2026-11-12T05:23:39Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:23:51Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=12345 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=12417
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=12345 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=12345
final exit status 0
Evidence: Changed test with delayed sampler on 0.9.3

Source: Changed test with delayed sampler on 0.9.3

herdr version: herdr 0.9.3
scratch mutation applied: slow-target
Validation round 1
FM_TEST_BEGIN 2026-11-12T05:23:52Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path note: this Herdr release preserves focus across the explicit close; continuing with outcome-only assertions
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a focus-preserving release: the plain explicit close preserved exact focus throughout
ok - version floor: herdr 0.9.3 protocol 22 is at or above the floor and preserves focus
ok - version floor: an unconfigured home stays projected on herdr 0.9.3 and the explicit opt-in agrees
evidence: herdr=0.9.3 protocol=22 steal_live=0 floor_verdict=0 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:24:04Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=12538 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=12607
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=12538 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=12538
final exit status 0
Evidence: Restore-removal negative control on 0.7.4

Source: Restore-removal negative control on 0.7.4

not ok - the fallback close left focus off the anchor (w8 w8:t1 -> wA wA:t1) final exit status 1

herdr version: herdr 0.7.4
scratch mutation applied: no-restore
Validation round 1
FM_TEST_BEGIN 2026-11-12T05:24:05Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
not ok - the fallback close left focus off the anchor (w8	w8:t1 -> wA	wA:t1)
FM_TEST_END 2026-11-12T05:24:07Z /tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=1 duration_ms=2730 gate_skip=false
FM_TEST_SUMMARY total=1 failed=1 skipped_gate=0 duration_ms=2795
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=2730 failed=1
FM_TEST_SLOWEST rank=1 script=/tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=2730
round 1 exit status 1
final exit status 1
Evidence: Ten consecutive rounds on 0.7.4

Source: Ten consecutive rounds on 0.7.4

herdr version: herdr 0.7.4
Validation round 1
FM_TEST_BEGIN 2026-11-12T05:22:40Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:43Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3077 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3145
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3077 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3077
Validation round 2
FM_TEST_BEGIN 2026-11-12T05:22:43Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:46Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3053 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3123
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3053 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3053
Validation round 3
FM_TEST_BEGIN 2026-11-12T05:22:46Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:49Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3088 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3158
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3088 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3088
Validation round 4
FM_TEST_BEGIN 2026-11-12T05:22:49Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:52Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=2998 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3070
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=2998 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=2998
Validation round 5
FM_TEST_BEGIN 2026-11-12T05:22:52Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:55Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=2930 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3000
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=2930 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=2930
Validation round 6
FM_TEST_BEGIN 2026-11-12T05:22:55Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:22:58Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3266 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3338
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3266 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3266
Validation round 7
FM_TEST_BEGIN 2026-11-12T05:22:59Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:23:02Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3120 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3196
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3120 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3120
Validation round 8
FM_TEST_BEGIN 2026-11-12T05:23:02Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:23:05Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3272 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3343
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3272 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3272
Validation round 9
FM_TEST_BEGIN 2026-11-12T05:23:05Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:23:08Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=3140 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3216
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=3140 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=3140
Validation round 10
FM_TEST_BEGIN 2026-11-12T05:23:08Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh family=real-herdr-gated expected_gate_skip=herdr
ok - old path: the explicit last-pane close of a non-focused workspace stole focus (w3	w3:t1 -> w2	w2:t1)
ok - mitigation: every in-operation sample preserved exact focus while the doomed workspace was removed
ok - mitigation: no explicit close and no corrective focus were needed on the defective release
ok - fallback: a doomed pane holding a persistent child exhausts the proof and takes the plain explicit close
ok - fallback on a defective release: the explicit close changed focus and the backstop restored the exact anchor
ok - version floor: herdr 0.7.4 protocol 16 remains conservatively below the floor with steal_live=1
ok - version floor: an unconfigured home falls back flat on herdr 0.7.4 and the explicit opt-in still projects
evidence: herdr=0.7.4 protocol=16 steal_live=1 floor_verdict=1 fleet-session-tripwire=armed
FM_TEST_END 2026-11-12T05:23:11Z /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh exit=0 duration_ms=2965 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=3039
FM_TEST_SUMMARY_FAMILY family=real-herdr-gated count=1 duration_ms=2965 failed=0
FM_TEST_SLOWEST rank=1 script=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh duration_ms=2965
final exit status 0
Evidence: Sandbox launcher (bwrap)

Source: Sandbox launcher (bwrap)

#!/usr/bin/env bash
# usage: sandbox.sh <herdr binary> <worktree> <mode>
# Disposable sandbox: no network, own pid/ipc namespaces, host HOME, /tmp and /run hidden,
# so no host Herdr session, socket or config is reachable. Everything dies with the sandbox.
set -euo pipefail
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
exec nice -n 10 bwrap --ro-bind / / --proc /proc --dev /dev \
  --tmpfs /tmp --tmpfs /run --tmpfs ~ \
  --dir /tmp/hbin --ro-bind "$1" /tmp/hbin/herdr \
  --ro-bind "$2" /tmp/worktree --ro-bind "$here" /tmp/evidence \
  --unshare-net --unshare-pid --unshare-ipc --unshare-uts --die-with-parent --new-session \
  --clearenv --setenv HOME ~ --setenv PATH /tmp/hbin:/usr/bin:/bin \
  --setenv TERM xterm-256color --setenv LANG C.UTF-8 --setenv FM_SANDBOX 1 \
  --setenv REPEATS "${REPEATS:-1}" --chdir /tmp \
  bash /tmp/evidence/entry.sh "$3"
Evidence: Sandbox entry script with scratch mutations

Source: Sandbox entry script with scratch mutations

#!/usr/bin/env bash
# Runs only inside the bwrap sandbox (private HOME, /tmp, /run, pid and net namespaces).
# usage: entry.sh <mode>   mode: plain | slow-base | slow-target | no-restore
set -euo pipefail
[ "${FM_SANDBOX:-}" = 1 ] || exit 2
[ ! -e ~/.config ] || exit 2
mode=$1
printf 'herdr version: %s\n' "$(herdr --version)"
T=/tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh
if [ "$mode" != plain ]; then
  mkdir -p /tmp/scratch && cp -a /tmp/worktree/tests /tmp/scratch/tests
  cp -a /tmp/worktree/bin /tmp/scratch/bin
  T=/tmp/scratch/tests/fm-backend-herdr-focus-flash-e2e.test.sh
  case "$mode" in
    slow-base) cp /tmp/evidence/base-test.sh "$T" ;;
    *) cp /tmp/worktree/tests/fm-backend-herdr-focus-flash-e2e.test.sh "$T" ;;
  esac
  chmod +x "$T"
  MODE=$mode TEST=$T python3 - <<'PY'
import os
from pathlib import Path
mode = os.environ['MODE']
if mode.startswith('slow-'):
    p = Path(os.environ['TEST'])
    line = '    if [ -e "$C_OPERATION_ACTIVE" ]; then\n'
    new = line + '      sleep 10\n'
else:
    p = Path('/tmp/scratch/bin/backends/herdr.sh')
    line = '    fm_backend_herdr_projection_focus_restore "$session" "$before" "pane close" || return 2\n'
    new = '    : # mutation: omit the restore backstop\n'
s = p.read_text()
assert s.count(line) == 1
p.write_text(s.replace(line, new))
print('scratch mutation applied:', mode)
PY
fi
herdr server --session default >/tmp/default-server.log 2>&1 &
for ((i=0; i<100; i++)); do
  if herdr status --json --session default | jq -e '.server.running == true' >/dev/null 2>&1; then
    rc=0
    for ((round=1; round<=${REPEATS:-1}; round++)); do
      printf 'Validation round %s\n' "$round"
      nice -n 10 bash "$(dirname "$(dirname "$T")")/bin/fm-test-run.sh" "$T" || { rc=$?; printf 'round %s exit status %s\n' "$round" "$rc"; }
    done
    printf 'final exit status %s\n' "$rc"
    exit "$rc"
  fi
  sleep 0.1
done
printf 'Sandbox default session failed to start:\n' >&2
tail -50 /tmp/default-server.log >&2
exit 3

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.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Run the changed focus-flash test on real Herdr 0.7.4 (a release whose explicit close steals focus): Part C passes by observing stolen focus right after the close and the exact anchor after the restore ✅ pass live target-herdr-0.7.4.log: all seven assertions ok, 'evidence: herdr=0.7.4 protocol=16 steal_live=1', final exit status 0
Run the changed focus-flash test on real Herdr 0.9.3 (a focus-preserving release): Part C passes with focus unchanged at the close checkpoint and in every background sample ✅ pass live target-herdr-0.9.3.log: 'ok - fallback on a focus-preserving release: the plain explicit close preserved exact focus throughout', final exit status 0
Reproduce issue 8004: the base-commit test with its Part C sampler delayed ten seconds fails on Herdr 0.7.4 with the 'sampler proved nothing' message ✅ pass live slow-sampler-base-0.7.4.log: 'not ok - Part C reached the fallback on a defective release but observed no wrong-focus sample at all, so the sampler proved nothing', final exit status 1
The changed test with the same ten-second sampler delay passes on Herdr 0.7.4 and on Herdr 0.9.3 ✅ pass live slow-sampler-target-0.7.4.log and slow-sampler-target-0.9.3.log: both final exit status 0
Adversarial: remove the production restore call after the fallback close; the changed test must still fail on Herdr 0.7.4 at the exact-focus assertion ✅ pass live no-restore-mutation-0.7.4.log: 'not ok - the fallback close left focus off the anchor (w8 w8:t1 -> wA wA:t1)', final exit status 1
Run the changed test ten consecutive times on Herdr 0.7.4: every round passes Part C ✅ pass live repeat10-target-0.7.4.log: ten 'ok - fallback on a defective release' lines, final exit status 0
  • bash driver/sandbox.sh &lt;herdr 0.7.4 binary&gt; &lt;worktree&gt; plain - runs nice -n 10 bash bin/fm-test-run.sh tests/fm-backend-herdr-focus-flash-e2e.test.sh in the bwrap sandbox: exit 0
  • bash driver/sandbox.sh ~/.local/bin/herdr &lt;worktree&gt; plain (Herdr 0.9.3): exit 0
  • REPEATS=10 bash driver/sandbox.sh &lt;herdr 0.7.4 binary&gt; &lt;worktree&gt; plain: 10 of 10 rounds passed
  • bash driver/sandbox.sh &lt;herdr 0.7.4 binary&gt; &lt;worktree&gt; slow-base - base commit a02b0898 test with sleep 10 injected into the Part C sampler: exit 1 with the issue 8004 message
  • bash driver/sandbox.sh &lt;herdr 0.7.4 binary&gt; &lt;worktree&gt; slow-target - changed test with the same sleep 10: exit 0
  • bash driver/sandbox.sh ~/.local/bin/herdr &lt;worktree&gt; slow-target (Herdr 0.9.3): exit 0
  • bash driver/sandbox.sh &lt;herdr 0.7.4 binary&gt; &lt;worktree&gt; no-restore - scratch copy of bin/backends/herdr.sh without the fm_backend_herdr_projection_focus_restore ... &#34;pane close&#34; call: exit 1 at the exact-focus assertion
  • git status --porcelain in the worktree after all runs: clean
  • ps check after all runs: only the two host Herdr servers started in September and October remain
⚠️ **Document** - 1 info
  • ℹ️ docs/verification/runtime-backends.md:1870 - The dated Herdr 0.7.5 transcript (run on 2026-08-05) records the old Part C pass line: 'a bounded wrong-focus window of 4 samples was fully restored to the anchor'. Line 1892 repeats the four-sample count in prose. This change renames that pass line to 'the explicit close changed focus and the backstop restored the exact anchor', so a new 0.7.5 run no longer prints the recorded line. I did not edit the transcript, because it is a record of a real run and a rewritten line would be output nobody observed. The host has Herdr 0.9.3 only, and the workspace rules forbid installing 0.7.5, so I could not produce a new 0.7.5 transcript. The recorded guarantee stays true: on 0.7.5 the fallback close moves focus and the backstop restores the anchor. Follow-up option: rerun tests/fm-backend-herdr-focus-flash-e2e.test.sh against the pinned Herdr 0.7.5 binary and replace the 0.7.5 block and the line 1892 sentence with the new output.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Issues

Fixes #8004

Capture the real explicit-close focus synchronously in Part C so the defective-release assertion does not depend on background sampling. Preserve final exact-focus and focus-preserving-release assertions.

Fixes kunchenguid#8004
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This test-only change appears safe to merge.

Reviews (1) · Last reviewed commit: "test: observe Herdr fallback focus befor..." · Reviewed by Greptile

@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 12, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @tiago-peixoto for closing the loop on #8004. On 5b4c1379, Part C's CLI override takes a focus snapshot right after the real pane close returns and before the restore backstop runs. On a defective release, the test now proves the steal from that at-close snapshot rather than from the background sampler. A focus-preserving release must show an unchanged at-close snapshot as well as zero wrong-focus samples, and the exact-anchor check after the restore is unchanged. Live is go 6 of 6 on real Herdr 0.7.4 and 0.9.3. That includes the slow-sampler reproduction of #8004 on the base commit, the changed test passing under the same delay, and the no-restore mutation still failing. The attestation binds this head with no skipped steps, Greptile is 5/5 with no open threads, the quick checks pass, and the branch is current with main. Fixes #8004 is right (open, ready-for-pr). Contract-class: restore (test-only, product path unchanged). VISION aligns.

I've queued the full suite. Nothing is waiting on you.

@kunchenguid
kunchenguid merged commit cf7329b into kunchenguid:main Nov 12, 2026
36 of 37 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @tiago-peixoto — really appreciate you taking the time on this.

ayrton-saunders added a commit to ayrton-saunders/firstmate that referenced this pull request Nov 14, 2026
* test: observe Herdr fallback focus before restoration (kunchenguid#8378)

Capture the real explicit-close focus synchronously in Part C so the defective-release assertion does not depend on background sampling. Preserve final exact-focus and focus-preserving-release assertions.

Fixes kunchenguid#8004

(cherry picked from commit cf7329b)

* no-mistakes(document): Clarify synchronous fallback focus verification

* no-mistakes(ci): Fixed extension-test queue contamination by draining prior recovery wakes before cleanup-headline assertions. Reproduced the exact CI failure using the real wake interface; the injected scenario and focused regression pass after the fix. Lint and diff checks pass. Aggregate extension suite twice hit its existing 34-second coordinator deadline locally, so aggregate verification remains incomplete. Full suite is a dependent failure, not a separate defect

* Revert "no-mistakes(ci): Fixed extension-test queue contamination by draining prior recovery wakes before cleanup-headline assertions. Reproduced the exact CI failure using the real wake interface; the injected scenario and focused regression pass after the fix. Lint and diff checks pass. Aggregate extension suite twice hit its existing 34-second coordinator deadline locally, so aggregate verification remains incomplete. Full suite is a dependent failure, not a separate defect"

This reverts commit 1c65050.

* test: stabilize extension orphan recovery readiness (kunchenguid#8210)

* test: wait for recovered orphan-readiness runners instead of a fixed marker poll

The lifecycle-orphan-readiness section polled each recovered source's
handled marker for a fixed 10s after reconcile. Reconcile only confirms
each launch; each runner then polls, captures, takes a silent verdict and
a terminal verdict, and the two runners take their verdicts in turn under
the home's extension lifecycle lock. On a CPU-starved host that chain of
short host and fixture processes can exceed 10s, so the section flaked.

Wait for the recorded runner process groups to exit, bounded by the
coordinator's section-lane deadline, then assert the handled markers,
retirement and claim release. On timeout, kill the recorded runner groups
and sweep the home before failing, and track the home so any exit sweeps
it.

* no-mistakes(review): Bound recovered-runner wait to coordinator deadline

(cherry picked from commit 6125d41)

---------

Co-authored-by: Tiago <tiagop@hey.com>
Co-authored-by: ayrton-saunders <9414344+ayrton-saunders@users.noreply.github.com>
Co-authored-by: Laszlo Horanszky <40281577+Dematom1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fm-backend-herdr-focus-flash-e2e.test.sh Part C fails when its focus sampler misses the short wrong-focus window

2 participants