Skip to content

fix: enrich hermes local usage from state db#100

Open
psionic73 wants to merge 1 commit into
NousResearch:mainfrom
psionic73:fix/hermes-usage-from-state-db
Open

fix: enrich hermes local usage from state db#100
psionic73 wants to merge 1 commit into
NousResearch:mainfrom
psionic73:fix/hermes-usage-from-state-db

Conversation

@psionic73

Copy link
Copy Markdown

Summary

  • enriches hermes_local execution results with Hermes session usage from $HERMES_HOME/state.db
  • preserves the existing stdout/stderr usage parser as a fallback
  • records diagnostic resultJson.hermes_usage metadata while populating Paperclip usage, costUsd, provider, model, and billing type when available

Why

Hermes quiet CLI output currently exposes the answer and session_id, but not a stable machine-readable usage/cost block. Paperclip only persists run accounting when the adapter returns usage and/or costUsd, so hermes_local runs were showing usageJson: null and zero spend despite Hermes recording token/cost data in its own state DB.

Safety / compatibility

  • best-effort only: missing state DB, missing session row, missing python3/sqlite, or query errors return null and do not fail the Hermes run
  • falls back to the existing Hermes stdout/stderr parser
  • no Paperclip core schema changes
  • no secrets are read or logged
  • uses config.hermesHome, then HERMES_HOME, then ~/.hermes

Tests

  • npm run typecheck
  • npm run build
  • node --test test/*.test.mjs

npm run lint is not currently runnable in this checkout because eslint is not installed/listed as a dev dependency.

Lab evidence

Verified in an isolated Paperclip/Hermes lab with no production Hermes home or production .env mounted into the container.

Final smoke run:

  • Run ID: e57a355b-4666-4314-90dd-80f97486b632
  • Hermes session: 20260502_005214_d854d5
  • status: succeeded
  • usageJson: non-null
  • resultJson.cost_usd: 0.0011862
  • resultJson.hermes_usage.usage_source: hermes_state_db
  • hermesCostStatus: estimated
  • actual_cost_usd: null
  • provider/biller: openrouter
  • model: openai/gpt-5.4-mini

Observed usage in Paperclip after the patch:

  • input tokens: 438
  • output tokens: 37
  • cached input tokens: 9216
  • cost USD: 0.0011862

@psionic73

Copy link
Copy Markdown
Author

Refreshed/audited PR state against current origin/main.

  • Branch remains 1 commit ahead / 0 behind origin/main; no rebase was needed.
  • Fork branch is in sync with local HEAD (0044ebb813e082e4d86d9e0d6787c5c3e3070e88).
  • GitHub reports the PR as mergeable.
  • Local verification on a fresh checkout:
    • npm ci — OK, 0 vulnerabilities
    • npm run typecheck — OK
    • npm run build — OK
    • node --test test/*.test.mjs — 3 passed

No code changes were made in this refresh; this is a verification/status update only.

@psionic73

Copy link
Copy Markdown
Author

Final pre-merge review from Hermes Agent:

  • Scope reviewed: src/server/execute.ts, test/hermes-state-usage.test.mjs, lockfile update.
  • The change is best-effort and preserves fallback behavior when Hermes state DB usage cannot be read.
  • It populates Paperclip accounting from Hermes state.db without changing Paperclip core schema or requiring production Hermes data access.
  • Local verification on current PR head: npm run typecheck OK; npm run build OK; node --test test/*.test.mjs — 3 passed.
  • GitHub reports the PR as mergeable and no checks are reported for this fork branch.

Verdict: no blockers found; ready for maintainer merge.

@psionic73

Copy link
Copy Markdown
Author

Refreshed final status check after latest sweep.

  • Branch remains 1 commit ahead / 0 behind current origin/main.
  • Fork/local parity verified: 0 ahead / 0 behind.
  • Local merge-tree against current origin/main: clean.
  • GitHub reports MERGEABLE / CLEAN.

Local verification on fresh checkout:

  • npm ci — OK, 0 vulnerabilities
  • npm run typecheck — OK
  • npm run build — OK
  • node --test test/*.test.mjs — 3 passed

No functional changes were made during this sweep.

@psionic73

Copy link
Copy Markdown
Author

Maintainer handoff / refresh status:

  • PR remains open and GitHub reports: MERGEABLE.
  • Base: 937ea71a34f5efcaa3834b11fdd08cfc1c99cb2c
  • Head: 0044ebb813e082e4d86d9e0d6787c5c3e3070e88
  • GitHub reports no checks for this branch, so there is no CI signal to report.
  • Prior local/lab verification covered Hermes local usage enrichment from state.db and non-null usage/cost propagation.

Ready for maintainer review/merge from my side.

@psionic73

Copy link
Copy Markdown
Author

This PR is still mergeable and has no reported checks/blockers from GitHub.

Current status:

  • Head: 0044ebb813e082e4d86d9e0d6787c5c3e3070e88
  • Mergeable: yes
  • Checks: none reported

Looks ready for maintainer review/merge when convenient.

@psionic73

Copy link
Copy Markdown
Author

Maintainer handoff:

  • PR is currently open, non-draft, and mergeable.
  • Current head: 0044ebb813e082e4d86d9e0d6787c5c3e3070e88.
  • Current base observed: 937ea71a34f5efcaa3834b11fdd08cfc1c99cb2c.
  • No status checks are configured/reported for this PR; observed 0 pending and 0 failures.

From my side this is ready for maintainer review/merge.

@psionic73

Copy link
Copy Markdown
Author

Quick follow-up: this PR is still mergeable and has no failing checks reported.

Current status:

  • mergeable: MERGEABLE / CLEAN
  • no CI checks configured/reported
  • no requested changes / no reviews yet

Happy to adjust if anything is blocking review or merge.

@psionic73

Copy link
Copy Markdown
Author

Friendly maintainer ping: this PR is still clean and mergeable, with no failing checks reported.

Current status:

  • mergeable: MERGEABLE / CLEAN
  • no CI checks configured/reported
  • no reviews or requested changes yet

Could a maintainer please take a look when you have a chance? Happy to adjust anything that would make this easier to review or merge.

@psionic73

Copy link
Copy Markdown
Author

Friendly maintainer ping after rechecking current state:

  • PR remains open, non-draft, and mergeable.
  • Current head: 0044ebb813e082e4d86d9e0d6787c5c3e3070e88
  • Current base: 937ea71a34f5efcaa3834b11fdd08cfc1c99cb2c
  • GitHub reports: MERGEABLE / CLEAN
  • No CI checks are configured/reported for this PR.

Still looks ready for maintainer review/merge from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant