Skip to content

fix(roadmap): log tokens on the result lines of five roadmap jobs #6360

Done

Description

@dan-petty

Problem

The result lines of five jobs carry no tokens= field, so the grades cannot give their cost per success.

  • Loki, 7 d to 2026-11-19, {namespace="devops",container=~"service|stage|fix-plan"} |= "roadmap job result:", lines with tokens= of all lines: refine 0/926, alternatives 0/591, intake 0/438, fix_checks 0/8, refine_judge 0/11. For comparison: stage 162/173, implement 89/89, retitle 24/24, fix_plan 3/3.
  • feat(roadmap): result lines state first-pass, model calls and cost #5168 added tokens= through job_result.attempt_context() (src/devops_cli/roadmap/job_result.py:245). src/devops_cli/roadmap/retitle.py:403 is the only caller of attempt_context() on origin/main.
  • DeepSeek tokens over 7 d (LiteLLM input plus output): 3,857 M. The result lines of stage, implement, fix_plan and retitle hold 2,525 M. So up to 1,332 M tokens have no job. This is an upper bound, because other callers also use the gateway.
  • devops roadmap eval grades --window 7d shows efficiency null for refine, alternatives and intake. The owner cannot rank these jobs by tokens per success.

Expected

  • refine, alternatives, intake, fix_checks and refine_judge open attempt_context() around each attempt, so each result line carries tokens=.
  • devops roadmap eval grades shows an efficiency value for these jobs.
  • Test first, one test for each job: a fake model call inside one attempt gives a result line with tokens= equal to the tokens of the fake call.
  • A field for the largest request (max_request_tokens=) is not part of this item.

Alternatives check of 2026-11-28: none.
Tool: none found.
Reason: Searches found open LLM observability tools (Langfuse, LiteLLM) that record tokens per call, but none writes the roadmap result line field that eval grades read; the work reuses the internal attempt_context() helper.

Lacks:

  • No write of tokens into the project's roadmap result lines
  • No per-job attribution that devops roadmap eval grades reads
  • Adoption needs a separate observability stack or gateway correlation work

Proposed design

Problem statement

The result lines of refine, alternatives and refine_judge carry no tokens= field. The owner cannot rank these jobs by token cost per success. The change opens the existing attempt_context() helper around each attempt so each result line carries token usage. The intake and fix_checks parts are deferred because their model calls and result lines run in separate phases or containers.

Acceptance criteria

Requirement: Refine result line has tokens

The refine job SHALL open attempt_context() around each attempt so its result line carries tokens=.

Scenario: Fake model call in one refine attempt

  • WHEN A test runs one refine attempt with a fake model call that reports 123 tokens.
  • THEN The result line for that attempt contains tokens=123.

Requirement: Alternatives result line has tokens

The alternatives job SHALL open attempt_context() around each attempt so its result line carries tokens=.

Scenario: Fake model call in one alternatives attempt

  • WHEN A test runs one alternatives attempt with a fake model call that reports 123 tokens.
  • THEN The result line for that attempt contains tokens=123.

Requirement: Refine-judge result line has tokens

The refine_judge job SHALL open attempt_context() around each attempt so its result line carries tokens=.

Scenario: Fake model call in one refine_judge attempt

  • WHEN A test runs one refine_judge attempt with a fake model call that reports 123 tokens.
  • THEN The result line for that attempt contains tokens=123.

Requirement: Refine and refine-judge keep separate token counts

The refine job SHALL NOT count the tokens of a refine_judge attempt in its own result line.

Scenario: Refine calls refine-judge

  • WHEN A test runs one refine attempt with a fake model call of 100 tokens and a nested refine_judge attempt with a fake model call of 23 tokens.
  • THEN The refine result line contains tokens=100 and the refine_judge result line contains tokens=23.

Requirement: Grades show efficiency from tokens

