session-runner records runs but no spend — a session's tokens are invisible to the Usage tab (#81 follow-up) #94

Closed
opened 2026-08-26 03:02:25 +00:00 by matou-build-agent · 3 comments

From the 2026-08-25 observability review.

Symptom. #81 made session-runner write runs/processes/attempts rows, but it writes no spend rows: the session's claude call consumes real account budget that never reaches swarm.db, so the fleet Usage tab (and any per-account accounting) undercounts by every session ever run.

Direction. Capture usage from the session's claude invocation (--output-format json or the session file's final usage record) and write a spend row attributed to the active account letter, same as record-run-result.sh does for swarm iterations. Applies equally to the triage and heal claude calls once their runs are recorded (see the sibling tickets) — one shared helper in swarm-db-lib.sh may serve all three.

Same commit: test update per CLAUDE.md.

From the 2026-08-25 observability review. **Symptom.** #81 made session-runner write `runs`/`processes`/`attempts` rows, but it writes no `spend` rows: the session's claude call consumes real account budget that never reaches swarm.db, so the fleet Usage tab (and any per-account accounting) undercounts by every session ever run. **Direction.** Capture usage from the session's claude invocation (`--output-format json` or the session file's final usage record) and write a `spend` row attributed to the active account letter, same as `record-run-result.sh` does for swarm iterations. Applies equally to the triage and heal claude calls once their runs are recorded (see the sibling tickets) — one shared helper in `swarm-db-lib.sh` may serve all three. Same commit: test update per CLAUDE.md.
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.
Ruling: ready-for-agent. Two-way door — an additive spend row using the same account-attributed write record-run-result.sh already performs; revertible, provable by test coverage.

Agent Brief

Category: enhancement
Summary: session-runner should write a spend row for its claude call, same as swarm iterations do.

Current behavior:
#81 gave session-runner runs/processes/attempts rows, but it writes no spend row: the session's claude call consumes real account budget that never reaches swarm.db, undercounting the fleet Usage tab by every session run.

Desired behavior:
Usage is captured from the session's claude invocation (--output-format json, or the session file's final usage record) and written as a spend row attributed to the active account letter — the same shape record-run-result.sh already writes for swarm iterations.

Key interfaces:

  • The swarmdb spend writer in swarm-db-lib.sh.
  • Consider one shared helper usable by session-runner, triage, and heal once their runs are recorded (sibling tickets #91/#92) — not required, but avoid three divergent implementations if you introduce one.

Acceptance criteria:

  • A completed session-runner claude call writes a spend row with real input/output/cache token counts and the active account letter
  • If a shared helper is introduced, record-run-result.sh's existing behavior is unchanged
  • Test coverage added/updated

Out of scope:

  • Wiring the triage/heal spend writes themselves (sibling tickets adopt any shared helper separately)
  • Cache-class/model fidelity (#96) — pass through whatever shape is currently available
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** Ruling: `ready-for-agent`. Two-way door — an additive spend row using the same account-attributed write `record-run-result.sh` already performs; revertible, provable by test coverage. ## Agent Brief **Category:** enhancement **Summary:** session-runner should write a `spend` row for its claude call, same as swarm iterations do. **Current behavior:** #81 gave session-runner `runs`/`processes`/`attempts` rows, but it writes no `spend` row: the session's claude call consumes real account budget that never reaches swarm.db, undercounting the fleet Usage tab by every session run. **Desired behavior:** Usage is captured from the session's claude invocation (`--output-format json`, or the session file's final usage record) and written as a `spend` row attributed to the active account letter — the same shape `record-run-result.sh` already writes for swarm iterations. **Key interfaces:** - The `swarmdb spend` writer in `swarm-db-lib.sh`. - Consider one shared helper usable by session-runner, triage, and heal once their runs are recorded (sibling tickets #91/#92) — not required, but avoid three divergent implementations if you introduce one. **Acceptance criteria:** - [ ] A completed session-runner claude call writes a `spend` row with real input/output/cache token counts and the active account letter - [ ] If a shared helper is introduced, `record-run-result.sh`'s existing behavior is unchanged - [ ] Test coverage added/updated **Out of scope:** - Wiring the triage/heal spend writes themselves (sibling tickets adopt any shared helper separately) - Cache-class/model fidelity (#96) — pass through whatever shape is currently available
Author
Member

swarm-claim host=elitebook-distributed-server-03 run=1545
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=1545 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #94 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 94,
  "status": "success",
  "commits": [
    "6d82cc5"
  ],
  "changed_files": [
    "session-runner.sh",
    "swarm-db-lib.sh",
    "tests/session-runner-test.sh",
    "tests/swarm-db-test.sh",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/session-runner-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/swarm-db-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A completed session-runner claude call writes a spend row with real input/output/cache token counts and the active account letter": "session-runner.sh runs the call with --output-format json and writes the usage block as one spend row via swarmdb_spend_from_result attributed to claude_active_account; tests/session-runner-test.sh group 20a asserts input/output/cache_creation/cache_read = 111/22/33/44, account A, model, and the join to the run row",
    "If a shared helper is introduced, record-run-result.sh's existing behavior is unchanged": "The new helper swarmdb_spend_from_result lives in swarm-db-lib.sh and is used only by session-runner; record-run-result.sh is not modified (it reads sandbox RunResult, not a --output-format json blob) and tests/record-run-result-test.sh stays green in the full suite",
    "Test coverage added/updated": "tests/session-runner-test.sh group 20 (advanced + noop record spend, limit-parked records none) and tests/swarm-db-test.sh group covering swarmdb_spend_from_result (tokens/cache/account/model/issue, usage-less/missing-file/no-issue, python-absent no-op)"
  },
  "summary": "session-runner captures its claude call's usage via --output-format json and writes one active-account-attributed spend row through a new shared swarm-db-lib helper, closing the #81 gap.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #94 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 94, "status": "success", "commits": [ "6d82cc5" ], "changed_files": [ "session-runner.sh", "swarm-db-lib.sh", "tests/session-runner-test.sh", "tests/swarm-db-test.sh", "STATUS.md" ], "tests": [ { "command": "bash tests/session-runner-test.sh", "exit_code": 0 }, { "command": "bash tests/swarm-db-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done", "exit_code": 0 } ], "criteria": { "A completed session-runner claude call writes a spend row with real input/output/cache token counts and the active account letter": "session-runner.sh runs the call with --output-format json and writes the usage block as one spend row via swarmdb_spend_from_result attributed to claude_active_account; tests/session-runner-test.sh group 20a asserts input/output/cache_creation/cache_read = 111/22/33/44, account A, model, and the join to the run row", "If a shared helper is introduced, record-run-result.sh's existing behavior is unchanged": "The new helper swarmdb_spend_from_result lives in swarm-db-lib.sh and is used only by session-runner; record-run-result.sh is not modified (it reads sandbox RunResult, not a --output-format json blob) and tests/record-run-result-test.sh stays green in the full suite", "Test coverage added/updated": "tests/session-runner-test.sh group 20 (advanced + noop record spend, limit-parked records none) and tests/swarm-db-test.sh group covering swarmdb_spend_from_result (tokens/cache/account/model/issue, usage-less/missing-file/no-issue, python-absent no-op)" }, "summary": "session-runner captures its claude call's usage via --output-format json and writes one active-account-attributed spend row through a new shared swarm-db-lib helper, closing the #81 gap.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Sign in to join this conversation.
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
Matou/dev-factory#94
No description provided.