Skip to content

fix(roadmap): explain totals count dropped model events #4457

Closed

Description

@dan-petty

Problem Description

devops roadmap explain <issue> and devops roadmap explain <issue> --json report 0 tokens and 0 seconds for the last implement run when the trace of that run is long. trace_totals in src/devops_cli/roadmap/explain.py adds the tokens and the seconds of the model events that the trace keeps. Since pull request #4436 (issue #4393), ImplementTrace.encode in src/devops_cli/roadmap/implement/implement_trace.py drops the oldest model events first when the trace is longer than CONST_ROADMAP_IMPLEMENT_TRACE_CHARS. For a long run, the bound drops all model events, so the totals are 0. Before #4436, the bound dropped the oldest events of all kinds, and some model events stayed.

The requirement "Totals of the last implement run" in openspec/specs/roadmap-explain/spec.md says: "The command SHALL report the token total, the seconds total, the repair-round count and the outcome counts of the last implement run of the item." #4436 did not change this requirement. implement.spend keeps the tokens of the run, but explain and explain --json do not read implement.spend.

The long runs are the runs that #4393 is about, so the totals are wrong for the runs that a reader most wants to explain.

Reproduction Steps

  1. On main, make a trace: trace = ImplementTrace(step="group 1").
  2. Add 100 model events of 20,000 input tokens, 300 output tokens and 4 seconds each (trace.model_call("model-a", 20_000, 300, 4.0)), and after each one, 1 or 2 shell calls (trace.tool_call("shell", "git", "<12 hex digits>", "ok", status=0)), 150 shell calls in total.
  3. Add one attempt: trace.attempt(1, "model-a", "limit_reached", "the step made too many requests", repair=False).
  4. Compare trace_totals(trace) with trace_totals(decode(trace.encode())).

Expected vs Actual Behavior

Expected: the totals after encode and decode equal the totals of the full trace: tokens_total=2030000, seconds_total=400.0. explain prints these totals and explain --json gives the same values.

Actual: the full trace gives TraceTotals(tokens_total=2030000, seconds_total=400.0, repair_rounds=0, outcomes={'failed': 1}, dropped=0). After encode and decode, the result is TraceTotals(tokens_total=0, seconds_total=0, repair_rounds=0, outcomes={'failed': 1}, dropped=180). The decoded trace keeps 1 attempt event and 70 tool events, and no model event. With the encode of the commit before #4436, the same run keeps 79 model events and gives 1,603,700 tokens and 316 seconds.

Proposed fix

Keep the sums of the dropped model events in the encoded value: add dropped_tokens and dropped_seconds next to dropped in ImplementTrace.encode, read them in decode, and add them in trace_totals. An old trace with no such keys decodes with 0 for each. Also count the repair rounds and the outcomes of dropped attempt events if the bound can drop an attempt event. As an alternative, read the token total from implement.spend, but that record holds no seconds.

Test first: a trace with more model events than the bound keeps gives explain --json totals that equal the totals of the full trace. Add a scenario for a long run to the requirement "Totals of the last implement run".

Existing tool considered

No tool applies: the change is two numbers in a JSON value that the project owns.

Environment Diagnostics

Found on 2026-11-11 by the review of the merged pull request #4436, on main at commit 6cf78e73.

Logs, Traces, or Terminal Output

full: TraceTotals(tokens_total=2030000, seconds_total=400.0, repair_rounds=0, outcomes={'failed': 1}, dropped=0)
kept: TraceTotals(tokens_total=0, seconds_total=0, repair_rounds=0, outcomes={'failed': 1}, dropped=180)
kinds kept: {<TraceEventKind.ATTEMPT: 'attempt'>: 1, <TraceEventKind.TOOL: 'tool'>: 70}

Source: #4436

Proposed design

Problem statement

Long implement traces lose all model events when ImplementTrace.encode applies the trace bound. devops roadmap explain then reports 0 tokens and 0 seconds for the runs that need explanation most. The change keeps the totals of dropped model and attempt events in the trace and adds them to the explain totals.

Acceptance criteria

Requirement: Dropped model sums

ImplementTrace.encode SHALL write dropped_tokens and dropped_seconds for the model events that it drops, and decode SHALL read them.

Scenario: A model event is dropped

  • WHEN the bound drops one model event of 20,000 input tokens, 300 output tokens and 4 seconds
  • THEN the encoded value holds dropped_tokens 20300 and dropped_seconds 4.0, and decode restores both values

Requirement: Totals of a long run

devops roadmap explain SHALL report the token total and the seconds total of the full last implement run when the trace bound drops model events.

Scenario: A long implement run

  • WHEN the trace holds 100 model events of 20,000 input tokens, 300 output tokens and 4 seconds each, and 150 shell calls, and encode drops every model event
  • THEN trace_totals(decode(trace.encode())) gives tokens_total 2030000 and seconds_total 400.0, equal to the full trace

Requirement: JSON totals of a long run

