Skip to content

fix(pi): preserve terminal and token accounting - #54

Merged
drewstone merged 1 commit into
mainfrom
fix/pi-terminal-accounting
Jul 30, 2026
Merged

fix(pi): preserve terminal and token accounting#54
drewstone merged 1 commit into
mainfrom
fix/pi-terminal-accounting

Conversation

@drewstone

Copy link
Copy Markdown
Contributor

Problem

Pi sessions ending with stopReason: error were reported as successful, while reasoning and cache token dimensions were discarded.

The live GLM-5.2 run exposed both failures: two workers ended with Stream ended without finish_reason, yet trace analysis called both successful and omitted 30,397 root reasoning tokens plus 300,736 cache-read tokens across the root and active worker.

Change

  • derive the root session status from Pi's final persisted message
  • report terminal model errors as failed
  • leave interrupted or unfinished sessions unknown instead of inventing success
  • preserve reasoning, cache-read, and cache-write usage
  • retain the native Pi stop reason on the root span

Proof

  • pnpm test: 373/373 passed
  • pnpm typecheck: passed
  • pnpm build: passed
  • replayed the three live run sessions: both errored workers now report failed; the externally interrupted leader reports unknown; root usage now includes 30,397 reasoning and 260,928 cache-read tokens

@drewstone
drewstone merged commit 9da4499 into main Jul 30, 2026
1 check passed
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