Skip to content

feat(ledger): stamp session_id on every execution row — run identity across ledger↔harness sources #1129

Description

@kokevidaurre

Why

squads-api#199 established the double-count seam: a dispatched lane run is BOTH a ledger execution and a Claude-harness session. Every merged view (CLI board #1119, Chief cost answers, upcoming API activity feed for squads-app#87 part 3) needs a run-identity join to dedup — and today no linkage exists anywhere:

  • .agents/observability/executions.jsonl: 0 of 398 rows carry session_id (verified 2026-07-14)
  • Postgres agent_executions.metadata: only trigger/context_tokens/provider keys
  • (api#199's "mapping already exists in the ledger row" was wrong — correction posted there)

What

Stamp session_id (the Claude Code session UUID) on every ledger row squads-cli writes:

  1. Detached runs: already launched with an explicit --session-id (Detached claude-run reconcile attributes the WHOLE machine's session usage to each run #857) — persist that same id into the execution record.
  2. Foreground runs: run-capture already locates the session JSONL to read tokens/cost (observability capture) — persist the file basename it found.
  3. squads board merge (feat(board): show Claude-harness executions — board only sees squads-run dispatches, hiding half the fleet #1119 seam in board.ts): drop a derived harness row when its session id matches a ledger row's session_id — the board currently unions with no dedup and double-counts lane runs exactly like api#199.

hq's ingest-usage.py then carries the field into Postgres so the API can join sessions.id = agent_executions.session_id.

Notes

  • Old rows stay NULL — no backfill; downstream mergers keep a worktree-cwd heuristic for the historical tail.
  • One field, additive, no schema break for --json consumers.

Related: squads-api#199, squads-app#87 (part 3), #1119/#1120, #857.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions