Repository navigation
Fire the Hermes session hook on on_session_finalize, not per turn - #347
Conversation
…iughelbur#345) Hermes fires on_session_end after every turn, and the hermes -z run the hook starts fires it again, so each turn started a consolidation and each consolidation started another. Register the hook on on_session_finalize instead. The script now also refuses to re-enter: the consolidation child gets OBSIDIAN_HERMES_CONSOLIDATING=1, and a per-user mode-0600 lock file allows one consolidation at a time (a lock whose PID is gone is replaced). The background run no longer inherits the hook's stdout, so the hook returns {} at once instead of when the consolidation ends.
eugeniughelbur
left a comment
There was a problem hiding this comment.
@drakeo338 thanks. Moving the hook to on_session_finalize is the right fix, and the tests check it. One thing before merge.
The loop guard has 2 parts, and #345 says part 1 may not work. @konsorsiumai found the hook runs inside the gateway (payload cwd is ~/.hermes). Then the OBSIDIAN_HERMES_CONSOLIDATING=1 marker on the hermes -z child never reaches the hook. The lock is what remains, and it can miss this order:
- The hook starts a consolidation and takes the lock.
- The consolidation's
hermes -zexits, and the lock is released. - Hermes finalizes that child session and fires the hook.
- The hook finds a free lock and starts the next consolidation.
I can't run a real Hermes gateway, so I'm not claiming step 3 lands after step 2. This PR has no guard for it if it does.
A minimum interval, the issue's second suggestion, holds in any order:
- A per-user stamp file next to the lock, mode 0600, with the start time of the last consolidation.
- The hook exits with
{}when that start is newer thanOBSIDIAN_HERMES_MIN_INTERVALseconds, default 6 hours. - A test: two hook runs back to back, marker unset and lock free, start 1 consolidation, not 2.
@konsorsiumai, you have the gateway and the probe script. Once this is in, could you run the probe on on_session_finalize? It shows where the child's event lands against the lock.
Last, the PR body says "2 other failures remain, outside the Hermes hook tests." Which 2 tests, and do they fail on main too?
If the hook runs inside the Hermes gateway, the
OBSIDIAN_HERMES_CONSOLIDATING marker on the hermes -z child never
reaches it, and the lock alone misses a child whose finalize event
lands after its lock is released: the hook then finds a free lock and
starts the next consolidation.
The hook now keeps the start time of the last consolidation in a
per-user mode-0600 stamp file next to the lock, and exits with {}
while that start is newer than OBSIDIAN_HERMES_MIN_INTERVAL seconds
(default 21600, 6 hours; 0 turns it off). The check runs under the
lock, and the stamp is written through a temp file and a rename so a
symlink at its path is replaced, not followed.
|
Pushed f4fcc33: the Hermes session hook now skips a consolidation while a per-user 0600 stamp is newer than |
|
Merged through #364, together with 4 other PRs. The new interval test fails on your previous commit and passes now. @konsorsiumai, a probe run with a real gateway on |
|
Tested Hermes
What this shows:
Not tested: a real gateway (Telegram etc.). There |
…entry under Unreleased
What this PR does
Fixes #345. Hermes fires
on_session_endafter every turn, not once per session, and thehermes -zconsolidation the hook starts fires it again. An armed hook would start a consolidation per message, each starting another. The hook, example config and Hermes adapter now useon_session_finalize. The script also exits whenOBSIDIAN_HERMES_CONSOLIDATINGis set (exported to the child) and takes a per-user lock so consolidations never overlap.Type of change
Related issues
Closes #345
How I tested it
New
tests/test_hermes_session_hook.pyand updatedtests/test_smoke.py: 61 pass on the committed HEAD, against 57 pass and 6 fail with the new tests on the base commit. 2 other failures remain, outside the Hermes hook tests.AI-first rule compliance (required for any vault-writing command)
Unticked: no vault-writing command changed.
references/ai-first-rules.md## For future Claudepreambleai-first: true,type:,date:,tags:[[...]]) used for every person, project, idea, decision referenced(as of YYYY-MM, source.com))Checklist
CHANGELOG.md(under "Unreleased") if applicableSKILL.mdand the README's command tableScreenshots / output (if visual or producing notes)
n/a