Commit Graph

451 Commits

Author SHA1 Message Date
Teknium
299fcf1c69 fix: the POSIX launcher counts the custodian its daemon forked as a started hand-off
Within moments of its claim the daemon hands marker line 1 to the custodian it
forked (fdab580431e). The launcher's start check (contract C2) still waited for
the daemon's own pid, so on a host where the handover beat its next 0.1 s poll
it never matched, and once the daemon finished it reported a running update as
a failed launch (exit 70). `marker_names_handoff` now accepts line 1 naming the
daemon or a process the daemon forked; a grandchild or an unrelated pid still
does not count.

Sabotage A/B (daemon held alive 2 s after the custodian takeover, real
hand-off via the shim-progress harness): old acceptance exits 70, new exits 0
and publishes the stage. Test: the predicate over custodian/daemon/grandchild/
unrelated, red on the previous marker.sh.
2026-10-06 05:44:21 -07:00
Teknium
b2678712f5 fix: an old Desktop never reads a dead owner while the Windows hand-off dies
Same gap as the POSIX hand-off: the -MarkerOp custody watcher took line 1
over only after windows.ps1 exited (WaitForExit, then the marker lock), so
an old packaged Desktop reading in between (lines 1 and 2 only) deleted the
marker while the resumed `hermes update` or a completion survivor still
held the checkout.

Start-MarkerCustodian now names the watcher on line 1 under the marker lock
right after starting it, before any update work, and the hand-off judges
its claim as that watcher from then on ($script:MarkerOwner in
New-MarkerContext): delegate publication, heartbeat and release keep
working. Invoke-MarkerRelease stops the watcher only after the release, so
line 1 stays live until then. Invoke-MarkerCustody keeps a claim that
already names it (judged by the creation time the hand-off recorded) and
falls back to the old takeover only when the handover failed.

Tests (Windows CI lane): the kill cell holds the marker lock across
taskkill /F and runs the shipped legacy reader at once; the pre-publication
kill cell and the A7 race expect the custodian on line 1.
2026-10-06 05:44:21 -07:00
Teknium
4a7c363c0b fix: an old Desktop never reads a dead owner while the POSIX hand-off dies
The previous fix let the line-2 refresher take the marker over only AFTER
the hand-off died: it polls once a second and then waits for the A7 lock,
and until it rewrote line 1 the marker named the dead hand-off. An old
packaged Desktop (judges lines 1 and 2 alone, ignores A7 and the delegate)
reading in that gap deleted the marker and booted its backend while the
`hermes update` the hand-off started, or a completion survivor, still held
the checkout lock -- and the custodian then found no marker to keep.

Now the custodian is named on line 1 BEFORE any update work starts:
marker_refresher_start forks the refresher, then, under A7, rewrites the
claim's line 1 to the refresher's exact pid + creation time and adopts that
identity (MY_PID/MY_CT) for every later marker mutation (delegate, refresh,
release). posix.sh checks its own liveness with $$. The refresher keeps
line 2 young; if the hand-off dies it keeps the marker until the delegate
and the checkout lock are gone, then releases it. The hand-off releases the
marker before it stops the custodian, so line 1 stays live until the
release. If the handover fails (A7 busy), the old takeover-on-death path
still applies.

Test: the orchestrator-killed cell now holds the A7 lock across the SIGKILL
and runs the shipped legacy reader at once (no takeover is possible), then
keeps the post-takeover phases. Red on 5f855a2392c: {'live': None,
'kept': False}. Tests that asserted line 1 == the hand-off pid now expect
the custodian (that assertion encoded the vulnerable state).
2026-10-06 05:44:21 -07:00
Teknium
e8dc3cd63c fix: the hand-off scripts read an unopenable checkout lock as held
marker.sh::checkout_lock_held and marker.ps1::Test-CheckoutLockHeld answered
"not held" when the lock file exists but cannot be opened (root-owned after
`sudo hermes update`, or held open without sharing on Windows), while the
Desktop's own probes (checkout_held / WINDOWS_CHECKOUT_LOCK_PS) answer "held".
The script helper's reclaim then deleted a dead marker the Desktop's probe
keeps. Both scripts now fail closed on every open/probe error except a
missing file: reclaim needs a provably free checkout. Parity tests: the
POSIX probe with perl, python3 and flock(1), plus an end-to-end reclaim; the
Windows reclaim against a lock file held with no sharing (Windows CI lane).
2026-10-06 05:44:21 -07:00
Teknium
d899d5a74b fix: an old Desktop stays parked when the Windows hand-off dies mid-update
Same shape as the POSIX hand-off: windows.ps1 heartbeats line 2 from its
own process, so `taskkill /F` (no finally runs) left line 1 naming a dead
pid while the resumed `hermes update` (the line-4 delegate) or a completion
survivor still held the checkout, and an old packaged Desktop - which judges
lines 1 and 2 alone - deleted the marker and booted its backend.

