# NousResearch/hermes-agent · Session state and token accounting bug fixes

## Open now

- Nothing open on GitHub.

These items address a cluster of session-state bugs including safe close tracking, flush-cursor fixes, row-retry logic, and a specific issue where the session_model_usage primary key rebuild was gated behind a version check that made token and cost accounting permanently broken on some installs.

## TL;DR

- 3 member(s): 0 open issue(s), 1 closed issue(s), 0 open PR(s), 1 merged PR(s), 1 PR(s) closed without merging.
- A fix was merged to main in PR #75883. Verify it addresses your case.
- **Recommended:** read PR #75883 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `resolved` · deciding PR(s): `pr-75883`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_SPANNING`): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
- Pairwise link density `0.67`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

- #73823: \[Bug\]: Token/cost accounting dies permanently on installs already at schema_version >= 22 â€” the session_model_usage PK rebuild is unreachable behind \`current_version < 22\`

## Prior & competing PRs

- **#75883: fix(state): four session-state fixes — safe close tracking, flush-cursor class fix, row-retry, usage-PK healer**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`
  - files: `agent/context_compressor.py`, `agent/turn_finalizer.py`, `contributors/emails/[redacted:email]`, `contributors/emails/[redacted:email]`, `hermes_cli/sqlite_safe_read.py`, `hermes_state.py`, `hermes_state_schema.py`, `tests/agent/test_micro_compaction.py`, `tests/agent/test_turn_finalizer_final_response_persistence.py`, `tests/run_agent/test_identity_flush.py`, `tests/state/test_no_more_rows_retry.py`, `tests/state/test_session_model_usage_pk_heal.py`, `tests/test_sqlite_lock_safe_inspection.py`
- **#73838: fix: heal session_model_usage PK unconditionally to restore token/cost accounting (#73823)**. closed without merge
  - maintainer direction: category `merged_via`; implication `superseded`; refs `#75883`, `#73823`

## Fix status

- Merged to main in PR #75883 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-08-01`.
- Subsystem: `agent`
