Skip to content

Token counter resets between spec generation and autonomous loop, making total appear to decrease #72

Description

@caoergou

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:

  1. SpecGenerator.generate() runs in its own agent context with AgentStreamDisplay.
  2. _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

  1. Pass spec-generation token/cost into _run_engine() as the initial accumulated value.
  2. Display phase sub-totals and a real grand total:
    • Spec generation: X tokens
    • Implementation (iterations): Y tokens
    • Total so far: X + Y tokens
  3. Label values as estimated when they come from the regex fallback instead of explicit API usage.
  4. Surface the grand total in the final report, status file, and TUI.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions