Skip to content

Merge upstream/main into fork main (procevent orphan-runner sync) - #39

Merged
adibirzu merged 2 commits into
mainfrom
fm/upstream-sync-r8
Sep 8, 2026
Merged

adibirzu merged 2 commits into
mainfrom
fm/upstream-sync-r8

Conversation

@adibirzu

@adibirzu adibirzu commented Sep 8, 2026

Copy link
Copy Markdown
Owner

What this is

One commit, brought across by merge:

Commit Subject
b84e0e36 fix(procevent): reap orphaned runners and prevent launch storms (kunchenguid#3904)

This is the follow-on to PR #38's 8-commit parity merge. Scope is deliberately one commit
and nothing else. After it, git rev-list --count upstream/main ^HEAD is 0.

Merged rather than cherry-picked. b84e0e36 is upstream's tip, so a merge carries exactly
that one commit and preserves ancestry. A cherry-pick would copy the patch but leave the
commit counted as unmerged forever — which is precisely the mechanism that turned d4eb2280
into two avoidable conflicts in PR #38.

Conflicts

None. git merge-tree simulated the merge as clean beforehand (rc=0), and the merge
touched only the 13 files the upstream commit changes.

The two files that auto-merged were checked rather than assumed:

tests/fm-procevent.test.sh, bin/fm-procevent.sh and bin/fm-procevent-lib.sh are
byte-identical to upstream/main on this branch. Shell and Perl syntax check clean;
bin/fm-lint.sh and bin/fm-test-run.sh --check-coverage both pass.

An accidental live verification of the fix

While validating, a test run was interrupted mid-flight and left two runners reparented to
PID 1 — exactly the orphan the commit exists to prevent:

83845  1  bash bin/fm-procevent.sh _start           when-deadline
84642  1  bash bin/fm-procevent.sh _owner-watchdog  when-deadline

Both were gone within 10 seconds, unprompted. That is b84e0e36's new _owner-watchdog
doing its job: it re-read the home's process-event lease, could not prove it fresh once the
owning session died, and stopped the runner's whole process group. A second occurrence
self-reaped on a slightly longer horizon (~30–60 s), consistent with a lease-freshness bound
rather than a fixed delay. Before this commit, those processes are what would have survived
"for about a day."

Local test results — two flakes, attributed, not merge damage

Run on macOS (arm64) on a badly contended box (load average 9.24; the same suite took
254 s on one run and 894 s on the next, a 3.5x spread).

Suite Result
tests/fm-procevent-when.test.sh pass, 0 failures, 51 s
bin/fm-lint.sh pass
bin/fm-test-run.sh --check-coverage pass (total=220 serial=183 herdr=13)
tests/fm-procevent.test.sh run 1 1 failure — no contender acquired the stale claim
tests/fm-procevent.test.sh run 2 1 failure — orphan fixture runner did not start

The two runs failed on different assertions, and both are fixture-startup/timing
assertions — one of them a 24-way concurrent race that spawns 24 contenders and waits on a
window. Different failures across repeated runs is the signature of load-induced flake, not a
deterministic defect.

It also cannot be merge damage in the code under test: the failing test file and the
production code it exercises are byte-identical to upstream/main on this branch, and the
failing race assertion is not among the lines b84e0e36 touches. CI on Linux is the
authoritative signal here.

No background processes were left behind by any of this.

Known-red lanes inherited from main

Unchanged from PR #38 and not caused by this commit: Behavior portable parallel 2 and
Behavior tests (Herdr) (Herdr projection-teardown), plus Behavior portable serial 4, which
is a 20-minute job-timeout kill on a lane that already ran 19.67 min on main — its tests pass,
it runs out of wall clock. That one still wants a shard count 5 → 6 in its own PR.

Not done here

Not merged — leaving that to the captain.

kunchenguid and others added 2 commits September 7, 2026 22:52
…henguid#3904)

* fix(procevent): bind a source runner to the session that owns it

A process-event source runner is detached into its own process group so a
persistent source survives the turn that armed it. Nothing bounded that
detachment, so a runner could reparent to init and keep its blocking child -
and every process that child spawned - running with nothing left to reap it.
One such runner outlived its home for about a day; the cost was not the runner
but the exec churn of the poll stubs under it, which stalled every fresh
process launch on the host.

Each runner now starts a small guard beside it, in a separate process group,
that re-reads its home's process-event lease and stops the runner's whole
process group once that lease can no longer be proved fresh. Every ordinary
entry point an owning session runs refreshes the lease, and the watcher's
reconcile cycle keeps it fresh in a live home; nothing a runner spawns can
refresh it, so a source cannot certify its own owner. Scope is the owning state
root and one runner generation, never a script or process name, so a live
source in another home is untouched and a live home simply starts a
replacement runner on its next cycle.

The test scaffolding that starts real runners could not reap them either: the
bearings-board and board-render suites tracked their homes in a shell array
appended to inside a command substitution, so the array was always empty and
every listener they started survived the run. Home registration moves to a
`$$`-keyed registry in tests/lib.sh, which sweeps it from every cleanup path,
now including HUP and QUIT, and the blocking fixture stubs stop themselves at a
bound so an escaped one cannot keep spawning processes indefinitely.

Adds a regression test that reproduces the orphan shape - a reparented listener
with a live descendant tree under it - and proves the whole group and its
process churn stop once its session is gone, that an identical listener in a
home whose session is still there is untouched, and that retirement still
reaches a reparented listener and everything under it.

* no-mistakes(review): Bound source launches and fail closed on guard startup

* no-mistakes(document): Document runner lease and storm containment

* no-mistakes(ci): Fixed the Greptile watchdog finding: failed runner cleanup now retries on each watchdog tick instead of abandoning the orphaned process group. The shared state-root lease behavior remains unchanged because it is an explicitly accepted ownership policy. Verified with bash syntax checks, git diff checks, and the complete fm-procevent test suite

* test(procevent): pin that an unprovable stop is retried, not abandoned

The owner guard used to call stop_runner_pid and exit unconditionally, so a
stop it could not prove - a descendant still finishing uninterruptible work
outlives even the group signal, and an unreadable process identity proves
nothing - left a still-running expired runner with nothing watching it. That is
the best-effort reaping this mechanism exists to remove, and the fix that made
the guard retry landed without a test holding it in place.

The unprovable attempt is injected through the signal the real path actually
reads: `ps` answers exactly one process-group query for the runner with a group
it does not lead, which is how a stop that cannot be proved is reported, and
every other call is the real command. The test also asserts that the injected
attempt happened, so it cannot pass vacuously if the fixture stops arming.

Fails against the exit-after-one-attempt guard, where the runner survives its
expired lease, and passes once the guard retries on its check cadence.

* docs(procevent): scope the no-self-refresh rule to confused-agent grade

The runner-lease documentation asserted as an absolute that nothing a runner
spawns can refresh the lease, so a source cannot certify its own owner.
That overclaims what the inherited FM_PROCEVENT_IN_RUNNER marker actually
enforces.

The marker holds at confused-agent grade: a runner and its ordinary children
inherit it and skip every refresh, which is exactly the accidental case this
boundary exists for.
A source that deliberately strips the marker from its environment can still
refresh, so adversarial-grade unforgeability is explicitly out of scope and
tracked as separate follow-up design work.

This states the real scope in docs/configuration.md, which owns the operating
contract, and corrects the two matching comments in bin/fm-procevent.sh.
The process-event-sources skill keeps its cross-reference and gains one line
in its never-to-be-claimed list so the overclaim is not reintroduced from the
agent-facing side.
The lease mechanism itself is unchanged.

* no-mistakes(review): Fix process-event lease and launch pacing edge cases

* no-mistakes(review): Scope launch pacing and clarify lease boundaries

* no-mistakes(review): Reap leftover groups and use monotonic launch pacing

* no-mistakes(review): Keep guards alive across runner PID reuse

* no-mistakes(review): Use monotonic leases and simplify launch generation identity

* no-mistakes(review): Prevent pacing identity reuse and bound reused-group guards

* no-mistakes(review): Preserve active pacing state on failed registration

* no-mistakes(review): Reap reused runner groups with registration evidence

* no-mistakes(review): Avoid ambiguous group kills and encode pacing identities

* no-mistakes(review): Abort kill escalation after runner identity reuse

* no-mistakes(review): Gate group signals and prune stale pacing state

* no-mistakes(review): Document bounded PID reuse signaling safety

* no-mistakes(review): Align leaderless group ambiguity guidance

* no-mistakes(review): Expire reboot stamps and preserve publication success

* no-mistakes(review): Bind owner leases to physical state roots

* no-mistakes(document): Clarify process-event lease and pacing contracts

* fix(procevent): drop a platform-dependent post-TERM test assertion

CI ran red on two lanes that the local gate could not see.

Lint failed with SC2034 on two reads in cmd_owner_watchdog that
destructure the state-root identity into five fields while using only the
device and inode.
Local changed-file mode suppresses the cross-file codes that need
--external-sources, so the warning cleared the pre-push lint step and
failed CI's full analysis, exactly as bin/fm-lint.sh's header describes.
The unused fields now read into `_`.

The behavior shard failed on this suite's own post-TERM assertion, which
required the stubbed identity source to be consulted more than once.
Whether that happens is platform-dependent: where the runner leader keeps
waiting on its TERM-ignoring source child, the post-TERM check sees a live
leader whose identity no longer matches, and where the leader dies
promptly it sees a leaderless group carrying the same numeric id.
fm_procevent_pid_state reaches that second verdict without consulting
process identity at all, so the identity source is never read twice and
the count assertion fails through no fault of the behavior.

The case now asserts the invariant both forms share: retirement refuses,
and the ambiguous group is not signalled.
Scoping a mutation to this fixture and making the refusal signal instead
confirms the case still fails, so dropping the count does not leave it
passing vacuously.

* no-mistakes(review): Prevent superseded runners recreating stale pacing stamps

* no-mistakes(document): Document pacing and ambiguity boundaries

* fix(procevent): retire under the recorded identity source and state the home-scoped lease

The reused-group case started its runner with the proc-root override in
place, so the runner recorded a ps-derived identity, then retired it
without that override.
Where /proc exists the retirement read identity from a different source
than the one recorded, the guard correctly refused an identity it could
not confirm, and the case failed on Linux while passing on macOS.
It now retires under the same source, and clearing the stub marker first
turns that cleanup into the complementary assertion: once the ambiguity is
gone, retirement reaps the whole group instead of leaving it behind.

The lease prose claimed a runner is bound to the session that owns it,
while the mechanism binds it to the home.
That gap is what makes a replacement session or an inspection command look
like a defect: any activity in the same home refreshes the lease.
The granularity is deliberate, because a persistent source is meant to
outlive the session that armed it, and binding a runner to that session
would stop the sources this mechanism exists to keep running.
A runner whose source is no longer wanted in a live home is stopped by
reconcile when that source is retired, independently of the lease, so the
lease is the backstop for a home that is gone - the torn-down sandbox this
change bounds - and the residual is recorded as a known limit.

* no-mistakes(review): Rate-limit polls and skip superseded runner launches

* fix(procevent): build the claim-only sweep case as a runnerless owned claim

A superseded generation now observes the registration-identity mismatch,
self-retires, and releases its claim, which is the behavior we want: it
clears its own residue rather than leaving a claim with no runner for the
home sweep to find.

The claim-only sweep case was built by deleting a registration out from
under a live runner, which used to leave that runner in place. It now
makes the runner retire itself, so the sweep raced that exit and retired
one source or two depending on which won. The case failed three runs in
four, alternating between a preflight-count failure and `attempted=1`.

It now builds the state it means to test: kill the runner's group so it
cannot run its own cleanup, assert the owned claim survived that kill, and
only then drop the registration. Coverage is unchanged - a runnerless
owned claim must still be swept - and the result no longer depends on
whether the runner had exited yet. Three consecutive runs pass.

The superseded exit also skipped the runner-marker cleanup the normal path
performs. The marker is written before the launch floor is waited on, and
a home sweep counts a marker with no owned claim as a preflight failure,
so exiting without clearing it would make that home refuse to sweep.

`FM_LAVISH_POLL_RETRY_DELAY= ` trips SC1007 under the full analysis CI
runs, though not under the changed-file mode the pre-push gate uses.

* test(procevent): retire a quiet reparented listener instead of racing a storm

Explicit retirement was exercised against the spawn-churning stub, which
made it nondeterministic. Retirement refuses rather than signalling when it
cannot confirm the runner's identity, that identity is read through `ps`,
and the stub's 0.1s spawn loop starves that read often enough that a single
attempt is a race - the suite failed on this case roughly one run in four,
reporting `cannot confirm runner identity; source remains registered`.

The refusal is correct: it is the documented preserve-for-retry contract,
and a separate case already asserts it. So this is a fixture problem, not a
behavior problem.

The storm is still covered where the evidence for it lives. The owner-loss
home keeps the churning stub and still asserts its tick log stops, which is
what proves the churn ended rather than one pid going away. The retirement
home never asserted ticks; it only ever read the descendant pid, so the
spawn loop bought this case nothing while costing it determinism.

It now uses a quiet stub that still reparents and still holds a real
descendant in its process group, so the assertions are unchanged: retiring
the source must reap the reparented listener's whole group and the
descendant under it. Four consecutive runs pass.

* no-mistakes(review): Serialize registration replacement through source child launch

* chore(no-mistakes): require honest test-step scenario marking

The test step recorded scenarios as passing that were only reached through
a stubbed dependency or the executable suite, and its validator refused
them, because `pass` asserts a scenario was verified against the real live
product.

That refusal is correct, so the fix is to mark honestly rather than to
weaken the gate: a scenario driven live stays a pass and cites its live
transcript, while one reached only through a stub or the suite is recorded
as untested with the reason and a pointer to its executable coverage.
Untested scenarios are reported rather than treated as failures, so real
coverage stays visible without claiming verification that did not happen.

The instruction also forbids dropping a scenario to avoid marking it
untested, since that would hide the gap instead of stating it.

* no-mistakes(review): Remove unrelated test scenario policy

* no-mistakes(document): Clarify process-event home lease documentation

* no-mistakes(document): Correct owner guard failure wording
Brings adibirzu/firstmate current with kunchenguid/firstmate at b84e0e3,
one commit past the 8-commit parity merge that landed as PR #38.

  b84e0e3  fix(procevent): reap orphaned runners and prevent launch storms (kunchenguid#3904)

Merged rather than cherry-picked. b84e0e3 is upstream's tip, so the merge
carries exactly that one commit while preserving ancestry; cherry-picking would
copy the patch but leave the commit counted as unmerged forever, which is the
mechanism that turned d4eb228 into two avoidable conflicts in PR #38.

No conflicts. git merge-tree simulated the merge as clean beforehand, and the
merge touched only the 13 files the upstream commit changes. The two files that
auto-merged were checked rather than assumed: docs/configuration.md keeps PR
#38's FM_SECONDMATE_WAKE_STALL_SECS=180, and the tests/lib.sh change is purely
additive against fork main, so no fork helper was displaced by the new
$$-keyed home registry.
@adibirzu
adibirzu merged commit c6b0577 into main Sep 8, 2026
11 of 14 checks passed
@adibirzu
adibirzu deleted the fm/upstream-sync-r8 branch September 10, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants