Skip to content

feat(roadmap): the implement job re-checks a plan premise against the base #3417

Closed

Description

@dan-petty

Problem or Motivation

The implement job runs the task groups of a Staged plan without a deterministic check that the plan's premise still holds. The step model can report a false premise with a plan-request of kind premise (_return_premise in src/devops_cli/roadmap/implement_run.py:582), but that relies on the model to notice the defect, after a model call.

The plan of PR #3374 (for #3368) is an example. It passed check_proposal and opened as a draft, so the plan check that #3393 adds would accept it. Its premise is false: it adds a title guard that _delivery_title already runs (#3319). The implement job would duplicate the guard, or stop only if the step model noticed the defect.

#3393 re-runs the plan check before the job starts a step. It does not check the base for the behavior that the plan adds.

Proposed Solution & Architectural Design

  1. Before a behavior group starts, the implement job checks the plan's premise against the branch it will change: when a task adds a guard or a check that the base already runs, stop the item with the evidence and write nothing.
  2. Reuse the premise check of the stage job rather than build a second; extract the check that a claimed missing check is absent into a shared function.
  3. Add a test in tests/roadmap/test_roadmap_implement_job.py for a plan that adds a guard that the base already runs, and one for a plan whose premise is true.

Target Subsystem

src/devops_cli/roadmap/implement.py, src/devops_cli/roadmap/implement_run.py

Existing Tool Considered

The stage premise check (#3176) exists in src/devops_cli/roadmap/stage_probe.py. This change extracts and reuses it instead of building a second check. Cost: about 6,000 tokens to extract and test, about 1,000 tokens to keep, and about 2 hours elapsed. The change deletes no internal code.

Source: PR #3374

Proposed design

Problem statement

The implement job runs a plan without a deterministic check that the plan's premise still holds. A step model can report a false premise, but only after a model call. A plan can add a guard that the base already runs. The job then duplicates the guard or stops only when the model notices.

Acceptance criteria

Requirement: Shared premise check

The stage job and the implement job SHALL call one shared function that reports whether a cited identifier has a definition at a commit.

Scenario: Both jobs use the shared function

  • WHEN The stage job probes a cited identifier and the implement job checks a task at the same commit
  • THEN Both jobs get the same definition lines from one function in src/devops_cli/roadmap/premise.py.

Requirement: False premise

The job SHALL return the item to New with the evidence when a behavior group task adds a guard that the branch tip defines.

Scenario: A task adds a guard that the base already runs

  • WHEN A behavior group task says to add _delivery_title and the branch tip defines _delivery_title
  • THEN The job runs no group step, writes no group file, makes no group commit, and comments the definition line.

Requirement: True premise

When the shared check finds no definition for a guard that a behavior group task adds, the job SHALL run the group.

Scenario: A task adds a guard that the base lacks

  • WHEN A behavior group task says to add a guard name that the branch tip does not define
  • THEN The job runs the group and commits the file that the group writes.

Requirement: Behavior groups only

The job SHALL run the premise check only for a behavior group.

Scenario: A non-behavior group adds a defined name

  • WHEN A group whose kind is not behavior has a task that says to add a name that the branch tip defines
  • THEN The job does not return the item to New and runs the group.

Requirement: Premise tests

The implement job test module SHALL hold one test for a false premise and one test for a true premise.

Scenario: The two premise tests run

  • WHEN The test suite runs tests/roadmap/test_roadmap_implement_job.py
  • THEN One test asserts the return to New with evidence and one test asserts the group runs.

Existing Tool Considered

No alternatives check has run. The stage premise check (#3176) in src/devops_cli/roadmap/stage_probe.py covers cited paths and identifiers at a commit. It lacks a decision that a task adds a guard that the base already runs. The change extracts and reuses it. Cost: about 6,000 tokens to extract and test, about 1,000 tokens to keep, and about 2 hours elapsed. The change deletes no internal code.

Key questions

  • What does the job do when the deterministic check finds a false premise?: It returns the item to New with the evidence, as the existing premise path does. It does not block the item. (best practice) [sources: CONTEXT.md, docs/ROADMAP_WORKFLOW.md:139, src/devops_cli/roadmap/implement_run.py:582]
    • Chosen: Return to New. CONTEXT.md and the failure table record that a false premise returns the item to New.
    • Rejected: Block the item. It conflicts with the recorded premise outcome and adds a retry wait.
  • Which commit does the check read?: The worktree HEAD before the group starts. That is the branch tip that the group will change. (best practice) [sources: src/devops_cli/roadmap/implement_run.py, src/devops_cli/roadmap/implement.py]
    • Chosen: Current worktree HEAD. It includes the staged plan and the work of earlier groups.
    • Rejected: Default branch only. It misses a duplicate that an earlier group adds.
  • Where does the shared check live?: In a new module src/devops_cli/roadmap/premise.py. The stage probe and the implement job import it. (best practice) [sources: src/devops_cli/roadmap/stage_probe.py, src/devops_cli/roadmap/implement_run.py:582]
    • Chosen: New module. It avoids a private import from stage_probe.py and keeps one check.
    • Rejected: Private import from stage_probe. It couples the implement job to the stage probe internals.
    • Rejected: Duplicate check. It creates two checks to keep in step.
  • How does the job detect a task that adds a guard the base already runs?: It reads a task line for an add verb and a backticked identifier. The line must also name a guard or a check. The shared function then looks for definitions at the branch tip. A definition makes the premise false. (best practice) [sources: src/devops_cli/roadmap/stage_probe.py, src/devops_cli/roadmap/step_files.py]
    • Chosen: Deterministic text rule. It needs no model call and is testable offline.
    • Rejected: Model call. It repeats the defect that the issue fixes.
    • Rejected: Whole-text grep. It reports names that the task does not add.
  • Which groups does the check cover?: Only a group whose kind is behavior. A group that is not behavior does not add product guards. (best practice) [sources: src/devops_cli/roadmap/step_files.py, src/devops_cli/roadmap/implement_run.py]
    • Chosen: Behavior groups only. The issue names behavior groups and other groups add no product guard.
    • Rejected: Every group. It can return an item for a docs or test task.
  • Which tests cover the change?: Add two tests to tests/roadmap/test_roadmap_implement_job.py. One test uses a plan that adds a guard the base already runs. One test uses a plan whose premise is true. (best practice) [sources: tests/roadmap/test_roadmap_implement_job.py]
    • Chosen: Extend the implement job test module. It already holds the job stop tests and the fakes.
    • Rejected: New test module. It would mirror one helper and split the job cases.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 4, 2026
  2. dan-petty commented on Nov 4, 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. It prevents the implement job from adding a guard the base already runs, but the stage job should catch most false premises first.
    • Value: Medium. It stops wasted model calls and duplicate guards in the implement job, but the stage job already filters most cases.
    • Effort: Medium. Extract one shared function, wire it into the implement job, and add two tests; the candidate estimates about 2 hours.
    • Related: feat(roadmap): Verify a claimed missing check in helpers and base #3416, which asks for a different change. Both extract the 'claimed missing check is absent' check into a shared function; #3416 applies it in the stage job while the candidate applies it in the implement job.
  3. added
    priority/p2-medium
    on Nov 4, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 4, 2026
  5. devops-cli-service commented on Nov 4, 2026

    @devops-cli-service
    Contributor

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

  6. devops-cli-service commented on Nov 4, 2026

    @devops-cli-service
    Contributor

    Staged: branch feat/3417-the-implement-job-re-checks-a, draft pull request #3438. 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. Extract the shared definition check into the premise module: 27300 tokens
    2. Check the premise of a behavior group before its step: 24844 tokens
    3. Record the new premise check on the implement page: 8489 tokens

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

    • other at group 1: The plan moves the git grep call out of _Run.identifier into premise.py. The grep then bypasses _Run.git, so it is not counted against the command budget. It also bypasses the stage_probe.git_result spy in test_roadmap_stage_probe.py. The plan does not change that test file, so the verify command is likely to fail. Evidence: "Move _definition_pattern and the definition branch of _Run.identifier of src/devops_cli/roadmap/stage_probe.py into the new module, and call it from _Run.identifier so the stage probe keeps its behavior and its messages"

    The plan run made 3 model request(s), and used 233289 input tokens and 11715 output tokens. The model made no tool call.

    The stage job read the open pull requests and their files in 1 GraphQL request(s).

  7. added 2 commits that reference this issue on Nov 4, 2026
  8. removed
    status/ready
    on Nov 4, 2026
  9. 3 remaining items

  10. added
    status/in-progress
    on Nov 5, 2026
  11. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Stopped at group 2.

    Failure class: limit_reached.
    Action taken: none.
    Action left: raise_limit: raise the limit that the run went over.

    Step Status Attempts Tokens in/out Last failing command
    group 1 done 2 4043630/24013 pytest on base: tests/roadmap/test_premise.py
    group 2 stopped 1 8131072/34725 -

    Reason:

    LimitReached: The step spent its budget `roadmap.implement.step_token_budget=8000000`.
    Refused commands: grep 3, git 1. Other retries: 2.
    

    Last message of the agent (a claim that no check verified): Now the imports and the guard_names helper.

    The job discarded this work. Read it before you retry:

    diff --git a/src/devops_cli/roadmap/implement_run.py b/src/devops_cli/roadmap/implement_run.py
    index 98425972..204e4c01 100644
    --- a/src/devops_cli/roadmap/implement_run.py
    +++ b/src/devops_cli/roadmap/implement_run.py
    @@ -58,7 +58,7 @@ from contextlib import contextmanager
     from dataclasses import dataclass, field, replace
     from enum import StrEnum
     from pathlib import Path
    -from typing import Any, NamedTuple, NoReturn
    +from typing import Any, Final, NamedTuple, NoReturn
     
     from devops_cli.ai.client.models import AIClientError, AICredentialsError
     from devops_cli.config.commands import BIN_DEVOPS, BIN_GIT, BIN_UV
    @@ -150,6 +150,8 @@ from devops_cli.roadmap.implement_trace import (
     )
     from devops_cli.roadmap.implement_wip import WipCommit, kept_commits
     from devops_cli.roadmap.pull_form import title_problems
    +from devops_cli.roadmap.plan_read import group_kind
    +from devops_cli.roadmap.premise import definition_lines
     from devops_cli.roadmap.pull_labels import (
         add_pull_labels,
         declared_labels,
    @@ -158,6 +160,7 @@ from devops_cli.roadmap.pull_labels import (
     )
     from devops_cli.roadmap.return_item import apply_return, plan_return
     from devops_cli.roadmap.stage_change import (
    +    GroupKind,
         closing_keyword_in,
         criteria_section,
         delivery_title,
    @@ -170,12 +173,19 @@ from devops_cli.roadmap.stage_form import form_problems
     from devops_cli.roadmap.stage_paths import StagedTree, path_problems
     from devops_cli.roadmap.stage_split import ask_split
     from devops_cli.roadmap.status_sync import StatusFacts, derive_status
    -from devops_cli.roadmap.step_files import TaskGroup, parse_task_groups, section_text
    +from devops_cli.roadmap.step_files import TaskGroup, code_spans, parse_task_groups, section_text
     from devops_cli.roadmap.store import ImplementRecordKey, Item, ItemField, RoadmapStore
     from devops_cli.roadmap.title_labels import title_labels
     from devops_cli.security.sanitizer import mask_secrets
     
     _WHY_HEADINGS = frozenset({"why"})
    +# The words of a task that adds a guard (#3417): an add verb, and the word that names a guard. The
    +# task names the guard in a code span that is an identifier.
    +_ADD_VERB: Final[re.Pattern[str]] = re.compile(r"\b(add|adds|adding|implement|implements)\b", re.I)
    +_GUARD_WORD: Final[re.Pattern[str]] = re.compile(
    +    r"\b(guard|guards|check|checks|validation|validate)\b", re.I
    +)
    +_IDENTIFIER: Final[re.Pattern[str]] = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
     
     
     class _Mark(NamedTuple):
    diff --git a/src/devops_cli/roadmap/plan_read.py b/src/devops_cli/roadmap/plan_read.py
    index 42eba35a..9a424a04 100644
    --- a/src/devops_cli/roadmap/plan_read.py
    +++ b/src/devops_cli/roadmap/plan_read.py
    @@ -284,14 +284,9 @@ class _Task:
     
     def _task(group: TaskGroup, index: int) -> _Task:
         text = _task_texts(group)[index]
    -    suffixes = _verification_suffixes(group.text)
         task = group.tasks[index]
         if task.verification:
    -        return _Task(
    -            text=text,
    -            verification=task.verification[0],
    -            suffix=suffixes[index] if index < len(suffixes) else None,
    -        )
    +        return _Task(text=text, verification=task.verification[0], suffix=_suffix(group, index))
         match = _INLINE_VERIFY.search(text)
         if match is None:
             return _Task(text=text, verification=None, suffix=None)
    @@ -302,11 +297,29 @@ def _task(group: TaskGroup, index: int) -> _Task:
         )
     
     
    -def _kind(text: str, first: _Task) -> GroupKind:
    -    found = KIND_LINE.search(text)
    +def _suffix(group: TaskGroup, index: int) -> str | None:
    +    """The suffix of the `Verification:` line of the task at `index`: the `fails on the base`
    +    sentence that tells a behavior group (#3042). None when the task has no such line, and for a
    +    task whose `Verify that` sentence names no suffix."""
    +    task = group.tasks[index]
    +    if task.verification:
    +        suffixes = _verification_suffixes(group.text)
    +        return suffixes[index] if index < len(suffixes) else None
    +    match = _INLINE_VERIFY.search(task.text)
    +    return match["suffix"].strip() if match is not None else None
    +
    +
    +def group_kind(group: TaskGroup) -> GroupKind:
    +    """The kind of `group`: `behavior` when the group says `Kind: behavior.` or the first task's
    +    `Verification:` line ends with `fails on the base`, and `other` otherwise. The stage reader
    +    infers the kind of a plan, and the implement job reads it to run the premise check of a
    +    behavior group only (#3417)."""
    +    found = KIND_LINE.search(group.text)
         if found is not None and found["kind"] == GroupKind.BEHAVIOR.value:
             return GroupKind.BEHAVIOR
    -    return GroupKind.BEHAVIOR if first.suffix == FAILS_ON_BASE else GroupKind.OTHER
    +    if not group.tasks:
    +        return GroupKind.OTHER
    +    return GroupKind.BEHAVIOR if _suffix(group, 0) == FAILS_ON_BASE else GroupKind.OTHER
     
     
     def _verification_problems(group: TaskGroup, first: _Task) -> list[str]:
    @@ -334,7 +347,7 @@ def _group(group: TaskGroup) -> StageGroup:
             raise PlanReadError(_TASKS, MESSAGES.roadmap.plan_read_bad_task.format(text=first.text))
         if problems := _verification_problems(group, first):
             raise PlanReadError(_TASKS, " ".join(problems))
    -    if _kind(group.text, first) is GroupKind.BEHAVIOR:
    +    if group_kind(group) is GroupKind.BEHAVIOR:
             if len(group.tasks) < 2:
                 raise PlanReadError(_TASKS, MESSAGES.roadmap.plan_read_bad_task.format(text=first.text))
             second = _task(group, 1)
    diff --git a/tests/roadmap/test_roadmap_implement_job.py b/tests/roadmap/test_roadmap_implement_job.py
    index 8ea51196..1a7aab09 100644
    --- a/tests/roadmap/test_roadmap_implement_job.py
    +++ b/tests/roadmap/test_roadmap_implement_job.py
    @@ -45,6 +45,7 @@ from tests.support.roadmap_implement import (
         CHANGE,
         PULL,
         SHOUT,
    +    SHOUT_DOC,
         TASKS,
         TASKS_PATH,
         TICKED_FIRST,
    @@ -1649,3 +1650,110 @@ def test_a_default_tree_that_git_cannot_list_leaves_each_planned_item_out_and_en
             planned_world.number: True,
             second: True,
         }
    +
    +
    +# ── The premise of a behavior group at the branch tip (#3417) ─────────────────────────────
    +
    +GUARD_PATH = "src/devops_cli/roadmap/implement_run.py"
    +GUARD_SOURCE = (
    +    '"""The title of a delivery."""\n\n\n'
    +    "def _delivery_title() -> str:\n"
    +    '    return "fix(roadmap): the job drops a comment"\n'
    +)
    +PREMISE_TASKS = """\
    +# Tasks
    +
    +## 1. The first group
    +
    +Kind: behavior.
    +
    +Reads: `CONTEXT.md`. Changes: `tests/test_shout.py` (new), `src/devops_cli/shout.py` (new).
    +
    +- [ ] 1.1 Add the failing test `tests/test_shout.py` for `src/devops_cli/shout.py`
    +  - Verification: `uv run devops ci test tests/test_shout.py` fails on the base
    +- [ ] 1.2 Add the guard `_delivery_title` to `src/devops_cli/shout.py`
    +  - Verification: `uv run devops ci test tests/test_shout.py`
    +
    +## 2. The second group
    +
    +Reads: `CONTEXT.md`. Changes: `CONTEXT.md`.
    +
    +- [ ] 2.1 Document the function in `CONTEXT.md`
    +  - Verification: `uv run devops docs check`
    +
    +## Criteria
    +
    +- Group 1: The job keeps every comment.
    +"""
    +
    +
    +class TestThePremiseOfABehaviorGroup:
    +    """The job runs a behavior group whose guard the branch tip lacks (#3417)."""
    +
    +    @pytest.fixture
    +    def staged_tasks(self) -> str:
    +        return PREMISE_TASKS
    +
    +    @pytest.fixture
    +    def staged_files(self) -> dict[str, str]:
    +        return {"tests/conftest.py": '"""The tests."""\n'}
    +
    +    def test_a_behavior_group_whose_guard_the_base_lacks_runs(self, job_world: JobWorld) -> None:
    +        answer_pytest_on_base(job_world.programs, junit((SHOUT_TEST_ID, "failed")))
    +        first_ticked = PREMISE_TASKS.replace("- [ ] 1.", "- [x] 1.")
    +        all_ticked = first_ticked.replace("- [ ] 2.", "- [x] 2.")
    +        script = ModelScript(
    +            tool_calls(
    +                write_call("tests/test_shout.py", TEST_BODY),
    +                write_call("src/devops_cli/shout.py", GUARD_SOURCE),
    +                write_call(TASKS_PATH, first_ticked),
    +            ),
    +            say("Group 1 is done."),
    +            tool_calls(
    +                write_call("CONTEXT.md", SHOUT_DOC),
    +                write_call(TASKS_PATH, all_ticked),
    +            ),
    +            say("Group 2 is done."),
    +        )
    +
    +        applied = job_world.run(script)
    +
    +        assert (applied.ready, applied.stopped, applied.returned) == ((1,), (), ())
    +        assert "fix(roadmap): The first group (#1)" in job_world.origin_log()
    +
    +
    +class TestThePremiseOfABehaviorGroupTheBranchTipDefines:
    +    """The job returns the item when a behavior group adds a guard that the branch tip defines."""
    +
    +    @pytest.fixture
    +    def staged_tasks(self) -> str:
    +        return PREMISE_TASKS
    +
    +    @pytest.fixture
    +    def staged_files(self) -> dict[str, str]:
    +        return {GUARD_PATH: GUARD_SOURCE}
    +
    +    def test_a_behavior_group_that_adds_a_guard_the_base_already_runs_returns_the_item(
    +        self, job_world: JobWorld
    +    ) -> None:
    +        before_tip = job_world.repo.origin_git("rev-parse", BRANCH)
    +        script = ModelScript(say("Nothing to do."))
    +
    +        applied = job_world.run(script)
    +
    +        assert (applied.ready, applied.stopped, applied.failed, applied.returned) == (
    +            (),
    +            (),
    +            (),
    +            (1,),
    +        )
    +        assert script.seen == []
    +        status, record = _item(job_world)
    +        assert status == "New"
    +        assert record.get("implement.branch") is None
    +        assert record.get("implement.pr") is None
    +        (comment,) = job_world.issue_comments()
    +        assert f"{GUARD_PATH}:" in comment
    +        assert "def _delivery_title" in comment
    +        assert job_world.repo.origin_git("rev-parse", BRANCH) == before_tip
    +        assert job_world.repo.git("worktree", "list").count("\n") == 0

    The item is Blocked, and the job will not run it. Fix the cause. Then comment implement: retry. The Service clears the stop on its own when a new runner image rolls out, but only if a retry can fix the class of the stop and the limits of roadmap.implement.digest_clears_per_class and roadmap.implement.digest_clears_per_item allow it.

  12. added
    status/blocked
    and removed
    status/in-progress
    on Nov 5, 2026
  13. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261105-161718-1942 ended: succeeded.
    Image digest: sha256:b538e97e8c41f0ab07e396ade33cfe3e9f9f1ecd881a5b27b7e32e2c81e8ac7d

    The last lines of its log:

    Tool call: grep, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: grep, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: grep, ok.
    Tool call: read_file, ok.
    Tool call: grep, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: grep, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: grep, ok.
    Tool call: read_file, ok.
    Tool call: edit_file, ok.
    Tool call: edit_file, ok.
    Tool call: shell, started: uv run devops ci test tests/roadmap/test_roadmap_implement_job.py ...
    Tool call: shell, program uv, ok.
    Tool call: edit_file, ok.
    Tool call: shell, started: uv run devops ci test tests/roadmap/test_roadmap_implement_job.py ...
    Tool call: shell, program uv, ok.
    Tool call: edit_file, ok.
    Tool call: edit_file, ok.
    Tool call: edit_file, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: read_file, ok.
    Tool call: edit_file, ok.
    Tool call: edit_file, ok.
    Tool call: edit_file, ok.
    Tool call: edit_file, ok.
    Failure class limit_reached. Action left: raise_limit.
    ✓ Took 0 item(s) to a ready pull request, stopped 1.
    Elapsed: 29m 49s
    
  14. removed
    owner/service
    on Nov 5, 2026
  15. removed
    status/blocked
    on Nov 6, 2026
  16. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor
  17. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-06 06:16 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/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions