fix(sessions): record session presence regardless of the concurrency cap - #80034
Open
maxmilian wants to merge 1 commit into
Open
fix(sessions): record session presence regardless of the concurrency cap#80034maxmilian wants to merge 1 commit into
maxmilian wants to merge 1 commit into
Conversation
Presence tracking was gated on `max_concurrent_sessions`, which defaults to None -- so `try_acquire_active_session` returned before writing any entry for almost every user, and the registry was empty exactly when someone wanted to ask whether another session was already attached to a checkout (NousResearch#46303). A None cap now means "reject nobody", not "know nobody": the lease entry is always recorded and only *enforcement* stays conditional on the cap. Entries carry the enclosing git checkout (via the existing `metadata` field), and `find_sessions_for_repo()` answers the question the issue opens with. Writing is strictly best-effort -- a read-only or corrupt registry logs and falls back to the previous no-op lease, so it can never keep a session from starting. `hermes status` drops the same cap gate: it already had the display path and `active_session_registry_snapshot()`, but showed nothing unless a cap was set. Sessions in the current checkout are marked, which is the reporter's scenario. Deliberately out of scope, per the review on NousResearch#47029: no mutation of `self.system_prompt` (it must stay byte-stable for prompt caching), and no change to the Honcho `session_strategy` default. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
maxmilian
marked this pull request as ready for review
August 12, 2026 08:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes active-session presence tracking work when
max_concurrent_sessionsisn't set, so "is another session already attached to this checkout?" becomes answerable — the question #46303 opens with.Today
try_acquire_active_sessionreturns before writing anything when the cap isNone(hermes_cli/active_sessions.py:285-291), andNoneis the default (gateway/config.py:920). So for almost every user the registry is permanently empty, and nothing can warn them that a second session is live in the same repo. The reporter's near-clobber was caught by a human readingtmux lsandgit status, not by anything the program knew.This is the second pass @teknium1 invited in the review on #47029 — "registry-always-on for repo detection, no system-prompt mutation" — and it stays inside the invariants set out there. Both constraints from that review still hold on current
main(f5be9236e0); the same cap gate also appears inhermes_cli/status.py:636, which is whyhermes statusshows nothing today either.The framing: a
Nonecap should mean "reject nobody", not "know nobody". Presence and enforcement were the same switch; this separates them.Related Issue
Refs #46303 (addresses the awareness half; the worktree-locking half landed in #48699)
Type of Change
Changes Made
hermes_cli/active_sessions.pytry_acquire_active_session()always records the lease entry; only the rejection path stays conditional on the cap.current_repo_root(): walks up for.gitrather than shelling out togit(this runs on every session start). Tests existence rather thanis_dirso linked worktrees — precisely the [Bug]: Concurrent sessions cross-contaminate (shared memory injection + shared git worktree) with no isolation or awareness #46303 scenario — are detected.find_sessions_for_repo(repo_root, *, exclude_lease_id=None).metadata["repo_root"]by default, so all three call sites (CLI, gateway, TUI gateway) get attribution without changes; an explicit caller-suppliedrepo_rootstill wins.hermes_cli/status.py— drops theif _cap:gate. With a cap it prints slots as before; without one it prints aLive:count. Entries show which checkout they're in, and sessions in the current one are marked← this repo.tests/hermes_cli/test_active_sessions.py— four tests (below).Not touched, deliberately, per the #47029 review:
self.system_prompt(must stay byte-stable for per-conversation prompt caching) and the Honchosession_strategydefault (agreed it deserves its own PR).How to Test
pytest tests/hermes_cli/test_active_sessions.py -q # 7 passedThe four new tests, and what each pins:
test_registry_records_presence_when_cap_is_unsetmax_sessions is Noneearly returntest_uncapped_sessions_are_recorded_but_never_rejectedtest_entries_carry_repo_root_so_sessions_are_attributablerepo_rootmetadatatest_registry_failure_never_blocks_session_startexceptaround the writeI verified those aren't vacuous by reverting each change in turn and confirming only the matching test goes red, then confirming all 7 pass again.
And the new
statusoutput, driving that block directly against a scratchHERMES_HOMEwith two real registry entries — one in this checkout, one elsewhere — rather than a fullhermes statusrun:With no cap set, that block previously printed nothing at all.
On the "all tests pass" checkbox — I can't honestly tick it, so here is what I actually ran.
tests/hermes_cli/gives 138 failures in my environment, but they are pre-existing: on unmodifiedmainthe same suite gives 143. My branch has strictly fewer, and the directly-relevant files (test_active_sessions.py,test_cli_active_session_limit.py,test_status.py,test_session_api.py) are 30/30 green. The noise looks like missing optional dependencies —uv synccan't be used here becauseuv.lockfails to parse onmain(TOML error at line 10,[options]), so I installed withuv pip install -e ".[dev]". Happy to re-run under whatever the canonical setup is.Checklist
Code
pytest tests/ -qand all tests pass — see the note above; pre-existing failures, fewer than onmainDocumentation & Housekeeping
max_concurrent_sessionskeeps its meaning; it just no longer gates presence)current_repo_root()is purepathlibwith no shell-outs;.git-as-file is handled, which is the Windows/worktree caseOpen question
Always-on means every session now takes the file lock and writes
active_sessions.json, where most sessions previously did no I/O here at all. I've left it unconditional on the reasoning that presence you have to opt into doesn't help the person who didn't know they needed it — but if you'd rather it sat behind its own flag (separate from the cap), that's a small change and better made before review than after.