Deduplicate Hermes session scan across workspaces#170
Merged
Conversation
readHermesSessions() re-ran the entire workspace-independent ~/.hermes scan -- reading and JSON-decoding up to MAX_PROVIDER_ROWS session files -- once per open workspace. After PR #154 began refreshing agent sessions for every open workspace tab, an N-workspace review fanned this into N concurrent full re-reads of the same corpus, multiplying peak heap by the workspace count. Scan the corpus once per CACHE_TTL_MS via a new memoizeAsyncWithTtl helper and apply the per-workspace match to the shared result. This closes the last unbounded per-workspace session-scan path from the v0.1.9 OOM investigation, complementing the codex/claude bounding in #169. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
8e7aed1 to
24d2e9d
Compare
JJPuertas
pushed a commit
to JJPuertas/Athena
that referenced
this pull request
Jun 20, 2026
The codex `~/.codex/sessions` metadata scan (bounded in luckeyfaraday#169) carried its own inline TTL cache with identical semantics to the `memoizeAsyncWithTtl` helper added for the Hermes scan dedup (luckeyfaraday#170): share one in-flight promise per TTL window, never cache rejections. Fold the codex cache into the shared helper to remove the duplicated cache bookkeeping. No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
readHermesSessions(workspace)re-ran the entire workspace-independent Hermes corpus scan — the~/.hermes/state.dbquery plus a fullreadFile+JSON.stringifyof up toMAX_PROVIDER_ROWS(1000) session files — and only narrowed to the workspace with a final match. PR #154 ("Improve multi-workspace review handoffs", first shipped in v0.1.9) began refreshing agent sessions for every open workspace tab, so an N-workspace review fanned this single scan into N concurrent full re-reads of the same corpus, multiplying peak heap by the workspace count.This is the Hermes analogue of the codex amplification fixed in #169, and the last unbounded per-workspace session-scan path flagged in the v0.1.9 heap-OOM investigation.
Change
memoizeAsyncWithTtl(client/electron/ttl-cache.ts): a small async memoizer that shares one in-flight promise per TTL window and never caches rejections — the same semantics as the existing inline codex metadata cache.readHermesSessionsinto:scanHermesSessions()— the workspace-independent scan, now run once perCACHE_TTL_MS(30s) and shared across all workspaces.readHermesSessions(workspace)— filters the shared result withhermesSessionMatchesWorkspaceand stamps the per-workspaceworkspacefield.Eleven open workspaces now perform one corpus scan per 30s window instead of eleven concurrent ones. The session-building logic is otherwise unchanged.
Behavior notes
state.db) the result is identical.searchText, which the per-workspace match needs) for the 30s TTL. This is bounded by the existingMAX_PROVIDER_ROWS× 300 KB cap and is far below the multi-GB transient spike it replaces.Verification
npm run build:electron— cleannpm run test:electron— 133/133 pass, including 3 newttl-cachetests (in-flight sharing, TTL expiry, rejections not cached)Context
Root cause: PR #154 (
b4c801c) turned one active-workspace session scan into one-per-workspace. The codex/claude side is bounded in #169; this PR closes the Hermes side.🤖 Generated with Claude Code