Skip to content

feat(roadmap): halt implement step when all group tasks are verified #4075

Not planned

Description

@dan-petty

Problem or Motivation

In src/devops_cli/roadmap/implement/implement_step.py, an agent runs turns until it stops or until limits stop it.

When an agent completes all tasks of its task group, it ticks each task in tasks.md. WipKeeper verifies each ticked task.

In issue #3253 (pull request #4035), the agent completed task 1.1 and task 1.2 in 18 seconds. Both tasks passed verification. tasks.md held no unticked task for group 1.

The agent did not stop. It executed more tool calls across many turns. Each turn sent the full prompt context of 140,000 tokens. The step spent its full budget of 8,000,000 tokens (roadmap.implement.step_token_budget=8000000) and stopped with limit_reached.

The job marked issue #3253 blocked, although all tasks of the group were complete and verified.

Proposed Solution & Architectural Design

  1. Add a check in implement_step.py that inspects keeper.tasks_file or the group task list after each turn.
  2. When every task of the assigned group is ticked and verified:
    • Provide an instruction in the next turn message: "All tasks of group {number} are ticked and verified. Provide your summary now and call no further tools."
    • If the agent calls more tools without unticking or changing code, stop the agent loop cleanly and start the step exit checks.
  3. Update src/devops_cli/ai/tasks/roadmap_implement_step.md to state clearly:
    "When all tasks of your group are ticked and their verification commands pass, stop tool calls and write your final summary."

Target Subsystem

AI & Agentic Review Pipeline

Existing Tool Considered

PydanticAI agent run loop controls. Building this check in implement_step.py requires approximately 10,000 tokens to implement and test.

Standards Compliance

  • I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 5, zero bare exceptions, tests that cover the changed lines).
  • I am willing to submit a pull request implementing this feature with accompanying tests.

Source: #3253

Dependencies

Alternatives check of 2026-11-25: in-use.
The repository already uses this tool.
Tool: pydantic-ai (https://pypi.org/project/pydantic-ai), MIT, last activity 2026-11-25, maintained.
Reason: Searches found no library that detects a complete OpenSpec task group; PydanticAI, already used, supplies only run-loop hooks and limits, so the completion policy, the final instruction and the prompt rule must be written.

Covers:

  • Agent run loop with request and token limits
  • Hooks that run before each model request
  • Ends a run through an exception from a hook

Lacks:

  • No notion of a ticked and verified task group
  • No check that a task group is complete
  • No instruction that asks the agent for its summary

Proposed design

Problem statement

The implement step continues to send model requests after the agent ticks every task of its group. Each request resends a prompt of about 140,000 tokens. A completed group can spend the full step token budget and stop with limit_reached, which marks a complete item blocked. The change detects a ticked and verified group before a request, adds one final instruction, and ends the loop before the next request so the exit checks and the commit still run.

Acceptance criteria

Requirement: Completion check before a request

The implement step SHALL treat the assigned group as complete before a model request when every task of the group is ticked and each verification command of the group passes.

Scenario: Every task of the group is ticked and verified

  • WHEN A step runs with a scripted model that ticks every task of group 1 and whose group verification command exits 0, and the before-request check runs.
  • THEN The check reports group 1 as complete before the next model request is sent.

Requirement: One final instruction

The step SHALL add exactly one final instruction to the next model request after it marks the group complete.

Scenario: Final instruction in the next request

  • WHEN The check marks group 1 complete and the step has sent no final instruction for that group.
  • THEN The next request carries one part with the text All tasks of group 1 are ticked and verified. Provide your summary now and call no further tools., and a second before-request check adds no second part.

Requirement: Stop after the final instruction

The step SHALL end the agent loop before the next model request when every task of the group stays ticked after the final instruction.

Scenario: The agent calls a tool after the final instruction

  • WHEN The scripted model answers the final instruction with a tool call and leaves every task of group 1 ticked.
  • THEN The run ends with an empty failure reason, and run_step runs the exit checks and commits the group when they pass.

Requirement: Untick keeps the loop running

The step MUST NOT end the agent loop when the agent unticks a task of the group after the final instruction.

Scenario: The agent unticks a task

  • WHEN The scripted model unticks one task of group 1 after the final instruction and sends another request.
  • THEN The check reports group 1 as incomplete, the request is sent, and the run records no stop.

Requirement: Prompt states the stop rule

The implement prompt SHALL tell the agent to stop tool calls and write its final summary when every task of its group is ticked and its verification commands pass.

Scenario: Prompt text

  • WHEN A test calls load_task_prompt for roadmap_implement_step.md with the tools table of the step.
  • THEN The returned prompt text holds the sentence When all tasks of your group are ticked and their verification commands pass, stop tool calls and write your final summary.

Existing Tool Considered

pydantic-ai (https://pypi.org/project/pydantic-ai), MIT, maintained, verdict in-use: the repository already uses it. The alternatives check in the issue body holds what the tool covers and what it lacks. The change writes the completion policy on the existing before_model_request hook and the RequireVerification and WrapUpAtLimits capabilities. The repository builds and keeps that policy: about 10,000 tokens to write and test it, plus upkeep, and about one working day.

Key questions

  • Where does the step check for a complete group?: Before each model request, in a before_model_request hook added beside limit_hooks and ToolCallLog.hooks. The hook runs before the full prompt goes out. (best practice) [sources: src/devops_cli/roadmap/implement/implement_limits.py, src/devops_cli/roadmap/implement/implement_step.py, src/devops_cli/roadmap/implement/implement_tool_log.py]
    • Chosen: Before each model request. The hook runs at the only point before a full prompt goes out, and the step already stops a run there with LimitReached.
    • Rejected: After each run_sync turn. A turn holds many model requests, so the step would still send extra full prompts.
    • Rejected: Only in the prompt. The model ignored the prompt in issue feat(roadmap): map all issue requirements to a group #3253.
  • How does the step know that every task of the group is ticked and verified?: The new completion state re-parses the group from tasks.md with parse_task_groups, reads GroupTask.ticked, and runs the group verification commands once with commands_failure after every task is ticked. It records the run in log.verified, the same record that the exit check reads. (best practice) [sources: src/devops_cli/roadmap/step_files.py, src/devops_cli/roadmap/implement/implement_step.py, src/devops_cli/roadmap/implement/implement_tool_log.py]
    • Chosen: Re-parse the tasks file and run verification once. The step already owns the file and the verification commands, and the exit check uses the same two sources.
    • Rejected: Read StepInputs.group alone. It is the group text from before the run, so it never shows the ticks the agent writes.
    • Rejected: Trust the ticks alone. A tick does not show that the verification command passed.
    • Rejected: Re-run every verification before each request. It repeats expensive commands at every request and duplicates the exit check.
  • What does the step do when the group becomes complete?: The hook adds one final instruction to the pending request and stops on the next request. It returns the request context with one extra UserPromptPart, records that it sent it, and raises a completion exception before the next request when the group is still complete. (best practice) [sources: src/devops_cli/roadmap/implement/implement_step.py, src/devops_cli/ai/tasks/roadmap_implement_step.md]
    • Chosen: One final instruction in the pending request, then stop. It gives the agent one chance to write the summary, bounds the extra cost to one request, and uses one hook for both the instruction and the stop.
    • Rejected: Stop at once. The step loses the summary that the prompt asks for.
    • Rejected: A second _run_turn with the message. It ends the run first and starts a second one, so the instruction and the stop need two paths.
    • Rejected: Run until a limit. It spends the token budget and marks a complete item blocked, as issue feat(roadmap): map all issue requirements to a group #3253 shows.
  • How does the step end the agent loop with no failure reason?: The hook raises a private completion exception. _run_turn catches it beside its handlers and returns a _Run with an empty reason and no failure_class, so _attempt runs the exit checks and the done path. (best practice) [sources: src/devops_cli/roadmap/implement/implement_limits.py, src/devops_cli/roadmap/implement/implement_step.py, src/devops_cli/roadmap/failure.py]
    • Chosen: Private completion exception. It ends the loop before the next request and keeps the exit checks and the done path.
    • Rejected: Raise LimitReached. It classifies the stop as limit_reached and blocks the item.
    • Rejected: Let the agent end on its own. The agent can continue for many turns and spend the full budget, as issue feat(roadmap): map all issue requirements to a group #3253 shows.
  • What does the implement prompt say?: Add one sentence to src/devops_cli/ai/tasks/roadmap_implement_step.md: when every task of the group is ticked and its verification commands pass, stop tool calls and write the final summary. The code guard enforces it. (best practice) [sources: src/devops_cli/ai/tasks/roadmap_implement_step.md, src/devops_cli/ai/task_loader.py]
    • Chosen: Add the stop sentence to the prompt. The prompt is the instruction of the agent, and the code guard enforces it.
    • Rejected: Change the prompt only. The prompt alone did not stop the agent in issue feat(roadmap): map all issue requirements to a group #3253.
    • Rejected: Change the code only. The agent would not know why the step stops before its summary.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#6521

Activity

  1. added
    source/agent
    on Nov 7, 2026
  2. added
    type/feature
    scope/roadmap
    status/new
    value/high
    effort/medium
    on Nov 7, 2026
  3. dan-petty commented on Nov 7, 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/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. The step wastes 8 million tokens and marks a complete job as blocked, but the work is not lost and a person can re-run the step.
    • Value: High. It stops token burn and prevents a false blocked status when all tasks are already verified.
    • Effort: Medium. The body estimates roughly 10,000 tokens of code and tests across implement_step.py and the prompt file.
    • Related: feat(roadmap): devops roadmap implement runs one task group of a staged change in one 128k context with the pydantic-ai-harness Coder #2664, which asks for a different change. Both concern the implement step created by #2664, but #2664 builds the step while the candidate adds a halt condition when all group tasks are verified.
  4. added
    priority/p2-medium
    on Nov 7, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  6. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

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

  7. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Reason: PydanticAI is an open, maintained agent framework that provides the run loop and the before-request hook this change would build on. The one search for a ready-made "halt when all tasks verified" tool returned nothing relevant. No tool covers the OpenSpec task-group completion policy, so the project has to write that part itself. No ADR rejects PydanticAI. The issue does not name it as in use, only as the "Existing Tool Considered".

    Tool: pydantic/pydantic-ai (https://github.com/pydantic/pydantic-ai)

    • License: MIT
    • Last activity: 2026-11-10
    • Maintained: yes

    Covers:

    • Agent run loop
    • Before-request hook for stopping before a model request

    Lacks:

    • Policy for an OpenSpec task group that is ticked and verified
    • WipKeeper completion predicate
    • Single final-summary instruction and exit-check handoff

    Tools considered:

    Searches run:

    • pydantic-ai stop agent run loop early custom condition before model request hook, results: 5

    Sources:

    Checked on 2026-11-10. A person decides what this means for the item. The check changes no label and closes no issue.

  8. added
    owner/service
    and removed
    owner/service
    on Nov 18, 2026
  9. 6 remaining items

  10. added
    owner/service
    and removed
    owner/service
    on Nov 19, 2026
  11. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Owner question: The inputs of the step of the task group "End the loop with one final instruction when the group is complete" hold 64313 tokens, over the budget of 64000 tokens, also after the model split the groups once. Split the group or raise the budget of the step?

    Options

    1. Split the group: A person splits the group and runs the item again.
    2. Raise the budget: A person raises the budget of the step and runs the item again.

    Recommendation: Split the group: the plan check keeps the budget of the step.

    Evidence

  12. removed
    owner/service
    on Nov 20, 2026
  13. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Frozen on 2026-11-20. The stage, implement and fix-checks jobs grade under 60%, so the owner rule asks for a re-architecture before more fixes inside the current design (tracker #6519). This item is incremental work on those jobs, so its Dependencies section now names #6521 first. Stage and implement leave this item while #6521 is open. When the experiments of #6519 decide, a person closes #6521 (this item can then continue) or closes this item as not planned.

  14. dan-petty commented on Nov 24, 2026

    @dan-petty
    OwnerAuthor

    Split the group.

  15. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: in-use, tool https://github.com/pydantic/pydantic-ai. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • pydantic-ai stop agent run from before_request hook, results: 5
    • open source agent loop stop when all tasks complete verified guard, results: 5
    • "pydantic-ai" usage limits stop agent iterations, results: 5
    • pydantic-ai docs hooks agent run loop, results: 5
    • AI coding agent continues after all tasks complete token budget wasted stop condition, results: 5
    • pydantic ai agent framework github repository, results: 5

    Sources:

  16. added
    status/new
    and removed
    status/ready
    on Nov 26, 2026
  17. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies and Watched files in the section Proposed design of the body.

  18. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  19. dan-petty commented on Nov 30, 2026

    @dan-petty
    OwnerAuthor

    Triage under #6519 (owner instruction of 2026-11-30), before the hold #6521 closes. This item adds or extends a gate, refusal, screen, cap, limit, retry, result line, shell allowlist, tool catalog or plan-shape rule of the stage, implement or fix-checks job. #6519 found that 263 of about 900 issues in four weeks added such rules and none replaced the engine. Stage now runs on stock Coder (grade 60 on 30 graded attempts), where the agent reads the repository, runs the checks in its loop and has a real shell; implement follows (#6527). The code paths that this item names have also moved. If the failure class still shows in graded attempts, file a new item from that evidence. Closed as not planned; a person may reopen it.

  20. removed
    status/new
    on Nov 30, 2026
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/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions