Problem
When running owloop go, the token counter displayed in the UI appears to drop after the spec generation phase finishes.
In a real run we saw:
- Spec generation phase: 3,253,400 tokens displayed.
- Autonomous loop starts: counter resets to 2,144,890 tokens.
- Iteration 1 completes: counter climbs by +695,847.
This gives the impression that token usage went backwards, which is confusing and undermines trust in the reported numbers.
Root cause
owloop go is implemented in two separate phases:
SpecGenerator.generate() runs in its own agent context with AgentStreamDisplay.
_run_engine() creates a fresh OwloopEngine whose self.tokens_used starts at 0.
The 3.2M tokens consumed during spec generation are never added to the engine total, so the "total" shown in the loop and in the final report is only the implementation-phase total.
Why accuracy is also shaky
src/owloop/tokens.py falls back to regex parsing of agent output lines because "Claude Code CLI does not emit a stable, documented token-usage line today." If the agent does not print a token line, the iteration is counted as zero; if the output contains multiple token lines, it may be double-counted.
Suggested fixes
- Pass spec-generation token/cost into
_run_engine() as the initial accumulated value.
- Display phase sub-totals and a real grand total:
- Spec generation: X tokens
- Implementation (iterations): Y tokens
- Total so far: X + Y tokens
- Label values as
estimated when they come from the regex fallback instead of explicit API usage.
- Surface the grand total in the final report, status file, and TUI.
Related
Problem
When running
owloop go, the token counter displayed in the UI appears to drop after the spec generation phase finishes.In a real run we saw:
This gives the impression that token usage went backwards, which is confusing and undermines trust in the reported numbers.
Root cause
owloop gois implemented in two separate phases:SpecGenerator.generate()runs in its own agent context withAgentStreamDisplay._run_engine()creates a freshOwloopEnginewhoseself.tokens_usedstarts at 0.The 3.2M tokens consumed during spec generation are never added to the engine total, so the "total" shown in the loop and in the final report is only the implementation-phase total.
Why accuracy is also shaky
src/owloop/tokens.pyfalls back to regex parsing of agent output lines because "Claude Code CLI does not emit a stable, documented token-usage line today." If the agent does not print a token line, the iteration is counted as zero; if the output contains multiple token lines, it may be double-counted.Suggested fixes
_run_engine()as the initial accumulated value.estimatedwhen they come from the regex fallback instead of explicit API usage.Related