devops roadmap eval grades SHALL show a non-null efficiency value for refine, alternatives and refine_judge when their result lines carry tokens=.

Scenario: Efficiency from token result lines

  • WHEN A test feeds the grades evaluator one successful result line with tokens=100 for each of refine, alternatives and refine_judge.
  • THEN The evaluator prints a non-null efficiency value for each job.

Existing Tool Considered

The alternatives check in the issue body records verdict none on 2026-11-19 and names no tool. The block lists what the project's roadmap result lines lack. The change reuses the existing internal attempt_context() helper and adds no new token-tracking code.

Key questions

  • Which helper adds tokens= to a roadmap result line?: attempt_context() in src/devops_cli/roadmap/job_result.py:245 adds the token usage to the result line. src/devops_cli/roadmap/retitle.py:403 calls it around an attempt. [sources: src/devops_cli/roadmap/job_result.py:245, src/devops_cli/roadmap/retitle.py:403]
  • Can intake and fix_checks use attempt_context() alone to put tokens on their result lines?: No. plan_intake() makes the model calls and returns an IntakePlan. log_job_result(RoadmapJob.INTAKE, ...) runs later in apply_intake(). The fix_checks model repair runs in the agent container of a Kubernetes Job. log_job_result(RoadmapJob.FIX_CHECKS, ...) runs later in _report in the service container. The token count must cross a phase or container boundary. [sources: src/devops_cli/roadmap/intake/intake.py:1333, src/devops_cli/roadmap/intake/intake.py:1569, src/devops_cli/roadmap/fix_checks_row.py:408, src/devops_cli/commands/roadmap_step_fix_checks.py:153, src/devops_cli/roadmap/steps/fix_checks_phases.py:388]
  • Which jobs should this item wrap with attempt_context()?: Wrap refine, alternatives and refine_judge. Defer intake and fix_checks because their model calls and result lines run in separate phases or containers. (best practice) [sources: src/devops_cli/roadmap/job_result.py:245, src/devops_cli/roadmap/retitle.py:403, src/devops_cli/roadmap/intake/intake.py:1333, src/devops_cli/roadmap/fix_checks_row.py:408]
    • Chosen: Three in-process jobs. The three jobs make their model call and write their result line in one process. The stage return shows that intake and fix_checks do not.
    • Rejected: All five jobs. Intake logs its result after plan_intake() returns. Fix_checks logs its result after a separate Kubernetes Job. A simple context cannot carry the token count.
    • Rejected: Only retitle. Retitle already calls the helper. The item needs the three jobs that lack tokens.
  • How should refine and refine_judge nest their attempt_context() calls?: Open one attempt_context() for each result line. Do not nest the refine_judge context inside the refine context. If refine calls refine_judge, run that call after the refine context exits. (best practice) [sources: src/devops_cli/roadmap/job_result.py:245, src/devops_cli/roadmap/retitle.py:403]
    • Chosen: Separate context for each result line. Each result line gets its own token count. No model call is counted twice.
    • Rejected: Nested context with subtraction. The helper has no subtraction API. It adds code and risks double counting.
    • Rejected: One shared context for both. The second result line would repeat the first token count or carry none.
  • How should the tests prove the token field for each job?: Add one unit test for each of refine, alternatives and refine_judge. Each test runs one attempt with a fake model call that reports 123 tokens. Each test asserts that the result line contains tokens=123. (best practice) [sources: src/devops_cli/roadmap/job_result.py:245, src/devops_cli/roadmap/retitle.py:403]
    • Chosen: One unit test per job. The issue asks for one test for each job. Each test names the attempt boundary of one job.
    • Rejected: One parameterized test for all jobs. It hides which job lacks the call. It does not give one test for each job.
    • Rejected: Live Loki query. It needs deployed data. It is no offline test.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

#7150, #7151

Activity

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

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 19, 2026
  4. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • LiteLLM token usage tracking callback, results: 5
    • log LLM token usage per call Python library, results: 5
    • Langfuse LLM observability token usage tracing, results: 5
    • tiktoken count tokens Python library, results: 5
    • tokencost estimate LLM API cost tokens, results: 5
    • litellm github token usage cost tracking, results: 5
    • pydantic-ai usage tokens result, results: 5
    • litellm, results: 5
    • LLM observability open source token cost per request, results: 5
    • langfuse, results: 5

    Sources:

  5. added
    status/ready
    and removed
    status/new
    on Nov 19, 2026
  6. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    on Nov 25, 2026
  8. dan-petty commented on Nov 25, 2026

    @dan-petty
    OwnerAuthor

    Returned #6360 to New: the item cannot be built as written on origin/main.

    Evidence from the repository

    1. fix_checks does not run its model call and log_job_result in one attempt context.

      • log_job_result(RoadmapJob.FIX_CHECKS, ...) is called only in src/devops_cli/roadmap/fix_checks_row.py:408 (_report), which runs in the service container after an external Kubernetes Job (cronjob-runner.yaml, fix_unit) ends. _report makes no model call.
      • Inside that Kubernetes Job (k8s/devops/cronjob-runner.yaml, src/devops_cli/commands/roadmap_step_fix_checks.py:153-183), the model repair runs in the agent container (agent_phase in src/devops_cli/roadmap/steps/fix_checks_phases.py:388-404), which writes out/outcome.json and out/summary.json (AgentSummary) and returns None without calling log_job_result. publish_phase runs in the publish container and prints FixChecksReport.to_json() without tokens or log_job_result.
      • fix_checks_row._report reads only the "result" string from _RESULT_CONTAINERS = ("publish", "prepare") via result_of() (src/devops_cli/roadmap/fix_checks_row.py:127-130, 291-351) and passes counts={"attempt": _attempt(job), "seconds": seconds}. Also, RESULT_LINE_SELECTOR in src/devops_cli/roadmap/job_grade_report.py:123 queries {namespace="devops", container=~"service|stage|fix-plan"} and excludes runner containers.
      • Opening attempt_context() around _report or inside steps/fix_checks*.py (like retitle.py:403) therefore cannot place model tokens= onto RoadmapJob.FIX_CHECKS result lines. Carrying model tokens to fix_checks result lines requires propagating token counts across containers and pods (agent -> publish -> FixChecksReport or item job record -> fix_checks_row._report counts=), which the item's design excludes.
    2. intake splits model calls (plan_intake) and log_job_result (apply_intake) across separate phases with a shared batch _embed call.

      • plan_intake() (src/devops_cli/roadmap/intake/intake.py:1333-1380) calls _Planner.decide_all() (intake.py:1199-1214), which embeds all checked candidates in one batch call (_embed, intake.py:1225) before _decide() calls self.run.model.propose() per candidate, and returns IntakePlan.
      • log_job_result(RoadmapJob.INTAKE, ...) is called later in _count_candidate() inside apply_intake() (src/devops_cli/roadmap/intake/intake.py:1518, 1569-1590), after any attempt_context() opened in plan_intake has already reset and exited. Per-candidate tokens therefore cannot come from attempt_context() alone without carrying counts on IntakeDecision and deciding how to attribute shared _embed() batch tokens.

    Needed before re-readiness

    Refine #6360 to either:

    1. Scope the attempt_context() change to the in-process single-loop jobs (alternatives, refine, refine_judge, plus explicit refine/refine_judge nesting behavior) and split or specify separate designs for intake (IntakeDecision counts + batch _embed attribution) and fix_checks (cross-container / cross-pod token reporting into fix_checks_row._report).
  9. added
    status/new
    and removed
    status/ready
    on Nov 25, 2026
  10. added
    status/ready
    and removed
    status/new
    on Nov 25, 2026
  11. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  12. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  13. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  14. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:50 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/lowpriority/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