Skip to content

fix(roadmap): keep tool events in the trace of a long run #4393

Closed

Description

@dan-petty

Problem Description

The trace of a long implement run (implement.trace, devops roadmap explain <issue> --trace) holds only the last model events. The tool and check events of the run are gone. This gives no data to judge the progress of a run that stopped.

ImplementTrace.encode drops the oldest events first until the text fits CONST_ROADMAP_IMPLEMENT_TRACE_CHARS. The step adds the model events of a turn after the turn ends (_trace_replies in implement_step.py), so the events are not in the order of the run. For a run of about 100 requests, the oldest events are the tool and check events of the step, and they are the first to go.

Reproduction Steps

  1. Run uv run devops roadmap explain 3443 --trace for an item whose run stopped with limit_reached (for example fix(roadmap): Name the test case that a change invalidates #3443, test(roadmap): fault-injection tests prove the pipeline recovers #3075 or feat(roadmap): map all issue requirements to a group #3253).
  2. Count the events: 66 model events, 1 attempt event, no tool and no check event. The count dropped is 71 to 543.

Expected vs Actual Behavior

Expected: the trace of a stopped run shows, for the last part of the run, the tool calls (tool, outcome, argument digest) and the checks (command, exit status), in the order they happened, with the tokens of each request next to them.

Actual: only the tokens, seconds and model of the last 66 requests. A reader cannot see whether the agent edited a file, repeated a call or got a failing check. The Job log in Loki holds the tool names and outcomes, but no exit status and no tokens.

Environment Diagnostics

Found on 2026-11-10 while a measurement of the progress of 419 implement runs (14 days) looked for data to judge progress at a limit. Related: #4115, #4075, #4043.

Logs, Traces, or Terminal Output

Events kept by the trace for 17 stopped runs of limit_reached: all model and attempt, none tool or check.

Proposed design

Problem statement

The implement trace of a long run keeps only the last model events. It loses the tool and check events that show progress. The fix keeps those events within the existing trace bound and in run order.

Acceptance criteria

Requirement: Protect progress events from the trace bound

The implement trace SHALL drop the oldest model events before it drops any tool, check or attempt event when the encoded value exceeds CONST_ROADMAP_IMPLEMENT_TRACE_CHARS.

Scenario: Many model events exceed the bound

  • WHEN A run records 200 model events and 5 tool or check events, and the encoded value exceeds CONST_ROADMAP_IMPLEMENT_TRACE_CHARS.
  • THEN The encoded value is not longer than the bound, it contains all 5 tool or check events, and dropped counts only the removed model events.

Requirement: Keep run order for late model events

The implement trace SHALL order every retained event by the sequence in which the run made it.

Scenario: Model event appended after a turn

  • WHEN A turn records a model request, two tool calls and one check before the step appends the model event.
  • THEN The encoded and rendered trace shows the model event, the two tool events and the check event in that run order.

Requirement: Keep token counts with their request

The implement trace SHALL keep the input and output token counts of a retained model event with that event.

Scenario: Rendered trace with token counts

  • WHEN A stopped run has a retained model event with 120 input tokens and 30 output tokens and a following tool event.
  • THEN The rendered trace shows 120 input tokens and 30 output tokens on the model event before the tool event.

Requirement: Render tool and check details

The roadmap explain command SHALL render retained tool events with name, outcome and digest and retained check events with command and exit status.

Scenario: Explain a trace with a failed check

  • WHEN The trace holds a check event for command pytest with exit status 1 and a tool event with outcome failed.
  • THEN The command output shows the command pytest, exit status 1 and the tool outcome failed.

Requirement: Count dropped events

The implement trace SHALL count every event that it removes from the encoded value in the dropped field.

Scenario: Bound removes mixed events

  • WHEN The trace holds 100 model events and 10 tool events, and the bound removes 100 model events and 2 tool events.
  • THEN The encoded value reports dropped as 102 and keeps the newest 8 tool events.

Requirement: Read traces that predate the sequence field

The implement trace decoder SHALL accept events that have no sequence field and keep their stored list order.

Scenario: Decode a stored trace from before the change

  • WHEN A stored trace holds model and tool events without a sequence field.
  • THEN The decoder returns the events in their stored order and raises no error.

Existing Tool Considered

No alternatives check has run. No open, maintained tool covers this compact, project-specific trace in the issue body. The change builds its own code in src/devops_cli/roadmap/implement/implement_trace.py and src/devops_cli/roadmap/implement/implement_step.py. Cost: about 6,000 tokens to build, 3,000 tokens to keep and fix, and 1 day elapsed.

Key questions

  • Which events does the trace drop first when the encoded value exceeds CONST_ROADMAP_IMPLEMENT_TRACE_CHARS?: Drop the oldest model events first. Drop the oldest remaining events only after no model event remains. Keep tool, check and attempt events as long as the bound allows. (best practice) [sources: src/devops_cli/roadmap/implement/implement_trace.py, src/devops_cli/roadmap/implement/implement_step.py:852, openspec/changes/archive/2026-11-03-3032-a-trace-of-every-run-kept/proposal.md]
    • Chosen: Protect tool, check and attempt events. These events are few and show progress, while model events repeat.
    • Rejected: Drop oldest events by time. This removes the oldest tool and check events first, the reported defect.
    • Rejected: Use a fixed quota for each event kind. It wastes space when one kind is absent and adds configuration.
  • How does the trace keep run order when the step appends model events after a turn?: Assign a monotonic sequence number to every event when the run makes it. Encode and render in that order. (best practice) [sources: src/devops_cli/roadmap/implement/implement_step.py:852, src/devops_cli/roadmap/implement/implement_trace.py, openspec/changes/archive/2026-11-03-3032-a-trace-of-every-run-kept/proposal.md]
    • Chosen: Monotonic sequence number. It keeps order without a second write or a clock.
    • Rejected: Wall-clock timestamp. Clocks can tie or skew.
    • Rejected: Placeholder event at request start. A stopped step can leave a partial event.
  • What is the existing character bound for the implement trace?: The bound is 8192 characters in CONST_ROADMAP_IMPLEMENT_TRACE_CHARS. [sources: src/devops_cli/config/constants.py, openspec/changes/archive/2026-11-03-3032-a-trace-of-every-run-kept/proposal.md]
  • How does the decoder handle stored traces that have no sequence field?: The decoder treats the sequence field as optional and keeps the stored list order. (best practice) [sources: src/devops_cli/roadmap/implement/implement_trace.py, openspec/changes/archive/2026-11-03-3032-a-trace-of-every-run-kept/proposal.md]
    • Chosen: Optional sequence with list-order fallback. Old traces stay readable.
    • Rejected: Required sequence field. Old traces fail to decode.
    • Rejected: Rewrite old traces on read. It changes stored data and needs a write.

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 10, 2026
  2. dan-petty commented on Nov 10, 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. The trace loses all tool and check data for long runs, blocking diagnosis of stopped runs, but Loki logs still hold partial data.
    • Value: Medium. Readers cannot judge the progress of a stopped run without tool calls and check results in the trace.
    • Effort: Medium. The fix targets one method, ImplementTrace.encode, to change which events are dropped first.
    • Related: feat(roadmap): a trace of every run, kept and shown in the PR comment and in explain #3032, which asks for a different change. #3032 created the trace record with ordered events; the candidate fixes a defect in how that trace encodes events for long runs.
  3. added
    priority/p2-medium
    owner/agent
    on Nov 10, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 10, 2026
  5. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

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

  6. added
    status/in-progress
    and removed
    status/ready
    on Nov 11, 2026
  7. removed
    status/in-progress
    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 00:59 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