devops roadmap explain --json SHALL report the same token total and seconds total as the text output for a long implement run.

Scenario: A long run in JSON

  • WHEN the job record holds the long-run trace and the command runs with --json
  • THEN the JSON object holds tokens_total 2030000 and seconds_total 400.0

Requirement: Dropped attempt totals

The encoded trace SHALL keep the repair-round count and the outcome counts of attempt events that the trace bound drops.

Scenario: An attempt event is dropped

  • WHEN the bound drops an attempt event with outcome failed and next repair
  • THEN trace_totals(decode(trace.encode())) counts 1 repair round and 1 failed outcome from that event

Requirement: Old trace compatibility

The decoder SHALL read a trace with no dropped-sum keys as a trace with zero dropped sums.

Scenario: An old trace

  • WHEN the encoded value holds events and dropped but no dropped_tokens, dropped_seconds, dropped_repair_rounds or dropped_outcomes
  • THEN decode succeeds and trace_totals gives the same totals from the kept events

Requirement: Re-encode without double count

An encoded trace that is decoded and encoded again SHALL keep its dropped sums once.

Scenario: A decoded trace is encoded again

  • WHEN a trace with dropped sums is decoded and encoded with no new dropped event
  • THEN the decoded totals equal the totals before the second encode

Requirement: Trace bound

The encoded trace SHALL stay within CONST_ROADMAP_IMPLEMENT_TRACE_CHARS characters after it adds the dropped sums.

Scenario: A long trace stays bounded

  • WHEN the trace has more events than the bound holds
  • THEN len(trace.encode()) is at most CONST_ROADMAP_IMPLEMENT_TRACE_CHARS

Requirement: Dropped events line

The command SHALL state that the totals include the events that the trace bound dropped.

Scenario: Trace with dropped events

  • WHEN the trace reports 12 dropped events
  • THEN the output names 12 dropped events and says that the totals include them

Existing Tool Considered

No check has run. No open, maintained tool covers this need: the change adds numbers to a JSON value that the project owns. Written cost: about 20,000 tokens to build and test, 10,000 tokens to keep and fix, and about 4 hours.

Key questions

  • How should the trace keep the token and second totals of model events that the bound drops?: Add dropped_tokens and dropped_seconds to the encoded trace and to ImplementTrace. Add them in trace_totals. (best practice) [sources: src/devops_cli/roadmap/implement/implement_trace.py, src/devops_cli/roadmap/explain.py, openspec/specs/roadmap-explain/spec.md]
    • Chosen: Store the dropped model sums in the trace JSON. It keeps the seconds that implement.spend lacks and needs no extra read.
    • Rejected: Read the token total from implement.spend. The record holds no seconds, so it cannot meet the requirement.
    • Rejected: Raise the trace bound or drop fewer model events. It changes the trace size and can still drop model events.
  • How should the trace keep the repair rounds and outcomes of attempt events that the bound drops?: Add dropped_repair_rounds and dropped_outcomes to the encoded trace and to ImplementTrace. Add them in trace_totals. (best practice) [sources: src/devops_cli/roadmap/implement/implement_trace.py, src/devops_cli/roadmap/explain.py]
    • Chosen: Store the dropped attempt sums in the trace JSON. The bound can drop attempt events, so the totals must keep them.
    • Rejected: Leave dropped attempt events out of the totals. The totals would be wrong for a long run.
    • Rejected: Read the outcomes from another record. No other record holds the per-attempt outcomes.
  • How should decode treat an old trace with no dropped-sum keys?: Set each dropped sum to zero and decode the kept events. (best practice) [sources: src/devops_cli/roadmap/implement/implement_trace.py]
    • Chosen: Default a missing key to zero. Old records stay readable.
    • Rejected: Reject a trace with no dropped-sum keys. It breaks existing job records.
    • Rejected: Infer the sums from the dropped count. The count holds no tokens, seconds or outcomes.
  • Should the dropped-events line say that the totals include the dropped events?: Yes. Change the line to say that the totals include the dropped events. (best practice) [sources: openspec/specs/roadmap-explain/spec.md, src/devops_cli/roadmap/explain.py]
    • Chosen: Say that the totals include the dropped events. The totals now include them, so the text must match.
    • Rejected: Keep the text that the totals leave them out. The text would be false.
    • Rejected: Remove the dropped-events line. The spec requires the count beside the totals.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. A regression makes the explain command report zero totals for the runs users most need to inspect.
    • Value: Medium. Wrong totals mislead a reader diagnosing a long run, which is the primary use of explain.
    • Effort: Medium. The fix touches encode, decode, trace_totals, and needs a new test scenario.
    • Related: fix(roadmap): keep tool events in the trace of a long run #4393, which asks for a different change. #4393 asked to keep tool events in the trace; its fix (#4436) changed the drop order and introduced the regression this candidate reports.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at c653bde (see proposed design in issue body).

  6. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 11, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 11, 2026
  8. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor
  9. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 14:13 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions