Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Hermes Session Forensics?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/rafaelrr5-hermes-session-forensics)
---
name: hermes-session-forensics
description: "Read Hermes session stores read-only: prove loss, export, hand off."
version: 1.0.0
author: Rafael Rocha Ribeiro (github.com/Rafaelrr5)
license: MIT
platforms: [linux, macos, windows]
metadata:
agent:
tags: [hermes, sessions, sqlite, state-db, forensics, rewind, compaction, handoff]
related_skills: [recall-and-claim-verification, delegated-agent-supervision, delivery-verification]
---
# Hermes session forensics
## When to Use
- "My messages disappeared", "the history got cut", "the chat went blank",
"the session lost its beginning".
- Handing a Hermes session to another agent, or resuming a long one yourself.
- "Is session X still working or stuck?", or bringing back a turn that died mid-task.
- Harvesting lessons from recent Claude Code / jcode sessions
(`references/other-agent-session-stores.md`).
Not for changing the rewind code itself (see `hermes-core-patching`).
Goal: prove whether data is **gone** or only **hidden from the live view**, name the
trigger with log evidence, and offer a non-destructive recovery. Everything here is
READ-ONLY: never UPDATE/DELETE `state.db`, never flip `active` by hand.
## Procedure
1. **Locate the store.** `$HERMES_HOME/state.db` plus its `-wal`/`-shm` sidecars
(`$HERMES_HOME` defaults to `~/.hermes`; on Windows to `AppData\Local\hermes` under
the user profile). Note any `state.db.pre-update-emergency-<timestamp>.bak` at the
same level — the Desktop updater writes it before touching the store, and it is the
baseline for step 2. Open read-only only, from `python3`:
`sqlite3.connect('file:state.db?mode=ro', uri=True)`. Never copy `state.db`
without its `-wal`; the three files are one image.
2. **Rule out hard loss first.** Against the newest backup, compare: session ids
missing now, and sessions whose `count(*)` of messages DROPPED. Rewind and
compaction archive rows instead of deleting them, so zero missing + zero decreased
means nothing was deleted. Lead the report with that — it is the user's real worry.
(Session delete/prune and non-archiving rewrites do delete rows; if counts dropped,
say so plainly.)
3. **Classify rows** (`messages` columns):
- `active=1`: the live view. After a rewind, `sessions.message_count` is reset to
the live row count.
- `active=0, compacted=1`: summarized away by in-place compaction (expected).
- `active=0, compacted=0`: rewound (retry / regenerate / edit / undo), or an
original row whose copy was carried forward after compaction.
- `_compressed_summary=1`: compaction summary rows. `display_kind` marks synthetic
turns, e.g. `model_switch`, `auto_continue`, `steer`, `async_delegation_complete`,
`hidden`.
4. **Find what is really missing from view:** inactive, non-compacted user/assistant
rows whose (role, decoded content) has no active twin, excluding synthetic
`display_kind` rows and `[System…` notes. Rank sessions by that count; list the user
rows with timestamps.
5. **Correlate with logs** in `$HERMES_HOME/logs/` (`agent.log*`, and `gui.log` for the
Desktop app):
`grep -h "prompt.submit: truncating session\|auto-continue scheduled\|startup_orphan_reap"`.
The line `prompt.submit: truncating session <ui_session> history N -> M messages (ordinal=K)`
is the cut; it logs at WARNING when M is 0, INFO otherwise. The next
`tui prompt accepted: ui_session=<same> session_key=... agent_session_id=<id>` maps
the ephemeral UI id to the stored session id. Check the same window for rate-limit,
spend-limit or provider-fallback errors: a failed turn followed by Retry, or a model
switch plus resend, is a common trigger.
6. **Report:** not lost (numbers), a small table session → cut (N → M), the trigger,
an immediate workaround (after a provider error, send "continue" instead of
Retry/edit; don't edit the first message of a long session), and the recovery offer.
7. **Recovery = read-only export**, never a DB edit: dump the hidden rows per session to
a file the user picks. **Redact secrets** the user pasted into chat (API keys,
tokens) before writing. `hermes sessions export --format md` includes compaction
archives but not rewound rows, so it does not recover them. Don't promise a restore
command unless `hermes sessions --help` on the user's version shows one.
## Handing a Hermes session to another agent
A Hermes session id (e.g. `20260922_143359_7c6ecc`) names rows in `state.db`, not a
file. An agent told to "continue session <id>" that searches the disk for it burns
minutes and finds nothing. Export first and pass the file:
```bash
hermes sessions export --session-id <id> --format md --redact <OUT_DIR>
# md/qmd: <OUT_DIR> is a DIRECTORY holding <id>-<title-slug>.md + manifest.jsonl
# (OUT_DIR defaults to $HERMES_HOME/session-exports). Add --lineage logical to
# include the whole compression lineage.
```
Long sessions export to hundreds of KB, so read the tail first.
When YOU resume a session id: `session_search(session_id=...)` returns only the first
20 + last 10 messages, each truncated to 2,000 characters; pass `around_message_id` to
scroll the middle. (Under Anthropic OAuth the tool is exposed as
`chat_history_lookup`.) For a long session, read the tail in full from `state.db`
read-only instead:
`select id, role, content from messages where session_id=? and role in ('user','assistant') and active=1 and id >= <anchor> order by id`
(take the anchor id from the `session_search` result). The last long assistant turn is
usually the handoff you need.
## Is another session still working?
Asked "is session X alive or stuck?" from outside it: read only, and never message,
interrupt or resume it while you check.
1. **Age of the last row:** `select id, role, tool_name, finish_reason, timestamp from
messages where session_id=? order by id desc limit 3`, as `now - timestamp`. An
assistant row with `finish_reason='tool_calls'` and no tool row after it means a call
is in flight (a long tool or a hung model).
2. **Turn lease:** `session_turn_leases(conversation_id, holder, acquired_at,
expires_at)`. The key is the conversation (the lineage root reached through
compression parents), not always the session id you hold. While a turn runs,
`expires_at` keeps moving forward. A missing or expired lease plus a stale last row
means a dead turn. An unexpired `compression_locks(session_id, holder, acquired_at,
expires_at)` row means compaction is running. `sessions.ended_at` stays NULL for live and abandoned sessions alike,
so it proves nothing.
3. **Admissions:** the newest `session_admissions` row for `target_session_id` has
`status` `queued`, `started`, `unknown` or `terminal`; a terminal row carries the
`outcome` (`completed`, `interrupted`, `failed`, `rejected`, `cancelled`).
4. **Children:** `sessions where parent_session_id=?` (source `subagent`) that are
unended or recently started mean delegated work is still running.
5. **Loop check:** group the tail's `tool_calls` JSON by (function name, first ~300
characters of arguments). The same signature three or more times is a loop; once or
twice is normal re-reading.
6. **Classify the outcome, not just activity.** Read the latest assistant text and
`finish_reason`. A question in the final answer means waiting for input; a final answer
with no running turn means finished; a stopped turn with no final answer means it died.
7. **Report short:** status, current step, age of the last row, lease and admission
state, loop yes/no, and what you could not verify.
## Resuming a session that stopped mid-task
The transcript survives an interrupted turn (a compaction failure, or `Session turn
lease could not be refreshed; stopping to protect the transcript.`); only the turn is
dead.
1. **Confirm it is dead:** no live lease, a `terminal` newest admission, no compression
lock. Never start a second turn while a lease is live, and ask the user not to type in
the original window while your turn runs: two turns on one transcript is what the lease
exists to stop.
2. **Fix the cause first**, or the resumed turn dies at the same point. For a lost lease,
test for host sleep before blaming Hermes: an elapsed time far above any real call, or
an hours-long gap between consecutive `agent.log` lines, means the machine slept and
nothing renewed the lease (Windows Modern Standby is one example). Resume under a
temporary keep-awake request rather than retrying blindly. If the update marker
`.hermes-update-in-progress` exists in the install root, wait until the update ends.
3. **Resume headless, prompt from a file:**
`hermes chat -Q --resume <session_id> --query-file <prompt.txt> > out.txt 2>&1`, run in
the background. The prompt says what stopped the turn, points at the task's own state
file, and forbids redoing finished work.
- Do not pass `-m` or `--provider`. Resume keeps the session's launch policy and
refuses overrides ("Resume retains gateway session policy; ...") with exit code 2,
printed only to the output file, so a launcher that reported a PID can still have
failed.
- Make the launch idempotent: if a `--resume <id>` process already runs, do not start
another.
4. **Verify in the logs, not by exit codes:** `agent.log` lines for the session id
(`API call #N`, tool completions, `Turn ended`), a lease whose `expires_at` keeps
moving, and a `started` admission.
5. **Right after a turn, compaction may hold the compression lock.** Wait for it; do not
kill it. A resumed rate-limited turn re-hits the limit at once, so cap its parallelism in
the prompt and tell it to checkpoint and stop on a repeated provider blocker.
## Usage profile from state.db
For "how is this Hermes used" (hour and weekday histograms, sessions per source), open
`state.db` read-only:
- `sessions.started_at` and `messages.timestamp` are epoch floats. Convert with the
local timezone of the machine the user asks about, and state the window start.
- Count sessions per `sessions.source` (`cli`, `oneshot`, `tui`, `desktop`, `cron`,
`subagent`, and others) with and without a `role='user'` row.
- `role='user'` rows include injected turns (cron prompts, auto-continue, steer, tasks
sent by other programs). Report the all-source histogram and one without automated
sources, and call the second an upper bound of human typing.
## Pitfalls
- **Multipart content reads as empty.** Image/attachment turns are stored as a string
prefixed `\x00json:` followed by the JSON parts list; the leading NUL makes
`length(content)` and text comparisons misbehave. Read `cast(content as blob)` and
decode before matching.
- **Order by `id`, not `timestamp`.** Compaction clones carried rows with their
ORIGINAL timestamp and a new id, so timestamp order interleaves generations.
- **Rewound ≠ lost, and compacted ≠ bug.** Count only step-4 rows as "disappeared";
compaction archives are normal and inflate naive `active=0` counts.
- **Say what the logs can't prove.** The truncation line does not record which UI
action (retry, edit, restore) sent it; mark that as unconfirmed instead of guessing.
- **Scope source greps** to `tui_gateway/`, `hermes_state*.py` and
`apps/desktop/src/app/session/hooks/use-prompt-actions/`. The rewind path is
`runRewindSubmit` (`use-prompt-actions/rewind.ts`) → `prompt.submit` truncation in
`tui_gateway/methods_prompt.py` → `replace_messages(..., archive_dropped=True)`.
- **Keep anything identifying an employer or client out of shared notes** when you
record what a session taught you.