After its claim the hand-off starts a hidden watcher (-MarkerOp custody
-CustodyOf <pid>, Start-MarkerCustodian). Once the hand-off exits with its
claim still published and the delegate running or the checkout lock held,
the watcher names itself on line 1 under the marker lock, heartbeats line 2
and releases the marker when both end (bounded like the R6 wait).
Invoke-MarkerRelease stops the watcher once the hand-off's own release is
decided. The Windows kill-cell test now also runs the reader be3fd671d7
shipped; that reader runner moves to a helper shared with the POSIX test.
2026-10-06 05:44:21 -07:00
Teknium
e410ffc941 fix: an old Desktop stays parked when the POSIX hand-off dies mid-update
An older packaged Desktop judges the update marker by line 1 (pid alive) and
line 2 (under 20 minutes) alone and unlinks it otherwise, never consulting
the protocol-2 delegate line or the marker helper. The line-2 refresher
exited with the hand-off script, so a SIGKILLed hand-off left line 1 naming
a dead pid while the `hermes update` it started, or a completion survivor,
still held the checkout lock: the old Desktop deleted the marker and booted
its backend into a checkout still being mutated.

The refresher now outlives the hand-off as its custodian (marker_custody):
once the hand-off is gone, if its claim is still published and the delegate
runs or the checkout lock is held, it names itself on line 1 (exact pid +
creation time, under the A7 lock), keeps line 2 young, and releases the
marker only after both are gone (bounded like the R6 wait). The test runs
the reader be3fd671d7 shipped (vendored verbatim under tests/fixtures).
2026-10-06 05:44:21 -07:00
Teknium
ed17c1cea3 fix(desktop): the hand-off waits long enough for a Desktop quit that joins a managed update
The hand-off scripts gave the Desktop a fixed 30 s (windows.ps1) or 60 s
(posix.sh) to exit, but the Desktop's quit can first join a managed SSH update
it is running, which legitimately takes longer. The hand-off then recorded a
failed update although the Desktop exited safely moments later (review H2).

Both twins now share one 150 s ceiling, measured on the clock rather than as a
loop count, and still refuse with "Nothing was changed" if the Desktop is alive
at the ceiling, so nothing is ever replaced under a live Desktop. The ceiling is
overridable through HERMES_UPDATE_DESKTOP_EXIT_SECONDS only so the self-tests
need not sit it out, like the existing pipe-drain and step-idle overrides.

Tests: a Desktop still alive at the ceiling refuses with exit 4 and never runs
the update (red on the start sha, which waited out its hardcoded 60 s); a
Desktop that exits inside the ceiling lets the update run (control).
2026-10-06 05:44:21 -07:00
Teknium
e13fb204e9 fix(update): with no marker the Desktop gate still asks whether the checkout lock is held
The script helper's `reclaim` answered `absent` the moment the marker file
was missing, before the checkout lock was looked at, and the Desktop gate
(update-marker-gate.ts liveMarkerProbe) returned "nothing runs" for a
missing marker without asking the helper at all. An update that holds the
checkout lock before it publishes its marker, or after it retired it (the
CLI paths of the stacked PRs do both), therefore let the Desktop boot a
backend into a checkout still being written.

- marker.sh marker_op_reclaim_locked / marker-claim.ps1 Invoke-MarkerOp:
  no marker -> `held` when the checkout lock (owner byte + lease bytes on
  Windows) is held, else `absent`, under the same marker lock.
- update-marker-gate.ts (gate-lane file, additive): a missing marker is also
  routed through the helper; only its positive `held` keeps the gate shut
  (blocked screen, Retry, Start anyway as for a dead marker). Any other
  answer, `error` included, proceeds as before, so a broken script never
  blocks a markerless boot.

The gate test "a live owner never reaches the helper; an absent marker
neither" pinned the missing check for the absent half; that half is now the
new "no marker: only held keeps the gate shut" case.

Review 5411223284 (open thread: update-marker-gate.ts ~193 / helper absent).
2026-10-06 05:44:21 -07:00
Teknium
510eeb2c27 test(update): the read-only-home reclaim cell gates geteuid portably
The S3 cell's root skip referenced os.geteuid directly, which
check-windows-footguns flags (absent on Windows). Same skip, resolved through
getattr.

review S3
2026-10-06 05:44:21 -07:00
Teknium
7a8249f35c fix(update): hand-offs report a nonzero exit past the commit point as installed with a follow-up
Both hand-off scripts treated ANY nonzero `hermes update` exit as ok:false
"Update failed". After the commit point `hermes update` can still exit
nonzero by design -- 130 (Ctrl-C after the code moved: receipt outcome
`interrupted`) and 1 (a parked autostash: `partial`) -- or crash after a
committed run (`success`). The Desktop then said the update failed while the
new code was installed (contract C3 / invariant 3).

The scripts now hand the update a correlation id (HERMES_UPDATE_CORRELATION_ID,
already honoured by update_receipt._launcher_correlation_id; a caller's own id
is kept) and, on a nonzero exit other than 2 (refused), read the root's
logs/update_receipts/latest.json. Only THIS run's finalized receipt counts
(matching correlation_id, finished_at set, outcome success|partial|
interrupted); a record reconciled as interrupted keeps finished_at null and
never matches. Then the result is ok:true, manual, with an `update` warning
naming the exit and outcome, and the post-commit steps (Windows: verify,
gateway start --all) still run.

posix.sh also routes its own signal handler through the same judgement: a
HUP/INT/QUIT/TERM that lands after the update committed (exit 0, or a
committed receipt) is an owed `handoff` follow-up, exit 0, not
"hand-off was interrupted".

Tests: posix live cells (RED at start) for interrupted/130, partial/1,
success/1 and an INT delivered while the committed child finishes, plus
negative controls (no receipt, failed, another run's receipt, a reconciled
unfinished record); the Windows twin cells.

review S5
2026-10-06 05:44:21 -07:00
Teknium
98d6720885 fix(update): hand-off results carry the real finish time after the R6 release wait
posix.sh::finish and windows.ps1's finally write the result (finished_at =
now) BEFORE the R6 release wait, which lasts up to 7200 s while a survivor
holds the checkout lock, and before the relaunch. The relaunched Desktop has
no expected run id and handoff-result.ts drops a non-manual result older than
30 min, so a failure or warnings result was silently discarded after a long
wait.

The early write stays (a kill during the wait still leaves a result); when the
wait actually ran, the result is published again after it with the real
finish time, unless something already consumed it. The release records that
it waited (RELEASE_WAITED / $script:MarkerReleaseWaited).

Tests: posix live cell (RED at start: finished_at 3 s before the survivor
let go) and the Windows twin with a timed checkout-lock holder.

review S2
2026-10-06 05:44:21 -07:00
Teknium
6b97fee9c2 fix(update): the Windows hand-off removes its result tmp when publishing fails
Write-Result writes <result>.<pid>.tmp and then Moves/Replaces it over the
result. When both fail (result path locked, a directory, ACLs) the catch only
logged, leaving one tmp file per hand-off beside the result. The tmp is now
removed in a finally (it is gone already after a successful publish), the
same as posix.sh's write_result.

Test (Windows live cell): with the result path occupied by a directory the
hand-off still exits 0 and leaves no .hermes-update-result.json.*.tmp.

review S4
2026-10-06 05:44:21 -07:00
Teknium
684e7d713f fix(update): posix hand-off results stay valid JSON for any control character
json_escape escaped only \ " \n \r \t. Every result/status string it builds
(FINAL_MSG, branch, channel, warnings) can carry text from git/ps/hermes
output; a raw ESC, BEL or any other char below 0x20 made the whole
.hermes-update-result.json invalid, and the Desktop dropped the outcome.

The remaining control chars are now written as \u00XX. Bash 3.2 compatible:
printf -v, no forks; the loop runs only when the string holds a control char.

Test (RED at start): json_escape over chars 1..127 plus UTF-8 and an ANSI
colour sequence round-trips through json.loads, in the C and C.UTF-8 locales.

review S7
2026-10-06 05:44:21 -07:00
Teknium
58512c1671 fix(update): posix marker ops fail closed like marker-claim.ps1 on identity and removal
Two parity gaps between marker.sh and marker-claim.ps1:

- adopt-run (--handoff-run), withdraw's `withdrawn` and `taken` accepted
  J_OWNER_STATE==2, which also covers "alive, creation time unreadable, line 2
  younger than 20 min". marker-claim.ps1 requires Test-ProcessIdentityExact
  (both creation times known, within 2 s). An unreadable ct is no proof the
  pid is still that process; these three now require ident_state 0, and
  `taken` skips our own pid like the ps1.
- reclaim / withdraw printed `reclaimed` / `withdrawn` after an `rm -f` that
  exits 0 even when it cannot unlink; the Desktop then proceeded as if the
  marker were gone. marker_remove checks the marker is gone; else `busy`, the
  ps1's answer when Remove-MarkerLocked fails.

Tests (RED at start): the three identity cases with every foreign ct
unreadable (and the readable control), and a reclaim inside a read-only
home that must answer `busy` and keep the marker.

review S3
2026-10-06 05:44:21 -07:00
Teknium
c8ac525cbf fix(update): Windows marker decisions re-read creation times instead of a pid's cached one
Get-LiveProcessCt caches a pid's creation time for the script's lifetime and
forgets it only when a probe SEES the pid dead. A delegate (the `hermes update`
child) that exits and whose pid is reused between two probes keeps the old
incarnation's time, so the release judged the unrelated new process live and
handed the marker to it (A7 rule 5), parking every later update behind it.

Every judgement made through New-MarkerContext (claim, delegate, heartbeat,
release) and the delegate line Add-MarkerDelegate writes now pass -Fresh,
which re-reads the time. Pollers that only ask "still alive?" (Wait-DesktopExit)
keep the cache.

Test (Windows live cell): a release with the delegate's pid cached at the
recorded ct but really owned by another incarnation deletes the marker instead
of handing it over. marker.sh reads /proc or ps on every call: no cache.

review S6
2026-10-06 05:44:21 -07:00
Teknium
a041e18255 fix(update): the Windows hand-off judges the checkout busy while a leased child holds it
marker.ps1::Test-CheckoutLockHeld probed only the owner byte at 1 MiB. Since R5b
every joiner the kill-on-close job refused also locks one of the 16 lease bytes
after it, and hermes_cli/update_lock.py::_try_lock treats any held lease as a
held lock. With the owner dead and a leased completion child still running, the
hand-off read the checkout as free, so the R6 release wait ended and the
Desktop's reclaim deleted the marker next to a live mutator.

Lock/Unlock now cover 1+16 bytes in one LockFile (it fails if any byte is held).
marker.sh needs no change: POSIX takes the checkout lock with flock on the whole
file and the lease bytes exist only on win32 (_take_lease).

Tests: a live Windows cell holds only a lease byte (1 and 16) and expects
`held`; a static cell, runnable on Linux, pins the probed range (RED at start:
(1048576, 1)).

review S1
2026-10-06 05:44:21 -07:00
Teknium
d549d5fb5c fix(update): a timed-out probe on a host without perl is killed with its whole tree (review desk-noperl-timeout-leak)
What: run_bounded's no-perl branch starts the probe under bash job control (set -m), so it gets its own process group and the timeout's kill -KILL -- -pid reaches its children.
Why: without perl the probe stayed in the caller's group, the group kill failed, and a hung hermes --version / update --help left its python child running.
Red: pre-fix posix.sh fails test_timed_out_probe_is_killed_with_its_whole_process_tree[absent] (grandchild alive after rc=124). Green: both [present] and [absent] pass.
2026-10-06 05:44:21 -07:00
Teknium
3bb4e87775 test(update): runtime unicode docstring matches the ProcessStartInfo UTF-8 capture
Review R8 m7: after the merge with main's 732b63d61a the probe decodes launcher
stdout as UTF-8 through ProcessStartInfo.StandardOutputEncoding and never touches
[Console]::OutputEncoding, so the test docstrings no longer claim the call sites
scope and restore it. runtime.ps1 keeps a one-line #124526 pointer at the
encoding line. Behaviour and assertions are unchanged.
2026-10-06 05:44:21 -07:00
Teknium
4f8fb4b263 test(update): windows marker timestamp test pins the run-identity line
87c67de3778 made the Windows claim carry its stable run:<id> line, so the
self-test marker is pid / started / ct / run. Pin the four-line body and the
run token grammar instead of the pre-run three-line count.

(cherry picked from commit f2bc6d679a17b17d996a27797116fe4dd7304776)
2026-10-06 05:44:21 -07:00
Teknium
450b53fab1 fix(update): require delegate publication before releasing handoff child
(cherry picked from commit c41f84ddffcc36a3a59a975d7f85bf8c5b2f19b3)
(cherry picked from commit c85844ceaca472d1260e9883f3268c01c0c6010f)
2026-10-06 05:44:21 -07:00
Teknium
b5852b3187 fix(desktop): correlate handoff receipts with stable run identity
(cherry picked from commit 87c67de3778735837b73de8d2955f83624b2b449)
(cherry picked from commit bf3ca9f63cead72e51f22d4376abe5b3504d4bf2)
2026-10-06 05:44:21 -07:00
Teknium
8f8e10deed test: posix hand-off protocol tests skip, not error, where fcntl is absent
The module imported fcntl at top level, so collecting it on Windows failed
with ModuleNotFoundError before the platforms("linux") mark could skip it
(seen in every wine2e desktop_update run). pytest.importorskip skips the
module there instead.

(cherry picked from commit 06ff00e654db11083d044d4a87d94877a04a895e)
2026-10-06 05:44:21 -07:00
Teknium
33cea9a733 fix: bash and PowerShell adopt an old Desktop's launcher bridge by one lineage rule
The two scripts disagreed on an old packaged Desktop's v1 bridge (round 5
D11): bash adopted a live launcher that is our parent but no longer the
Desktop's child when line 2 equals HERMES_UPDATE_STARTED_AT (the Desktop
quit first and the launcher was re-parented); PowerShell refused it, also
accepted a v2/delegate claim naming its parent, required a gone launcher to
be its recorded parent, and Trim()/TryParse'd the env value.

One rule now, as a pure function in both (marker_launcher_rule /
Test-MarkerLauncherRule) over the same facts, plus one env comparison
(plain ASCII digits of line 2's value). tests/scripts/desktop_update/
lineage_rule_cases.py is the shared table; the posix and Windows suites run
it, and a real-process cell per platform covers the divergent row.

(cherry picked from commit aa4b8ce704bc474d539690235c191edee3b637f2)
2026-10-06 05:44:21 -07:00
Teknium
b493b91a33 fix: hand-off probes the checkout lock for two syscalls and refreshes line 2 through the R6 wait
checkout_lock_held took the real checkout lock through flock(1) on a shell
fd and released it only when the shell closed that fd: the hold spanned
flock(1)'s exit, the wait and the close, so a concurrent `hermes update`
acquiring non-blocking was refused 223 of 3157 times in the reviewer's
tight-loop probe (round 5 D17). Now one process (perl, else python3) opens
the file, tries LOCK_EX|LOCK_NB and drops it in the next syscall: 0 of
3387. flock(1) stays the last-resort fallback; no tool still means held.

The old-Electron line-2 refresher ran only while `hermes update` ran, so
an old packaged Desktop could age-delete the marker 20 minutes into the R6
release wait (round 5 D18). The refresher now lives from the claim until
the release is decided (posix.sh), and the Windows heartbeat ticks inside
Invoke-MarkerRelease's wait. Tests shorten the cadence with the test-only
--self-test-refresh-every argument.

(cherry picked from commit 8339b25e9cfbd13f9f3e8f606e703d994b8b5410)
2026-10-06 05:44:21 -07:00
Teknium
b802f677b5 fix: windows hand-off keeps the marker while the checkout lock is held (R6)
Release waits (bounded) while any process still holds the checkout lock's
byte (hermes_cli/update_lock.py takes it with msvcrt.locking at 1 MiB), and
-MarkerOp reclaim answers `held` instead of freeing a dead marker in that
state, so a Desktop gate never opens over a surviving completion. posix.sh
withdraw now keeps a dead adopter's claim (`foreign`), like marker.ps1.

(cherry picked from commit 8a5525d26f036a3c4b5176f11ee4a590c746e2db)
2026-10-06 05:44:21 -07:00
Teknium
5d0a5c72b5 test(desktop-update): split the protocol-2/A7 Windows tests, expect hand-over at finish
- the real-process protocol tests outgrew the 300 s per-file budget on a
  native runner: split into marker_lock / handoff_lineage / marker_ops
  with a shared windows_handoff_support module
- the old-Desktop simulator writes its v1 marker LF-only, as Node did
- a live delegate at finish is now handed the claim (A7 release rule)
  instead of being kept as line 4 under a dead owner

(cherry picked from commit 88ecad1b6450c9709cce4e43a3392eb6d7b139d6)
2026-10-06 05:44:21 -07:00
Teknium
627489b58e test(desktop-update): Windows marker corpus consumer and protocol-2/A7 invariants
- every judge and release case of update_marker_corpus.json through the
  production marker.ps1 functions (live table, own pid/ct, now injected)
- real processes: claim decided inside the lock; four concurrent
  claimants over a dead marker -> one owner; old packaged Desktop cmd.exe
  wrapper lineage (start /b and waiting wrapper) adopted, unrelated live
  owner refused; -HandoffRun adoption; -MarkerOp reclaim/withdraw/busy;
  release hand-over to a live delegate; heartbeat; script killed before
  the delegate is published runs no update and leaves a dead marker

(cherry picked from commit b641f0855ceb7f3242edfd0f35c296004b7a95e0)
2026-10-06 05:44:21 -07:00
Teknium
a9f8800511 fix(desktop-update): probe .cmd launchers through cmd.exe /d /s /c
Invoke-HermesProbe handed a .cmd launcher to Process.Start with
UseShellExecute=false, letting CreateProcess pick the interpreter and
re-parse the arguments. Run it through ComSpec explicitly like the update
step does, and refuse arguments cmd.exe cannot be made to take literally.

(cherry picked from commit 0b24aab96962535268d71711c0ef564e01ac6e11)
2026-10-06 05:44:21 -07:00
Teknium
33ffcf9afd test: posix hand-off runs the shared marker corpus and protocol-2 invariants
Every judge and release case of tests/fixtures/update_marker_corpus.json
through marker.sh; real-process cells for the A7 race (flock and perl),
old-Desktop lineage, --handoff-run adoption, withdraw, a survivor holding
the checkout lock, the pre-publication kill cell, the probe process-group
kill and the line-2 refresh.

(cherry picked from commit 75a7f0b1f47c654ea8b7cf9b21cb1edd236733b5)
2026-10-06 05:44:21 -07:00
Teknium
53e6630c8a fix: windows hand-off names its hermes update child as the marker delegate at spawn
Same gap as posix: windows.ps1 killed before its `hermes update` child took
the lock left a marker that read DEAD while the update went on. The update
step now writes the child as line 4 (Add-MarkerDelegate, compare-and-swap)
right after the job-assigned start.

(cherry picked from commit d29e7f4be8626303de6a73a67b9cb94aec88157a)
2026-10-06 05:44:21 -07:00
Teknium
2245190411 fix: posix hand-off names its hermes update child as the marker delegate at spawn
A daemon killed in the second between spawning `hermes update` and that
child taking the update lock left a marker whose only identity was the dead
script: every reader judged it DEAD and a second update could start over the
first. The child now runs asynchronously just long enough for its pid to be
written as line 4 (`delegate:<pid> ct:<ct>`, compare-and-swap on our own
lines 1-3), then is waited on; HUP/INT/QUIT that land meanwhile are handled
after it exits, exactly as with the former foreground child.

(cherry picked from commit a09d2fb7cac0d730b491560ea0f970e5d227421e)
2026-10-06 05:44:21 -07:00
Teknium
d9f9920fcc test: windows system-process creation-time cell picks a pid by its real access rights
The precondition opens candidates with full and limited query rights
(what StartTime and CIM need) instead of trusting a PowerShell catch.

(cherry picked from commit f31ad7158093a650b193fdcc04fee49764252ea2)
2026-10-06 05:44:21 -07:00
Teknium
4729c737e5 fix: windows hand-off reads other users' creation times and never fails a committed update
- marker helpers move to scripts/desktop-update/marker.ps1, dot-sourced
  first (windows.ps1 2113 -> 1930 lines); a hand-off that cannot load it
  exits 3 having changed nothing. It ships in the checkout next to
  windows.ps1 and runtime.ps1, which is where the Desktop runs them from.
- creation time comes from Win32_Process.CreationDate (limited query
  rights), cached per pid while it lives: Get-Process .StartTime is access
  denied for SYSTEM/elevated/other-user pids under PowerShell 5.1, so a
  pid reused by a service after a reboot read as a live owner forever.
  Alive with an unreadable time is live only inside the 20-minute ceiling.
- -DesktopPid runs adopt the Desktop's live bridge claim only; a refused
  run exits 2 without a result file and only reopens a Desktop that is gone.
- positional parse identical to the other readers; claims publish the
  complete body with an exclusive hard link (rename fallback); a fresh
  empty marker is a claim in flight; the delegate line always carries ct.
- a follow-up step whose process tree cannot be quiesced after the commit
  point is ok:true + a manual warning (no relaunch, marker kept live),
  not "still on the previous version".
- the interrupted post-update tail is always a manual warning: re-running
  hermes update is the only remedy, so the copy says exactly that.
- the launcher probe bound is a -ProbeTimeoutSeconds parameter (default
  60), not the HERMES_UPDATE_PROBE_TIMEOUT_SECONDS environment variable.

(cherry picked from commit 65663dc6a64f942c6385b7de3ba13cdecd393387)
2026-10-06 05:44:21 -07:00
Teknium
073eb00f1d fix: posix hand-off adopts only under a Desktop pid and parses markers like every reader
Contract amendments A1-A4, posix side:
- --desktop-pid runs only adopt that Desktop's live bridge claim; with no
  bridge (the Desktop gave up after its 20 s wait) or anyone else's marker
  the script exits 2 without claiming, running, or writing a result
- a refused hand-off (exit 2) never writes .hermes-update-result.json; the
  other update owns the outcome, and a stale "still on the previous
  version" dialog could otherwise follow a successful CLI update
- positional parse: BOM/CRLF accepted, non-integer line 2 = malformed
  (dead), bad ct line = v1, line 4 only as "delegate:<pid> ct:<ct>"
- a live pid whose creation time cannot be read is live only inside the
  20-minute ceiling (unknown never means forever)
- an empty marker younger than 5 s is a claim in flight
- macOS ps lstart is rendered and parsed with TZ=UTC0 (DST-safe)

(cherry picked from commit 9d8b58063f0c2d8de6bc37b615e6e49f1abb7549)
2026-10-06 05:44:21 -07:00
Teknium
8920e24156 test: give the windows desktop-exit case an isolated runtime store
The published fixture launcher resolves its runtime from HERMES_RUNTIME_DIR;
without it the probe failed (exit 3) before the Desktop wait under test.

(cherry picked from commit 1fc5781fc994e5e0582e1ec85bc7e066af07adb9)
2026-10-06 05:44:21 -07:00
Teknium
4c4da27c36 test: windows marker timestamp test pins the v2 body
The es-ES culture case asserted the v1 two-line body; contract C1 v2 adds
line 3 ct:<unix seconds, 3 decimals>, which must stay culture-invariant
(a comma decimal would be unparseable by every other reader).

(cherry picked from commit d978ef239f77b5c62c48d377039315599de9eb74)
2026-10-06 05:44:21 -07:00
Teknium
bde2d86bc9 test: windows hand-off marker claim, release and post-commit outcomes run live
Real windows.ps1 against real owner processes and a published fixture
launcher: claim-first v2 body, live foreign owner refused untouched,
reused pid reclaimed, desktop bridge adopted with its started_at, dead
owner reclaimed, live delegate kept at finish, verify failure after a
committed update is ok+warnings with gateway start still run, result
carries started_at/warnings, banner remap warns, CPU-busy silent step
survives the watchdog, hung --help probe is bounded, a desktop that never
exits is not relaunched over, and the UI profile sweep spares live runs.

(cherry picked from commit d8421bbbe2d89f3b94b433de71369af462f3753d)
2026-10-06 05:44:21 -07:00
Teknium
b54d069815 fix: posix desktop hand-off claims the update marker first and never fails a committed update
posix.sh now implements the update-marker contract (C1/C2) as a lock:
- the daemon claims `.hermes-update-in-progress` as its first action with a v2
  body (pid, started_at, `ct:` creation time) via an atomic no-replace create
  (link(2)); a LIVE foreign owner refuses with exit 2 regardless of age, a
  marker owned by --desktop-pid is adopted keeping its started_at, a dead one
  is compare-and-deleted; liveness honours a line-4 `delegate:` (the running
  `hermes update`), so an orphaned update is never reclaimed;
- the launcher waits for the daemon's claim and exits non-zero when it never
  lands, so the Desktop does not quit into nothing;
- release is compare-and-delete and keeps a marker whose delegate is alive.

Outcomes follow C3: a legacy rebuild failure, a mac bundle stage/swap failure
or a relaunch gate after `hermes update` exited 0 is ok:true + warnings (no
more exit 6 / exit 7 "still on the previous version"). The result carries
started_at and warnings and is written via a per-pid tmp + rename.

Crash safety: start-of-run recovery restores an interrupted .app swap from its
aside copy (both swappers' suffixes) and a killed TCC heal backup, and sweeps
UI/probe litter of dead pids; the two swap renames are a signal-deferred
critical section. `hermes desktop`'s Python swappers recover the same state
instead of deleting the only copy first.

Also: probes are bounded (60 s), `hermes update` streams into the log, the
update child gets default TERM and the daemon default HUP (no SIG_IGN leak into
gateways or the relaunched app), the relaunched Linux app drops the update env,
the Desktop wait is zombie/pid-reuse aware and never relaunches over a live
app, serve-ui.py exits with its orchestrator, and the job section is parsed as
one brace group so `hermes update` rewriting posix.sh cannot shift the rest.

(cherry picked from commit c7dd9fab00b8af09321ec982d07a62f03351355d)
2026-10-06 05:44:21 -07:00
Teknium
260cef995a fix(update): every owed follow-up reaches the Desktop hand-off result
A committed update exits 0 and prints one whole "Update follow-up '<step>'
did not finish:" line per owed step (update_receipt.record_followup). The
hand-offs only reacted to the Desktop build line, so a gateway proven to
run old code (gateway_restart), a refused Windows resume, a lost
completion or a failed channel adoption ended as a plain
"Update complete.".

posix.sh collects the distinct owed steps from that line
(owed_followup_steps) and turns them into the manual result message
(DONE_NOTE, the only channel the main-based script has); a gateway_restart
adds the `hermes gateway restart` hint. windows.ps1 does the same through
its manual outcome. With #132354's add_warning protocol the same
owed_followup_steps output feeds one add_warning per step.

record_followup's docstring names the line as a protocol; a contract test
runs the real posix.sh parser and the windows.ps1 regex against it.

Review: kshitijk4poor 5411222454 regression 1 / open thread F6.
2026-10-06 03:44:49 -07:00
Teknium
e28c05e4b0 fix(update): an unbuilt Desktop app is reported by one whole line the hand-offs match (review F6-desktop-build-debt-grep)
What: build_update_products acquires npm inside the "Node dependencies" attempt and, whenever the
desktop product was requested but not built, prints `Desktop app build owed: <step> failed`.
posix.sh matches that line instead of the truncated follow-up text; windows.ps1 now projects it as
a manual outcome (it had no projection of the current follow-up at all).
Why: the 500-char follow-up leads with whichever product failed first, and an npm acquisition
failure escaped un-named, so a committed update whose Desktop was not rebuilt said "Update complete."
Red: pre-fix source_build.py -> test_unbuilt_desktop_is_named_on_one_whole_line[both] fail; pre-fix posix.sh -> truncated-followup hand-off test reports manual=false.
Green: test_source_build.py 15 passed; test_desktop_update_gateway_flag.py 3 passed. windows.ps1 needs a native run.
2026-10-06 03:44:49 -07:00
Teknium
adeecd8638 test(install): run the treeless re-run case through install.ps1 too 2026-10-05 17:32:54 -07:00
Teknium
8627946148 test(install): start the treeless re-run fixture from a real treeless clone
The bare origin had no main HEAD, so the clone had no commits and stage_repository
re-cloned it as an interrupted install; a plain-path clone also ignores --filter.
The test passed on the unfixed installer. Use -b main and a file:// URL, and assert
the checkout was converted in place.
2026-10-05 17:32:54 -07:00
Yuan Li
e7de41ca6c test(install): cover treeless checkout migration 2026-10-05 17:32:54 -07:00
Teknium
1d9bb51f6b fix(install): clone blobless, convert treeless checkouts once
Installers have cloned with --filter=tree:0 since c3e9ac87a7. A treeless
clone keeps commits only, and git requests a missing tree without telling
the server which trees it already has, so every checkout and every
path-filtered history walk re-downloads complete directory snapshots
(~0.58 MB per commit for this repo). GitHub's own guidance is that
treeless clones are for throwaway CI builds, not long-lived checkouts;
the blobless layout keeps every commit and tree local and fetches only
file contents on demand.

- install.sh / install.ps1 clone --filter=blob:none (same release tags,
  --commit pins and ancestor checks the treeless switch was made for).
- hermes update (post-update step) converts an existing tree:0 checkout once with
  `git fetch --refetch --filter=blob:none origin` (~120 MB, ~8 s
  from GitHub) and records the new filter only after it succeeds, so a
  failed refetch retries next update.
- The shallow-heal conversion unshallows as blob:none instead of tree:0.
- checkout_contains asks git with GIT_NO_LAZY_FETCH: a recorded SHA the
  checkout lacks is "not contained", never a download of that commit's
  whole history.
2026-10-05 01:30:17 -07:00
Teknium
e1ec584b57 feat(ci): cap every AGENTS.md chain below the context budget it is truncated at
scripts/ci/check_agents_md_size.py (in scripts/check and lint.yml): root <= 12k, every
AGENTS.md plus its ancestors <= 30k (the joined root->cwd block on a 128k window, minus
the per-file labels), every area file <= _MAX_HINT_CHARS read from the source so the two
cannot drift. On origin/main it reports the root and all 11 root-to-area chains over.
2026-10-04 23:05:42 -07:00
Teknium
9a98bd0165 fix(code-health): case-collision test stages blobs, not files
test_ci_only_guards_run_in_scripts_check wrote pkg/Notes.md and pkg/NOTES.md to disk,
which a case-insensitive filesystem (Windows, macOS) holds as one file, so the fixture
could not build its own premise. Each path is now staged from a blob with
`git hash-object -w` + `git update-index --cacheinfo`, which is what --staged judges.
2026-10-04 22:35:16 -07:00
Teknium
4249e5226d fix(code-health): staged-health test ignores elapsed time
test_staged_health_ignores_unstaged_policy_and_engine compared two reports byte for
byte, elapsed "(0.1s)" included, so it flaked whenever the two runs straddled a tenth
of a second (seen on native Windows). The comparison now drops the elapsed time.
2026-10-04 22:35:16 -07:00
Teknium
6cc7d4a570 fix(code-health): TS recursive rename ignores nested-scope bindings
bodyWithoutSelf treated a declaration of the function's name at any depth as a rebind,
so a renamed recursive function containing an unchanged `.map((legacy) => legacy)` kept
its old self-call text, no longer matched its base body, and lost its cap ("CC 22 >
target 20 (new code)"). Only the function's own scope (parameters, a named function
expression's name, declarations outside nested functions and classes) now stops the
normalization, and nested functions that bind the name keep their own reads, as the
Python measurer already does.
2026-10-04 22:35:16 -07:00
Teknium
16fba82ce3 fix(code-health): global/nonlocal no longer hide an import alias
_Binder.visit_Global marked the name ambiguous in the module, so `global execute` in a
function hid `from subprocess import run as execute` and HX006 (missing timeout) never
fired on `execute(cmd)`; nonlocal did the same for an enclosing function's import. A
declaration selects the outer binding, it does not rebind it: declared names now resolve
in the scope they point at, and only an assignment (or import) through the declaration
rebinds that outer name.
2026-10-04 22:35:16 -07:00
Teknium
51483660d3 fix(code-health): git hooks work with MSYS path conversion off
The hooks' judge() built its private index and tree under `mktemp -d`, a POSIX /c/...
path in Git Bash, and passed it to native git.exe and python.exe through GIT_INDEX_FILE,
--prefix and the checker path. Hermes' Windows terminal exports MSYS_NO_PATHCONV=1 and
MSYS2_ARG_CONV_EXCL=*, so those paths arrived unconverted and the hook died
("Unable to create '/c/.../index.lock'") before any check ran. judge() now hands native
tools the `cygpath -m` spelling when cygpath exists; elsewhere nothing changes.
2026-10-04 22:35:16 -07:00