Commit Graph

137 Commits

Author SHA1 Message Date
yliu325
b81e71addd feat(cron): optional per-job grace_minutes override
The catch-up window (how late a missed cron occurrence may run instead of being skipped) was
half the job's period, clamped to 120s-2h, for every job. A job can now override it outright:
0-1440 minutes, `0` meaning never catch up.

`grace_minutes` is a real 0, not "unset" — and the obvious write pattern would eat it:
`v in {None, "", False}` (the `workdir` update lambda) and `if value:` both treat `0` as
False in Python. Both doors therefore share `jobs_time.normalize_grace_minutes`, reads test
`is None`, and the renderer formats before testing truthiness.

The override moves the dispatch stamp too: `_classify_dispatch_lateness` and the dispatch
health metric read the same window, so a job the scheduler calls "late" is never reported
overdue by the dashboard.

Refused on `once`/`interval` schedules: the window describes a missed wall clock, and a
duration has none.

Split from the timezone commit so it can be reverted alone.
2026-10-28 19:40:40 -07:00
yliu325
bfa67878cd fix(cron): per-job timezone drives schedule compute and due-scan
A job may pin its own IANA timezone; its cron expression is then that zone's wall clock,
independent of the profile's configured timezone. Absent/None inherits the profile, so an
existing jobs.json keeps byte-identical behaviour and needs no migration.

The dispatch path needs the pin as much as the compute does. `compute_next_run()` resolves
the zone as job pin -> profile zone -> base offset, and every site that writes `next_run_at`
now passes it (advance, claim, resume, re-arm, recovery, and the quota/unreachable
planners); one missed site re-fires or skips a slot because the stored instant and the
expression would be read in different zones.

`_evaluate_due_job()` normalizes the stored instant into the JOB's zone, which hands every
downstream cron predicate the job's clock, and a pinned job skips
`_repair_timezone_shifted_cron` outright. That repair exists for jobs that FOLLOW the profile
zone across a zone change: on a pinned job its wall-clock comparison reads a due occurrence
as still-in-the-future and re-anchors past it.

Failing shape this fixes (profile America/Los_Angeles, job 0 9 * * 1-5 pinned to
America/New_York, scanned at 09:00 New York): `get_due_jobs()` returned [] and the job was
re-anchored to the next day, i.e. job zones east of the profile zone silently never fired.
The regression test drives the public store API and asserts both the fire and the absence of
the repair, and is proven red on main ([] and a rewritten instant).

