Skip to content

fix(roadmap): the plan group size measure differs between the stage and the Job #3265

Closed

Description

@dan-petty

Problem

The stage checks that each task group fits the token budget of a step (40,000 tokens). Two defects make the measure differ from the one the Job meets. Found by the fix agent of #3194, whose first draft had two groups over the budget (44,799 and 45,916 tokens) and had to be split:

  1. The measure depends on tiktoken. When the tiktoken cache is missing (offline), it falls back to a character heuristic, so a group can measure differently at the Job.
  2. The measure counts only the existing named files. A group that creates large files passes the measure and can still stop at the Job on its size.

Proposed change

  1. Use one counter in the stage and in the Job, and fail with a clear message (not a silent fallback) when the real counter is missing in the Job. If a fallback stays, state its error bound and keep a margin for it in the budget.
  2. Add the expected size of created files to the measure: a creates entry names a path, so the stage asks for a size estimate (a number of lines in the plan) and adds it. A group whose estimate is missing is refused.

Acceptance criteria

  1. A test shows that the same group text measures the same with the real counter and with the fallback, within the stated bound, or that the fallback is refused in the Job.
  2. A test shows that a group that creates a 1,500-line file is counted as over the budget.
  3. The prompt states the budget and the creation estimate, and the test(roadmap): check the planner prompt against its rules #3210 test passes.

Related: #3189, #3201, #3262.

Proposed design

Problem statement

The stage and the implement Job measure a task group with different token counts. The stage checks only existing named files, and the tiktoken fallback can change the count. A group can pass the stage and later stop at the Job on its size. This change uses one tiktoken counter in both paths. It fails when the counter is unavailable. It adds the estimated size of created files to the stage measure.

Acceptance criteria

Requirement: Same count in the stage and the Job

The stage and the implement Job SHALL use the same tiktoken encoding and return the same token count for the same task group text.

Scenario: Both paths count the same group

  • WHEN The stage and the Job count the same task group text and the tiktoken cache is present.
  • THEN Both return the same token count.

Requirement: Missing token cache fails clearly

The stage and the implement Job SHALL fail with a clear error when the tiktoken cache is missing.

Scenario: The token cache is missing

  • WHEN The stage or the Job measures a task group and the tiktoken cache is missing.
  • THEN The path fails with an error that names the missing cache and uses no character fallback.

Requirement: Creation estimate is required

The stage SHALL refuse a task group when a creates path has no line estimate.

Scenario: A creates path has no estimate

  • WHEN A task group creates a file and the plan gives no line estimate for that path.
  • THEN The stage refuses the group with an error that names the path.

Requirement: Created file size counts toward the budget

The stage SHALL add 32 tokens for each estimated line of a created file to the task-group token count.

Scenario: A group creates a 1,500-line file

  • WHEN A task group has a creates entry with a 1,500-line estimate and no other input.
  • THEN The stage counts the group as 48,000 tokens and refuses it as over the 40,000-token budget.

Requirement: Prompt states the budget and the estimate rule

The staging prompt SHALL state the 40,000-token step budget and the line-estimate rule for each creates path.

Scenario: The #3210 prompt test runs

Existing Tool Considered

No alternatives check has run. tiktoken is the open, maintained token counter that the repository already uses, and it covers exact BPE token counts. It lacks a bundled offline encoding cache and cannot estimate the size of files that a plan creates. Use tiktoken in both the stage and the Job. Add the creation estimate in the stage. Build no custom counter.

Key questions

  • Which token counter do the stage and the Job use?: Both use the exact tiktoken encoding that src/devops_cli/ai/context_budget.py selects for the step. The stage and the Job fail with a clear error when the tiktoken cache is missing. No character fallback is used. (best practice) [sources: src/devops_cli/ai/context_budget.py, src/devops_cli/roadmap/stage_change.py, CHANGELOG.md:1435]
    • Chosen: Exact tiktoken in both paths and fail when the cache is missing. It gives one measure and removes a silent difference.
    • Rejected: Character fallback with a stated bound and margin. It keeps the measure dependent on the cache state.
    • Rejected: Exact counter in the stage and a fallback in the Job. This is the defect that the issue reports.
  • How does the stage measure a file that a creates entry names?: The plan gives a line estimate for each creates path. The stage adds 32 tokens for each estimated line. The stage refuses a group when an estimate is missing. (best practice) [sources: src/devops_cli/roadmap/stage_change.py, tests/roadmap/test_roadmap_stage_plan.py]
    • Chosen: 32 tokens for each estimated line. A 1,500-line file then counts as 48,000 tokens and exceeds the 40,000-token budget.
    • Rejected: Four characters for each token. This heuristic can undercount dense code and let a large file pass.
    • Rejected: Count the file only after the Job creates it. The stage cannot reject the group before the Job.
  • What must the staging prompt state?: The prompt states the 40,000-token step budget and the rule that each creates path needs a line estimate. The test(roadmap): check the planner prompt against its rules #3210 prompt test must pass. (best practice) [sources: src/devops_cli/roadmap/stage_change.py, tests/roadmap/test_roadmap_stage_plan.py]
    • Chosen: State the budget and the creation-estimate rule. The planner needs both limits to size a group.
    • Rejected: State only the 40,000-token budget. The planner can omit the creation estimate and the stage will refuse it.
    • Rejected: State only the creation-estimate rule. The planner can exceed the step budget.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 2, 2026
  2. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

    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 real defect that causes groups to pass the stage check but fail at the Job, wasting work, but the Job still enforces the budget as a backstop.
    • Value: Medium. Prevents wasted Job runs and silent measurement drift, but does not block delivery entirely.
    • Effort: Medium. Requires unifying the counter in two code paths, adding a size estimate for created files, and writing tests for both defects.
    • Related: fix(roadmap): the stage job stops an item whose task group is a few percent over the budget after one split #2838, which asks for a different change. Both deal with the 40,000 token budget for task groups, but #2838 fixes enforcement for groups slightly over budget, while the candidate fixes the measurement method itself.
  3. added
    priority/p2-medium
    status/ready
    and removed
    status/new
    on Nov 2, 2026
  4. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

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

  5. devops-cli-service commented on Nov 3, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/3265-the-plan-group-size-measure-differs, draft pull request #3306. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Fail the token count when the cache is missing: 9259 tokens
    2. Measure created files and refuse a missing estimate: 13908 tokens
    3. State the budget and the estimate rule in the prompts: 5875 tokens

    The plan run made 2 model request(s), and used 130390 input tokens and 7092 output tokens. The model made no tool call.

    A model review of the plan found these points. They stop no draft, and a person judges them:

    • verify_form at group 3: The group says new prompt assertions pass, but no group writes them. Group 3 changes no test file and has no test. The verify command cannot show that the prompts state the budget and the estimate rule. Evidence: "so the test(roadmap): check the planner prompt against its rules #3210 prompt tests and the new prompt assertions pass"
  6. added 2 commits that reference this issue on Nov 3, 2026
  7. added
    status/planned
    and removed
    status/ready
    on Nov 3, 2026
  8. added
    status/in-progress
    and removed
    status/planned
    on Nov 3, 2026
  9. removed
    status/in-progress
    on Nov 3, 2026
  10. devops-cli-service commented on Nov 3, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-03 22:12 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/roadmaptype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions