Draft: Make Hermes collector writes atomic and monotonic #23

Closed
clawlter wants to merge 0 commits from audit/collector-atomicity into main
Owner

Remediates HUI-001 and HUI-002.

Baseline: 36a6494b01538328d906dfc8b3d9393ec0690a33
Head: abf71f5100c9cf1c04c5cbdd66a4160c73fe172f

Behavior

  • Wraps each Hermes snapshot import in one BEGIN IMMEDIATE transaction so checkpoint and event writes commit or roll back together.
  • Serializes overlapping collectors before checkpoint reads.
  • Merges cumulative counters monotonically so a stale snapshot cannot lower the checkpoint or create duplicate deltas.

Regression evidence

  • Injected event-insert failure leaves no checkpoint; retry imports the complete synthetic total.
  • Two independent SQLite connections importing overlapping newer/older synthetic totals finish with one exact total and the newer checkpoint.
  • Regressions failed on the audited baseline and pass on this head.

Verification

  • uv run pytest -q (16 passed)
  • uv run black --check src tests
  • uv run isort --check-only src tests
  • uv run pyright
  • uv run python -m build and uv run twine check dist/*
  • uv run mkdocs build --strict
  • Synthetic CLI import twice: imported 1, then 0; summary remained 20 tokens.

Residual risk

SQLite uses its configured busy timeout. A writer held longer than that can cause a collector run to fail safely rather than wait indefinitely; a later retry remains lossless. Cumulative counters are intentionally treated as monotonic for a stable Hermes session ID.

Remediates HUI-001 and HUI-002. Baseline: `36a6494b01538328d906dfc8b3d9393ec0690a33` Head: `abf71f5100c9cf1c04c5cbdd66a4160c73fe172f` ## Behavior - Wraps each Hermes snapshot import in one `BEGIN IMMEDIATE` transaction so checkpoint and event writes commit or roll back together. - Serializes overlapping collectors before checkpoint reads. - Merges cumulative counters monotonically so a stale snapshot cannot lower the checkpoint or create duplicate deltas. ## Regression evidence - Injected event-insert failure leaves no checkpoint; retry imports the complete synthetic total. - Two independent SQLite connections importing overlapping newer/older synthetic totals finish with one exact total and the newer checkpoint. - Regressions failed on the audited baseline and pass on this head. ## Verification - `uv run pytest -q` (16 passed) - `uv run black --check src tests` - `uv run isort --check-only src tests` - `uv run pyright` - `uv run python -m build` and `uv run twine check dist/*` - `uv run mkdocs build --strict` - Synthetic CLI import twice: imported 1, then 0; summary remained 20 tokens. ## Residual risk SQLite uses its configured busy timeout. A writer held longer than that can cause a collector run to fail safely rather than wait indefinitely; a later retry remains lossless. Cumulative counters are intentionally treated as monotonic for a stable Hermes session ID.
fix: make Hermes collection atomic
All checks were successful
Python CI / Build source and wheel distributions (pull_request) Successful in 7m51s
Python CI / Validate formatting, typing, and tests (pull_request) Successful in 1m51s
Python CI / Validate formatting, typing, and tests (push) Successful in 6m31s
Python CI / Build source and wheel distributions (push) Successful in 5m40s
abf71f5100
clawlter closed this pull request 2026-07-11 18:39:28 -04:00
All checks were successful
Python CI / Build source and wheel distributions (pull_request) Successful in 7m51s
Required
Details
Python CI / Validate formatting, typing, and tests (pull_request) Successful in 1m51s
Required
Details
Python CI / Validate formatting, typing, and tests (push) Successful in 6m31s
Python CI / Build source and wheel distributions (push) Successful in 5m40s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
clawlter/hermes-usage-insights!23
No description provided.