Knobs live in the new sibling `cron/jobs_time.py`; `cron/jobs.py` stays over the file-lines
ratchet and only gained the call-site plumbing.
2026-10-28 19:40:40 -07:00
Teknium
408cc0d12e Merge origin/main (#32: 36 commits to cf23a1a5cc) into feat/unified-gateway-runtime
17 conflicts, all from main's lint sweep (ruff UP007/UP017/UP022/UP028/UP031/UP037/UP041,
FURB188/FURB192); no other main commit touches a conflicted file. Resolution: the branch side
of each file plus main's exact autofix (ruff 0.15.10, main's ruff.strict.toml, --fix
--unsafe-fixes). ruff.strict.toml takes main's copy. The pool-retirement live fixture stays
deleted with the pooled backend this branch retires.
2026-10-09 10:24:04 -07:00
Maciej Lisiewski
9eab688b42 ci: ruff UP017 fixes 2026-10-09 17:34:36 +02:00
Teknium
65bec86e37 Merge origin/main (#27: 19 commits to 517b5e10fe) into feat/unified-gateway-runtime
45 conflicts, all from #135177 (lefthook + `ruff check --fix` over 2,366 files). No other main commit
touches a conflicted file. Resolution: the branch side of each file, then main's exact autofix
(ruff 0.15.10, `--config ./ruff.strict.toml --fix`) on it — rewrites only (typing generics, noqa
drops, import forms), no import removed. tests/cron/test_bot_chat_cli_home.py stays deleted
(1cc9cb9199 retired its lane).
2026-10-08 12:09:24 -07:00
Maciej Lisiewski
d76cce4f11 ci: apply all automatic linter fixes available 2026-10-08 17:22:54 +02:00
Teknium
ca38632fc0 Merge origin/main (#17: 454 commits to e6757f2029) into feat/unified-gateway-runtime
12 conflicted files, resolved in three lanes:
- gateway/run.py: take the branch split; main's tirith removal and spool-replay
  ordering ported into run_runtime_init.py / run_bootstrap.py.
- config migrations: main keeps v50 (tirith); the branch's bot-chat timeout removal
  becomes v51 (_config_version 51, template + test updated).
- hermes_state_usage.py: main's voice_chat task route threaded through the branch's
  owner transaction; worker.persist usage allowlist accepts task.
- tui_gateway/server.py: branch side; main's edits applied where the code now lives
  (agent_factory, session_registry). Desktop sessions get the catalog toolset on the
  authority path; daemon-run finite CLI turns are not watched turns; lazy session info
  reports nous/welcome on the free tier.
- Desktop/Ink: one branch-child spinner fix (main's route-token check); main's
  uninstall i18n keys kept, pool keys stay removed; voice_turn forwarded and accepted
  by the authority submit (surface_v1.voice_turn).
- chat_ws / PTY keepalive test: main's stricter test kept.
2026-10-07 06:48:09 -07:00
kshitijk4poor
152aa695bb fix(cron): key store state by resolved path, never swallow a flapped outage notice
Final-stack review (hermes-pr-review 2c) on #133283:
- The tick lock reported its outage under the unresolved profile home (_get_lock_paths), while
  every save, probe and grace check uses the resolved store path. With a symlinked HERMES_HOME
  (or macOS /var -> /private/var) the lock outage never cleared: writable stuck at 0, no
  "recovered" notice, and a skipped one-shot retired as missed. All store_health records are now
  keyed through one _key() (realpath). Pinned with a symlinked home; red without it.
- unwritable -> recovered (before delivery) -> unwritable posted nothing: the dropped first
  notice left the "recovered" timer pending, so the re-entry cancelled it as if an outage notice
  had gone out. A dropped "unwritable" now cancels that timer, so the re-entry announces. The
  notice test runs on a manual loop clock (no wall-clock timing; it had flaked once under load)
  and pins the sequence.
- cron status printed "0 due run(s) not fired" and an empty summary when the jobs could not be
  read from an unwritable store; it now says the jobs could not be read.
2026-10-07 10:20:18 +05:30
kshitijk4poor
6f88751a7e refactor(cron): share is_recurring, the CLI probe-then-read and the report fields
/simplify-code quality pass on the final #133283 stack, no behaviour change:
- One null-safe is_recurring in cron/constants.py replaces scheduler_tick's new copy and
  unreachable_retry's (whose .get("schedule", {}) raised on a null schedule).
- cron status / cron list share _probe_then_list_jobs (probe, print, guarded read) instead of
  two near-identical blocks.
- StoreDegraded.notice_fields and probe_report build their fields through one _report_fields.
- The notice listener's pre-checks no longer repeat deliver()'s store re-check; deliver() is the
  single staleness gate (still red when removed).
2026-10-07 10:20:18 +05:30
kshitijk4poor
b476fb107e fix(cron): probe the store the way a save writes it; print the store warning before job reads
Greptile r1 on #133283:
- #3: probe_store created an empty file in cron/, while a save stages a full payload beside a
  symlinked jobs.json's real target. A read-only or full target passed the probe, so status and
  doctor reported a writable store, and a fixed 1 MiB free-space cutoff could flag a store
  whose small save still fits. The probe now stages a jobs.json-sized payload with
  mkstemp_beside (the save's own staging helper), fsyncs it, and checks the resolved target is
  writable; the free-space cutoff is gone.
- #5: on a read-only cron/ without cron/output, list_jobs tries to create output and raised
  before `cron status` / `cron list` printed the warning and fix. Both print the store warning
  first, and a read failure on an unwritable store no longer hides it.
2026-10-07 10:20:18 +05:30
kshitijk4poor
4453800b82 refactor(cron): drop the warn_store_unwritable wrapper and two getattr hacks
Review cleanup, no behaviour change:
- warn_store_unwritable only resolved the active store before calling
  store_health.note_unwritable; note_unwritable now defaults cron_dir to the active store and
  every caller uses it directly (scheduler_tick no longer imports both).
- The advance-skip split no longer zips a parallel bool list twice, and reads
  (schedule or {}) so a null schedule cannot raise inside the OSError handler.
- skipped_runs metric: a walrus instead of getattr around an Optional record.
- Notices: runner._served_profile_homes is declared on the reconcile mixin, so no getattr.
- cron status loads the active jobs once (skipped count + summary) instead of twice.
2026-10-07 10:20:18 +05:30
kshitijk4poor
9d093008b4 refactor(cron): count skipped runs in cron_status, not behind a report flag
Gate r4 quality: _store_unwritable_report(count_skipped) took a boolean whose two
callers each picked a caller-specific step. The report now only probes the
store, and cron_status (the one caller that prints the skipped count) sums the
overdue jobs inside its existing `if (store_report := ...)` block. `cron list`
still does a single list_jobs pass.
2026-10-07 10:20:18 +05:30
kshitijk4poor
15e6c85e1c perf(cron): skip the skipped-run count in cron list
Gate finding C12 r3 #8 (efficiency): on an unwritable store `cron list`
read every job twice — once to count the due runs that had not fired, once
to list them — and its one-line banner never shows that count. Add a
count_skipped flag to _store_unwritable_report; `cron list` passes False,
`cron status` keeps the count. Probe: list_jobs calls in cron_list on an
unwritable store go from 2 to 1, and the banner still prints.
2026-10-07 10:20:18 +05:30
kshitijk4poor
8e457dfad2 feat(cron): show an unwritable store at the top of cron status and in cron list
Since the tick stopped raising on a failed store write, ticker_last_error is not written during
an outage, so `hermes cron status` stayed green while every job was skipped. The CLI cannot read
the ticker's in-memory state or trust markers in a directory nobody can write, so it probes the
store itself (cron.store_health.probe_report). On failure it leads with a red
"⚠ Cron store is NOT writable — scheduled jobs are being skipped" headline. The detail names
the path, the OS error, the last successful write, how many due runs have not fired, and the
fix. `cron list` prints a one-line banner. The probe runs before any job read, because loading
jobs re-secures the directory mode.
2026-10-07 10:20:18 +05:30
Teknium
1e500ebce2 Merge origin/main (#16: 4,465 commits to 9dcab1e440) into feat/unified-gateway-runtime
99 conflicted files resolved in nine area lanes (Desktop composer, Desktop renderer/shared
client, Electron main, Ink, tui_gateway, gateway, state, CLI/config, cron/tools/CI). The
unified runtime's architecture wins where it deliberately replaced a mechanism (pool,
fallback lanes, claim poller, renderer queue); every orthogonal main change is kept, ported
into the <stem>_<topic> sibling that now owns relocated code.

Notable ports and repairs in this merge:
- tui_gateway/server.py relocated regions: atomic _attach_built_agent (#49852), slash ranking
  registry names, minted-key helpers methods_session.py calls, request_overrides, service tier.
- gateway/run_turn*.py: i18n accessors for the removed reply constants, first-contact
  internal/DM rule, rotated-compression persist, fast-mode tiers, prompt-pin rehydration.
- webhook: route_from_chat_id decodes main's opaque webhook:v2 chat ids (old ids still read).
- ws.py: main's per-connection dispatch queue with authority-first dispatch inside it.
- state: schema event for runtime revision renumbered to 31; worker mirrors updated for
  main's message uid/merge fields, on_contended lease arg, compression columns.
- config: branch's bot_chat_delivery_timeout removal renumbered v47 -> v50.
- Electron: primary-profile pin, redirect header scoping, remote fetchJsonForBackend, SSH
  teardown on profile delete, held-update dial gate restored (lost in earlier merges).
- Desktop: canonical clarify.request mapped to main's questions[] card; replay truncation vs
  snapshot_required; periodic secondary prune tick restored; DELETE already_absent restored.
- cron/tools: diagnostic category on cron failure notices restored; owner_holds_delivery
  ported onto the authority; admitted receipts can no longer be cancelled locally.
2026-10-06 14:24:24 -07:00
salch-cred
e70801e736 fix(cron): keep a sticky last_failure stamp so a healed run stays visible
A failed cron run records last_status=error and bumps failure_streak
correctly, but the next successful run resets both in the same pass and
nothing durable records that a failure happened — a silent watchdog-style
script that fails every Nth tick collapses to a single tick of visible
failure, and monitors sampling jobs.json report green forever (#118354).

Stamp job[last_failure] = {at, detail} on every failed run, latest
failure wins, and do NOT clear it on success: last_status keeps
describing current health while last_failure preserves the recency
evidence for dashboards and cron list. cron list now prints a warning
line for the stamp (marked recovered when last_status is healthy).

Fixes #118354

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-10-02 20:29:53 -05:00
teknium1
f1a38955bd fix(cli): served-profile guard only counts a host gateway that is ours and not our own (#121352, #120871, salvage #121574 #122169)
`host_multiplexer_serving` read the HOST-wide rendezvous record and every
CLI guard (`_named_profile_refused_under_multiplexer`, `_cmd_stop`,
`_cmd_restart`, profile_lifecycle, status/cron/dashboard readers via
`named_profile_served_by_running_multiplexer`) trusted it as "someone
serves you", so two gateways that are NOT a multiplexer serving this
profile were refused with exit 78:

* #121352 (T2 vs a second tenant home): two Hermes tenants on one host,
  separate HERMES_HOME roots, each with its own `default`. Tenant B's
  start guard saw tenant A's multiplexer "serving default" and refused;
  launchd parked the unit. gateway/host_attach.decide() and run.py's
  host-lock claim already start beside a foreign-root owner; the CLI
  probe did not. `host_multiplexer_serving` now returns None when the
  record's home resolves to another tenant root
  (`get_default_hermes_root(home=...)` vs ours).

* #120871 (T1 standalone named fleet, T6 launchd): `hermes -p argus
  gateway restart` refused argus's OWN standalone host record as "a
  multiplexer serves you" and pointed at `-p default`, whose gateway was
  not running. `named_profile_served_by_running_multiplexer` no longer
  counts a host record launched by the profile's own home; `cron status`
  names the profile that launched the scheduler host instead of a
  hardcoded `default`.

Control kept: a satellite whose own home is not the host record's home,
while the same tenant's live default multiplexer lists it, is still
refused without --force and the hint names the owner.

Re-implements the idea of #121574 and #122169 by @Finn763 at the shared
seam so every reader inherits it (those PRs patched only one caller each).
2026-09-28 13:30:57 -07:00
teknium1
040dc77490 feat(metrics): hermes.process.exit from per-process markers and turn watchdogs
A crash or SIGKILL cannot record itself. CLI, TUI, gateway, serve and cron-tick
drop a small marker under the profile's store dir at start (only when
collection is on), restamp it clean at exit, crash+exception family from the
excepthook, or watchdog before the gateway's os._exit. The next start in that
profile reports every marker whose owner fails the canonical start-time
liveness check (running => killed), on a daemon thread with rename-claims so
startup never waits and concurrent starts never double count.

Turns killed by the turn liveness watchdog or the gateway inactivity watchdog
count as exit_kind=watchdog once per turn, in the turn's own profile (home
captured at turn entry; off-thread watchdogs bind it explicitly).
2026-09-28 12:43:03 -07:00
teknium1
17957f5014 fix(review): ticker heartbeat proves liveness only while its writer is alive; routed hand-off never trusts an unknown probe; satellite manual runs get the ticker's routed grant
MAJOR — `_builtin_gateway_liveness` trusted a bare-epoch ticker heartbeat for
~200 s after its writer died, for every profile, and the multiplexer pid gate
had been dropped: a killed serve/Desktop ticker read as alive and
`hermes -p X cron run` queued a primary-routed run "for the gateway's next
tick" with no ticker present.

- `cron/jobs.py::record_ticker_heartbeat` stamps `<epoch> <pid>`;
  `get_ticker_heartbeat_age` parses the first field (legacy bare stamps still
  yield an age); new `ticker_heartbeat_writer_alive` requires the stamped pid
  to be alive and treats a bare stamp as NOT proof by itself.
- The heartbeat-only rung is now `fresh AND (served-by-multiplexer OR writer
  alive)`: the multiplexer record proves the host process for a served named
  profile (and covers a stale-code multiplexer still writing bare stamps), so
  only the in-process serve/Desktop ticker relies on the heartbeat, and then
  only with a live writer. `cron status`'s in-process-ticker rung applies the
  same rule.

MINOR (a) — `_hand_off_primary_routed_run` gated on `is True`; an unknown
(None) probe returns an error naming the uncertainty instead of "queued …
runs and delivers it".

MINOR (b) — `_run_claimed_job` wraps a shared-bot satellite's resolved map in
`SharedRouteAdapters(primary, _primary_profile_routes_for_current_home())`,
the same grant the ticker's `tick_adapters_for` makes, instead of handing it
the full primary adapter map.

Tests (each red on the previous head a18977090be):
- test_cron_satellite_diagnostics.py::test_in_process_ticker_heartbeat_counts_only_while_its_writer_lives
- test_cronjob_run_primary_routed.py::test_routed_run_without_a_serving_gateway_fails_before_the_turn[None]
- test_cronjob_run_immediate.py::test_execute_job_now_grants_a_shared_bot_satellite_only_its_routed_targets
2026-09-28 05:28:05 -07:00
teknium1
dd00040182 fix(cron): liveness answers "is a scheduler ticking THIS profile" and names it (#121881, #99631, #99579, salvage #121921 #99613)
Trim of the #121921 salvage plus the rest of the class:

- `_builtin_gateway_liveness` (shared by `cron list/create`, `cron status` and the
  `cronjob` tool via tools/cronjob_job_args.py): own-home lock/pid, else a fresh
  ticker heartbeat in THIS home's store. The multiplexer-record rung was redundant
  once the heartbeat is the evidence (served + no heartbeat was already False), and
  it wrongly said "dead" when the record excluded the profile or predated
  `served_profiles` while `hermes serve` / the Desktop backend was ticking the home
  in-process (#121881) or a shared gateway was firing the profile's jobs (#99631).
- `cron status`: the in-process ticker is a rung beside the multiplexer rung instead
  of a re-indented copy of the "no gateway" block; its restart hint names the
  Desktop app / serve backend.
- The red verdict names the inspected profile and claims only what the probe can
  know ("No scheduler is serving profile 'X'"): from a named profile it cannot see a
  gateway alive for other profiles, so "No gateway is running on this host" was a
  host-wide negative it could not make (#99579). `cron list` names the profile in
  its banner and its empty-state line, and the list/create warning names it too
  (idea from #99613 by @webtecnica; its `_active_profile_label` wrapper, banner
  rewrite and unrelated kanban/script-validation scope were not taken).

WHEN L3 (ticker liveness read by a CLI command), WHERE T7 (Desktop/serve in-process
ticker) and T2/T3 (`hermes -p X` against the host multiplexer).

Tests: the salvaged serve-ticker test keeps the fresh->alive / stale->dead
invariant; one named-profile test proves the profile is named on every verdict and
that probe's own heartbeat counts when the default record excludes probe. Both red
on origin/main (`_builtin_gateway_liveness()` False with a fresh heartbeat;
"No scheduled jobs." without the profile). Existing assertions on the old host-wide
string were moved to the new one.

Co-authored-by: webtecnica <webtecnica@gmail.com>
2026-09-28 05:28:05 -07:00
Bartok9
fc15ec8fe3 fix(cron): treat a fresh serve ticker as scheduler-alive (#121881)
Desktop topology ticks cron in-process inside `hermes serve`, so
`hermes cron status`/`list` no longer report a missing CLI gateway
when the ticker heartbeat is fresh.

(cherry picked from commit 583de75430adf6272eca932bf72665148df52101)
2026-09-28 05:28:05 -07:00
teknium1
202961c4c6 Merge origin/main (#11: 28 commits to 6e69a8933a) into feat/unified-gateway-runtime
One conflict: website/docs/user-guide/features/cron.md -- kept the branch's
'script is always a file' rule alongside main's --interpreter venv pin.
2026-09-27 15:21:57 -07:00
M1racleShih
6f7cc7e74c feat(cron): allow Python scripts to use an external interpreter
Add an optional per-job `interpreter` field so a cron Python `script` /
`monitor_script` can run under a user-managed venv instead of Hermes' own
Python, letting scripts import packages the Hermes runtime does not carry
(#8714). Nothing is installed, frozen, or restored automatically.

- cron/jobs.py: persist + normalize the field (absent => record unchanged;
  empty string clears it on update).
- cron/scheduler_script.py: _resolve_cron_interpreter() validates the path
  at run time (absolute/~ required, regular file, executable on POSIX);
  _script_argv runs [interpreter, script] and skips the managed-store
  bootstrap/PYTHONPATH overlays, which exist for Hermes' own venv.
  Threaded through _run_job_script, the claim-heartbeat wrapper, the
  pre-run prompt path and monitor scripts.
- hermes_cli: --interpreter on `cron create` / `cron edit`; shown in
  details and `cron list`.
- tools/cronjob_tools.py: programmatic/CLI lane only, like model and
  reasoning_effort — absent from the model-facing schema.

Shell scripts (.sh/.bash) still always run under bash. Revives #8741.

Ported onto current main from #70500 (the scheduler moved to
cron/scheduler_script.py and the CLI/tool became table-driven since the
PR's base).

Co-authored-by: MestreY0d4-Uninter <241404605+MestreY0d4-Uninter@users.noreply.github.com>
2026-09-28 02:32:05 +05:30
teknium1
eec5bd6673 Merge remote-tracking branch 'origin/main' into fix/106742-thread-resolution
4,048 upstream commits (Sep 16-23) composed onto the unified gateway runtime by six
per-domain conflict lanes (gateway, desktop/shared, cli/state, cron, bots/tui_gateway, ink).
Retired lanes stay retired (Desktop secondary pool + exit supervisor, deferred Bot Chat
pending queue, subprocess retry adoption); main's gateway.standalone, host-role claim,
clarify capability gate, config-read caches and idle gates ride on top.
2026-09-23 03:25:31 -07:00
teknium1
ed703493da gateway: converge on multiplex-only — real migrate, no opt-out, no rollback, host lock refuses
One gateway per host is the only supported topology (#100896). This is the convergence
path that makes it true on an upgraded machine.

`gateway migrate --multiplex` is now defined by TOPOLOGY, not by the config flag: a host is
converged when no secondary profile owns a gateway process or a supervisor unit. A
half-migrated host (flag flipped, a unit left behind, a crash between the two) therefore
converges on the next run instead of reporting "already multiplexed" — that flag-only test
made the re-run a no-op on exactly the host that needed it. The manifest is the resume
record: present means UNFINISHED, so a confirmed convergence clears it and any manifest
found on disk is resumed from rather than refused.

Windows Scheduled Tasks (and the Startup-folder fallback `gateway install` writes when it
cannot register a task) are now detected and removed like any other unit; Windows used to
be a flat refusal with hand-migration instructions. s6 stays refused, because there the
per-profile gateways are slots the container's own boot registers — and that boot now
registers named slots DOWN unconditionally, which is the s6 leg of the convergence. It
used to read `gateway.multiplex_profiles`, so the UNSET default (on) booted the slots
anyway and the image shipped the opt-out topology by accident.

A running gateway is never SIGTERMed silently: the plan names every pid it will signal and
prints before anything is signalled, with a dry run that changes nothing.

`--standalone` is gone. Reinstalling per-profile services is not a supported target, so
there is no rollback command; the machinery survives only as the compensator inside a
single failed apply, because the one outcome worse than a per-profile fleet is a profile
with no gateway at all.

`gateway.multiplex_profiles: false` is retired as a topology opt-out: it still parses and
still carries the runtime mode every scoped code path reads, but it can no longer pin a
second gateway process — it resolves like an unset key, warns, and points at the migration.
The unset path is not optimistic (it refuses to multiplex while a real blocker holds), so a
host that genuinely cannot fold still comes up standalone and says why. The eager Desktop
activation stops reading it too: a stale `false` there made a multi-home host serve a
second profile with the LAUNCH profile's credentials.

The host gateway lock flips from observe-only to a refusal. `host_attach` already
attaches/rescans/refuses before anything binds, but it reads a RECORD published a moment
after the owner starts, so two gateways launched together can both see no owner. The lock
is the only atomic arbiter of that race. The refusal names the owner, prints the migrate
command, and exits 75 (EX_TEMPFAIL) so a supervisor RETRIES — never the parking 78 — and on
the retry the record exists and the attach path resolves it properly. `--force`, `--replace`
and an unopenable lock dir are not refusals.
2026-09-21 10:11:19 -07:00
teknium1
ea0c2b820b fix(host-topology): a createTime-null record is not a live gateway, and the restart we print must run
Review findings on this PR.

- `_from_host_record` accepted a record with `createTime: null`: `_same_incarnation` treats a
  missing create_time as "matches", so `liveness_is_proven()` blessed whatever process happens to
  own that PID today. A record pointing at an unrelated `sleep 60` made `cron status` print
  "the host gateway (PID ...) serving profiles default, served". Require a recorded create_time.
- `cron status`'s host-record rung printed `hermes gateway restart`, which exits 78 for exactly
  its audience (a served NAMED profile); use the `--profile default` form both rungs now share.
- doctor's WORST state (supervision slots exist, nothing owns the gateway role) emitted a warning
  but appended no issue, while the strictly less severe LEGACY case did.
- Drop three defensive wrappers in `host_topology`: a try/except around an always-importable
  `normalize_profile_name` that silently degraded to a DIFFERENT normalisation, a blanket except
  per rung, and a swallowed `get_active_profile_name`.
- `get_systemd_unit_path`, `_legacy_unit_search_paths`, the doctor host-unit probe and the
  profile-delete service cleanup hardcoded `~/.config/systemd/user`, so on a host that moves
  $XDG_CONFIG_HOME the unit probe false-negatived -- the very bug this PR fixes survived there.
  One `user_systemd_unit_dir()` helper honours the spec default.

Tests: the two "Scheduler host: the host gateway" assertions were prefixes of BOTH rungs, so the
rungs were indistinguishable and the host-record rung was never exercised (which is how the
restart-command defect shipped green). Both now assert the full line, plus a served-host-record
case. Rendezvous isolation uses `tmp_path` instead of a leaked `tempfile.mkdtemp()` and also
covers `test_gateway_multiplex_served_record.py`, which read the real host record; the
`tests/conftest.py` hook in #118097 supersedes all of them once it lands.
2026-09-21 05:06:45 -07:00
teknium1
a1398a6f67 fix: doctor, cron status, claw and gateway status report the real host topology
Multiplex-only (Teknium ruling) runs exactly ONE `hermes gateway run` per host,
multiplexing every profile. Four reporting surfaces still asked a per-PROFILE
process question ("does MY profile own a gateway process?"), so a SERVED profile
answered "no" and the output lied:

* `hermes -p served cron status` printed "Gateway is not running" and told the
  user to run `hermes gateway install` / `gateway run` for that profile — i.e.
  to start a SECOND host process, which the architecture forbids.
* `hermes doctor` reported "Per-profile gateways: up/total" from s6 slots and
  checked systemd linger against the CURRENT profile's unit, so a doctor run
  under a served profile skipped the check entirely.
* `hermes claw`'s destructive-action warning was gated on `get_running_pid()`,
  which returns None for a served profile — the token-conflict warning was
  SILENTLY SKIPPED (a real safety hole).
* `gateway.status.multiplexer_liveness_for_profile()` returned None for the
  default home by construction, so `default` could never be reported as SERVED.
* `hermes doctor`'s state.db holder + WAL wording implied one gateway per
  profile.

New `gateway/host_topology.py` resolves "which single process owns the gateway
role on this host, and which profiles does it serve" once, from the host
rendezvous record (`gateway/host_rendezvous.py`), falling back to the default
home's recorded `served_profiles` for a gateway that predates the record.
`default` is just another served profile there.

Root cause: every surface derived gateway identity from per-profile artifacts
(argv `-p <name>`, `gateway.pid`, the active profile's systemd unit, s6 slot
counts) instead of the host record that actually names the owner.
2026-09-21 05:06:45 -07:00
teknium1
8863b36fd6 fix(cron): stale-code yield reads as an outage in cron status; hermes update restarts proven-stale gateways
After `hermes update` fast-forwards the checkout under a running multiplex gateway,
its cron ticker yields every tick ("stale code: booted on A, disk is at B") for as
long as the process lives. Two things made that a silent total dispatch outage:

* `hermes cron status` weighed only the liveness heartbeat (kept fresh by the yielding
  loop) and the success marker; with no success marker on disk it printed
  "✓ Gateway is running — cron jobs will fire automatically", and with a stale one
  it pointed at "Check the gateway log" instead of naming the cause. The persisted
  `CronTickYielded` error is now recognised (`cron.scheduler.stale_code_yield_labels`)
  and reported as "Gateway is running STALE code — fires NOTHING", with both
  revisions and the restart command. A fresh heartbeat with a recorded error and no
  success marker is no longer green either.
* The post-update fleet version matrix flagged a `stale` gateway and exited 1, but
  left it running. `_verify_fleet_after_update` now hands every proven-stale survivor
  to the existing drain-first `request_restart` path (SIGUSR1) via
  `hermes_cli/update_cmd_stale_survivors.py`: a supervised gateway respawns on the new
  code, a bare `gateway run` is stopped and listed under "Restart manually" — the same
  contract the restart phase already uses for unmapped manual gateways. The drain
  budget computation is shared (`_gateway_drain_budget`).

The yield itself is unchanged: a stale-code process still never dispatches while a
fresher lock holder exists (design of 9a7732b45f).

Fixes #117275
2026-09-21 01:57:31 -07:00
fangliquanflq
3f399c0bd4 fix(cli): align kanban edit and paused cron listing 2026-09-20 16:33:49 -07:00
teknium1
0469740ab3 feat(cron): jobs follow the main agent model at fire time; pinned locks it on request
An unpinned cron job used to snapshot the global provider/model at creation and treat that
snapshot as its effective pin (#44585), so `hermes model` / `/model` never moved the fleet and
`hermes cron resnap` existed to catch jobs up. New ruling: jobs run on whatever the main agent
model is when they fire. Resolution is per-job pin > cron.model / cron.model_provider (the cron
fleet default) > model.default.

`pinned` replaces the implicit snapshot with an explicit lock: create/update with pinned=true
writes the CURRENT main provider+model onto the job as an ordinary per-job pin; pinned=false
releases both. The cronjob tool exposes it (schema: only when the user asks; it can only lock
the main model, never point spend at a different one) and reports `pinned` per job; the CLI
gets `--pin` / `--unpin`. Legacy records that still carry *_snapshot keys follow the main model.

Removed with the snapshot: `hermes cron resnap`, the tool's resnap action + `all` param, the
"N unpinned jobs keep running on ..." notice in `hermes model` / `hermes config set` / the
dashboard model assignment, and the Desktop cron-model-impact card (setMainModelAssignment
keeps the expensive-model confirm flow in store/model-assignment.ts).

Live A/B (real store + run_job against a temp HERMES_HOME): main-model X -> Y, unpinned job
fires on X before, Y after; pinned job stays on X; unpin -> Y; legacy snapshot record -> Y.
2026-09-20 09:20:51 -07:00
teknium1
eddf7283e4 fix(cron): label overdue next runs in cron list, dashboard and Desktop; one parser for the instant
`hermes cron list`, the web dashboard Cron page and the Desktop cron panel/sidebar all
rendered a `next_run_at` parked hours in the past as an ordinary upcoming "Next run" —
the only user-visible trace of a scheduler that stopped ticking (#114309). Every
surface now labels a slot past `cron doctor`'s 15-minute grace as overdue (CLI
`Overdue:` row with the lateness, web `Overdue since`, Desktop `Overdue since` label
on the detail panel and sidebar meta) while paused/disabled/completed jobs keep the
plain label because they are not expected to fire.

The CLI's overdue check now parses through `cron.jobs._parse_aware` and `hermes_time.now`
so status/list/doctor and the ticker agree on the instant (mixed offsets, DST folds,
legacy naive stamps read as system-local like the scheduler does), and both the
ordering and the subtraction normalise to UTC: Python compares same-tzinfo datetimes by
wall clock, which is wrong across a DST fold. Status still orders the soonest run by
instant (#113874) and prints the stored stamp.

Tests: the salvaged status tests are trimmed to two invariants (overdue + stale
heartbeat is loud on status AND list; within-grace stays plain on both), the DST-fold
ordering tests freeze the CLI clock as well so their 2026-11 fixtures never start
reading as overdue, and one vitest each pins the web and Desktop helpers.

Co-authored-by: funky-xamarin <30426178+Wenfengcheng@users.noreply.github.com>
Co-authored-by: joaomarcos <joaomarcosdias444@gmail.com>
2026-09-18 12:46:54 -07:00
liuhao1024
f968327144 fix(cli): share the doctor's overdue grace in cron status
Address review feedback: `cron doctor` tolerates a 15-minute grace
window (_OVERDUE_GRACE_SECONDS) before calling a next_run_at overdue,
but the new status OVERDUE line fired on any `scheduled < now`, so a
job a few minutes behind the ticker's own cadence could flash OVERDUE
while doctor still called the same job healthy.

- Gate the status OVERDUE line on the same _OVERDUE_GRACE_SECONDS so
  status, list, and doctor tell one consistent story.
- Reuse _next_run_overdue_seconds inside _next_run_overdue_issue,
  dropping the duplicated timestamp parsing.
- Add a regression test: a next_run_at 5 minutes in the past stays a
  plain 'Next run' line.
2026-09-18 12:46:54 -07:00
liuhao1024
a20a71a3e3 fix(cli): flag overdue next_run_at and stale ticker in cron status
When the scheduler host dies, a job's next_run_at is stranded in the
past and `hermes cron status` still printed it as an upcoming
"Next run", hiding the outage (#114309): the report's only signal was
the gateway line, while the schedule line kept presenting a 7h-old
timestamp as future.

- _print_active_jobs_summary: when the earliest next_run_at already
  passed, print a loud OVERDUE line (age + scheduler question) instead
  of a bare "Next run: <past ts>"; future timestamps render unchanged.
- cron_status gateway-down branch: when ticker_heartbeat is stale,
  print when the scheduler last ticked so the frozen state is
  first-class visible.

Fixes #114309
2026-09-18 12:46:54 -07:00
funky-xamarin
8f6f9e5b36 fix(cron): order status next run by actual instant 2026-09-18 12:46:54 -07:00
yoniebans
d63876e820 refactor(cron): R3-S3 remove redundant satellite PID checks
The lock result controls the multiplexer probe once the initial PID scan is empty. Pass the known-empty PID list explicitly on the served path.

Reported-by: kshitijk4poor
2026-09-18 17:10:12 +02:00
yoniebans
ad1bf68a21 refactor(cron): R3-S1 share dispatch labels and missed-fire guidance
Use one plain-text missed-fire core in list and doctor, including the rerun command. Keep the error-detail bound independent of the shared recovery suffix.

Reported-by: kshitijk4poor
2026-09-18 17:10:12 +02:00
yoniebans
c134199886 fix(cron): R3-W3 require satellite heartbeat for list and create
Share the freshness threshold with status and keep local and external-provider probes unchanged. Missing/stale satellite cases fail on the parent; the fresh control passes.

Reported-by: kshitijk4poor
2026-09-18 17:10:12 +02:00
yoniebans
909c736cd4 fix(cron): R2-2 explain when lateness warnings clear
Keep the nonzero doctor status for the last late dispatch. Replace the configuration-only footer and exercise persistence through successful completion until the next on-time dispatch.

Reported-by: kshitijk4poor
2026-09-18 17:10:12 +02:00
yoniebans
d68640ae2d fix(cron): R2-1 remove impossible Desktop takeover hint
Reported-by: kshitijk4poor
2026-09-18 17:10:12 +02:00
yoniebans
afc5efa178 refactor(cron): apply scheduler diagnostic review suggestions
Reported-by: kshitijk4poor
(cherry picked from commit 2a5adfbc772e9080a6a1a5253e077379ada34d1a)
2026-09-18 17:10:12 +02:00
yoniebans
f3090f60f9 refactor(cron): W4 remove redundant exception wrappers
Reported-by: kshitijk4poor
(cherry picked from commit 957a704fdd9c7633f7ecbe0dcacc87238692da39)
2026-09-18 17:10:12 +02:00
yoniebans
bd7d4e30eb fix(cron): W3 bound missed-fire details and ignore empty records
Reported-by: kshitijk4poor
(cherry picked from commit 1c4eb8a011f5f3e8a3c3f1c392662d6a3b393dc7)
2026-09-18 17:10:12 +02:00
yoniebans
a027b924a8 fix(cron): W2 keep custom homes on standalone guidance
Reported-by: kshitijk4poor
(cherry picked from commit 5d70694b034621dc3eb65ea0d546d6625c15a52d)
2026-09-18 17:10:12 +02:00
yoniebans
b2d9cef85e fix(cron): W1 restore per-profile gateway install guidance
Reported-by: kshitijk4poor
(cherry picked from commit f29d812b00c015525601b81e15c938c80a7cfa77)
2026-09-18 17:10:12 +02:00
yoniebans
2619995967 fix(cron): preserve satellite diagnostics on the CI merge base
Remove the upstream early multiplexer status shortcut so satellite heartbeat health remains authoritative. Model scoped gateway lock and command-line identity in fixtures, use recorded served profiles for exclusion, and retain rejection of unrelated live PIDs.

(cherry picked from commit 1238efcaa0445fdf198073ca0ba74c0c07cae365)
2026-09-18 17:10:12 +02:00
yoniebans
9f2b05bb8e fix(cron): point satellite recovery hints at the scheduler host
(cherry picked from commit bd6bc41f096c9a3e33e7c274bd33f82d46671c66)
2026-09-18 17:10:12 +02:00
yoniebans
a3dc9583a8 fix(cron): keep satellite diagnostics scoped to observed health
(cherry picked from commit 09a365a3504336d05f5abe1bdf5f8b0098555d8c)
2026-09-18 17:10:12 +02:00
hermes-pr
5298ace87c fix(cron): surface missed fires and clarify satellite gateway status (#107168)
- cron status now checks default-profile multiplexer so satellite profiles
  served by the gateway no longer falsely report 'Gateway is not running'
  and correctly show 'running via multiplexer'; when not multiplexed,
  the message explains the Desktop-only ticker cliff and how to enable
  gateway.multiplex_profiles for 24/7 fires.
- cron doctor now flags last_dispatch catch_up/late and last_fire_error
  so a missed schedule that fast-forwarded next_run_at is not silently
  reported as 'found no issues'.

(cherry picked from commit 46592ac52bf11736f0d8f3d2bd7e10067ef15af4)
2026-09-18 17:10:12 +02:00
teknium1
43c477571e Merge origin/main (61154b6f68) into feat/unified-gateway-runtime
1,446 upstream commits; 84 conflicted files resolved per family, porting
every post-branch main fix onto the cutover architecture rather than
dropping it or resurrecting replaced pre-cutover code:

- gateway/cron/kanban/a2a: #111988 hygiene bound, silence-marker rejection,
  UX copy, clarify-card retirement on explicit no-answer, Slack task-card
  publication_suppressed, webhook per-route coalescing (wrapping the durable
  admit_producer), kanban dead-worker last output + fingerprint boot witness,
  migrate-profile-identity control verb, SupervisedTickerThread, api-server
  terminal_run_status; config migration 45 kept from main, ours renumbered 46.
- hermes_cli/hermes_state/tools/tui_gateway: read_only SessionDB alongside
  explicit db_path, sessions_cmd observational flag, #111958 served-profile
  skips service install, #111999 usage source upsert repair, archived Bot Chat
  title release, find_canonical_owner, #111151 serves_routed_profile MCP scope,
  session_search after/before/exclude, server.py hunks into session_registry/
  agent_factory siblings, #111775 runtime_check resolve hook, Bot Chat
  silence rule on delivery reply.
- Desktop/apps/shared: pool modules stay deleted; SSH teardown fencing,
  default-profile + peer-window routing, per-session remote headers,
  server->client requests, generated gateway contract with our owner stamps
  and session.replay_gap retained.
- Ink: canonical WebSocket client kept; storedSid reconnect recovery, server
  request store, generated contract types, plain-language copy ported.
2026-09-16 13:20:14 -07:00
teknium1
83417552b8 fix(cron): a headless tick refuses agent jobs with no gateway instead of spawning one
`hermes cron tick` (external-scheduler mode: a system crontab calls it) reached
run_canonical_job -> connect_gateway -> ensure_gateway_runtime, which spawns an
unmanaged gateway daemon when nothing owns the profile. Every crontab tick with
the gateway down left a stray daemon behind.

Headless surfaces refuse rather than spawn (the approvals policy). tick() gains
`headless=True`, set only by the CLI tick and the `python -m cron.scheduler`
entry; cron/scheduler_gateway_gate.py then holds back agent jobs when discovery
reports the home has no owner ("absent" is exactly the state ensure would spawn
in; starting/ready/incompatible/remote are left to connect_gateway, which never
spawns for them). Held-back jobs are skipped, not failed: no run is recorded,
next_run_at keeps the due instant (no drift, no failure streak), the orphan
pending_slot/run_claim stamps from the due scan are dropped so nothing later
"restores" the slot, and `last_fire_error` carries the actionable reason that
`hermes cron list` shows. One warning per tick names the job ids and the fix
(`hermes gateway start` / `hermes gateway install`). no_agent script jobs still
run from a bare tick.

The in-process gateway ticker and `hermes cron run` are not headless and are
unchanged. Docs: cron.md `tick` verb, cron-troubleshooting, cron/AGENTS.md.

Reviewer finding by @erosika on #106742; ruling by @teknium1.
2026-09-16 10:23:38 -07:00