Commit Graph

7 Commits

Author SHA1 Message Date
Teknium
4440b3e345 fix(windows): owned children never break away; detached spawns share one breakaway-denied retry
The WhatsApp bridge is an owned child (spawn_owned): it must not outlive its gateway. It was
spawned with CREATE_BREAKAWAY_FROM_JOB, so a gateway in a job that forbids breakaway (Desktop, an
IDE or agent host, Task Scheduler) could never start it (WinError 5 on every reconnect), and under
a job that allows breakaway it escaped that job's teardown, keeping the port and the WhatsApp
session. spawn_owned now strips the breakaway bit on Windows, so every owned child stays in its
owner's jobs (the pairing bridge already spawned that way).

Children that must outlive their parent go through one primitive, _subprocess_compat.popen_detached:
breakaway when the parent allows it, else retry inside the job on ERROR_ACCESS_DENIED only. The two
Windows detached spawns without that retry (gateway /update, the Desktop launch) and five copies of
it (default plugins, commit-graph refresh, scratch prune, hermes desktop, launchd fallback) use it.

Fixes #68128

Co-authored-by: morkalg <20704953+morkalg@users.noreply.github.com>
Co-authored-by: IzzyWizzy666 <25311408+IzzyWizzy666@users.noreply.github.com>
Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
Co-authored-by: Rickard Robin <rickard@kumobits.com>
2026-12-01 13:20:40 -08:00
alt-glitch
4db81cc513 fix(logging): print logger names without the hermes_agent. package prefix
Log files, stderr and the plugin-host and MCP-server streams printed
%(name)s verbatim, so a module that runs inside the hermes_agent package
wrote "hermes_agent.gateway.run:" where its lines read "gateway.run:".
People and support tooling search logs for the short names, and the
prefix carries no information.

Every Hermes log format now prints canonical_logger_name(record.name),
the same rule the component filters already match on. display_record()
in hermes_logging derives it; RedactingFormatter and the new
DisplayNameFormatter (used by the plain formatters in git_commit_graph,
plugin_host_child and hermes_tools_mcp_server) format through it.
record.name is unchanged, so filters, tests and third-party handlers
keep reading the true module name. Names without the prefix format
exactly as before.
2026-11-13 18:45:32 +00:00
alt-glitch
360f48814c refactor: callers find the install folder through project_root_str()
61 call sites counted directories up from their own __file__ to find the
install folder. They now call hermes_cli._startup_fast.project_root_str(),
so the layout move changes one line instead of 61.

Kept with a reason in the lint baseline: files that cannot import Hermes
code (bootstrap, update path, pm/) and the sys.path bootstraps left for
part 2b. The baseline drops from 89 to 28 root_from_file sites.

Six existing tests that patched a module __file__ now patch the owner.
2026-11-13 18:45:31 +00:00
kshitijk4poor
fc67e99e99 fix(git): a bounded git maintenance run dies with its owner; the commit-graph refresh is marked detached
Rebase onto main: main moved the repack into git_commit_graph.run_bounded_git, a niced git in a
process group of its own (process_group=0) that the timeout and atexit kill. A SIGKILLed or
OOM-killed owner ran neither, so git repack and its pack-objects kept packing for as long as they
took; the detached-spawn ratchet flagged the new spawn. It now starts through spawn_owned (same
own group, plus the owner-death supervisor) and releases the group once it is empty; the timeout,
atexit and SIGTERM-first kill are unchanged. spawn_commit_graph_refresh is meant to be detached
("must neither delay the update nor die with it"), so its Popen gets a marker with that reason.

Test: a git-maintenance case in the kill -9 owner matrix (a `git` that execs the child, the way
repack forks pack-objects): the SIGKILLed owner's tree dies, the live owner's survives. Fails
with the plain process_group spawn.
2026-10-29 16:58:09 +05:30
Teknium
3f29cc2c2b fix(git): lock sweep keeps every lock unless it can see no git of any form
Review finding (#144647, P2): the object-store lock sweep removed a live
writer's lock. _git_proc_running matched only processes named exactly
`git` (git-core's dashed executables, e.g. a `git-commit-graph` writer,
ran unseen) and answered "no git running" whenever pgrep was missing or
failed. A writer stopped after taking commit-graph.lock, its lock aged
past ten minutes, lost the lock to the sweep; once resumed the repo was
left with no commit graph while Hermes had stamped it fresh.

The guard now fails closed: on POSIX it scans with psutil (pgrep with a
`^git(-.*|\.exe)?$` pattern in the dependency-free bootstrap), on Windows
it reads every tasklist image name; both match git, git-<sub> and .exe
through _early_recovery._git_program. A probe that cannot tell (pgrep
missing or erroring, tasklist failing, a psutil read denied) keeps every
lock. This covers every sweep that shares the guard (update-path
shallow/index/HEAD locks, tmp-pack debris), not only the graph refresh.

The freshness stamp is written only when a graph is on disk after a
successful write (a split chain whose layers all exist, or a monolithic
graph): a write that exits 0 with no graph, as in a commitless repo,
no longer marks the repo fresh.
2026-10-25 17:51:21 -07:00
Teknium
25db2df103 fix(git): graph refresh honours global core.commitGraph, serializes its slot and covers linked worktrees
Review round on the commit-graph refresh (Greptile + re-review):

- Global graph setting is ignored: core.commitGraph=false is read with the
  user's global/system git config, which the writer's isolated env blanks.
- Expired slots allow duplicate writers: check and claim of the maintenance
  slot run under one flock/msvcrt lock on the slot file, which is never
  unlinked; a failed spawn gives back only a claim holding its own pid.
- Linked worktrees and submodules (a .git file) were skipped: the common git
  dir is resolved once (update_lock._git_common_dir) and used for the object
  store, slot, debris sweep and fresh stamp, on the update spawn and on the
  `hermes -w` pass alike.
- Timeouts were silent: the kill is logged at WARNING, with the timeout
  unrounded.
- kill_process_tree(grace>0) returned once the leader exited on SIGTERM,
  orphaning a group member that ignores it: the rest of the group it led is
  SIGKILLed. grace=0 is unchanged.
- The child's failure line was lost when <home>/logs did not exist: the log
  dir is created at failure time via mkdir_under_hermes_home (a deleted
  profile is not resurrected), and a log that cannot be opened no longer
  raises out of the logger.
2026-10-25 17:51:21 -07:00
Teknium
a80b413cd6 fix(git): graph refresh sweeps only object-store debris and lets git clean up
Review round on #144647 (head d016f04694d):

- CI routing: the refresh (slot claim, bounded runner, stale check, detached spawn) moves to
  hermes_cli/git_commit_graph.py, routed to e2e_upgrade with the update pipeline. The update path
  imports it instead of all of worktree_ops; worktree_ops keeps its repack seams and imports the
  shared slot claim and runner from it (no cycle).
- W1: the -w pass runs in whatever repo it was launched from, so its refresh sweeps only the
  object-store locks (clear_stale_git_locks(names=OBJECT_STORE_LOCK_NAMES)); index.lock / HEAD.lock
  there belong to the user's git. The install checkout's update sweep is unchanged.
- W2: timeout/exit reaping SIGTERMs the git tree first and SIGKILLs only after a 5 s grace
  (kill_process_tree(grace=), default unchanged for every other caller), so git deletes
  commit-graph-chain.lock and tmp_graph_*. The age-gated tmp sweep now also takes
  objects/info/commit-graphs/tmp_graph_*.
- N1: a breakaway-forbidding Windows job gets the no-breakaway retry, and a spawn that fails gives
  the 6 h slot back.
- N2: the detached child logs a failed write (git's fatal line) to the home's agent.log/errors.log.
- core.commitGraph=false in the target repo skips the write.
- N3: a successful no-op write stamps hermes-commit-graph.fresh, so an idle repo is not rewritten
  every slot.
- N4: test_update_finish's completion child and every in-process hermes_cli test stub the
  detached spawn; no writer outlives a test run.
- Greptile: the refresh test now runs on a treeless clone over a Bloom graph and asserts the
  write adds no pack (red when --no-changed-paths is dropped).
2026-10-25 17:51:21 -07:00