Skip to content

fix(roadmap): implement starts while the plan is still changing #8001

Done

Description

@dan-petty

Problem Description

The implement row can start a Job for an item while a stage Job for the same item still runs. The stage Job then pushes a new head to the plan pull request, the Plan Check starts again, and the implement Job leaves its item out. The Service records that Job as a stop of class ci_infra for "a Job that ended without a result". It counts a failed attempt and spends one of the 4 continuations of the item.

Reproduction Steps

Observed on 2026-12-01 for item #7970 and plan pull request #7997 (times in UTC).

  1. 01:50:19 the stage row creates Job devops-cli-stage-devops-cli-7970-d4aef7f857. It ends at 02:02:03.
  2. 01:59:47 the implement row creates Job devops-cli-implement-devops-cli-7970-6aea75.
  3. 02:01:34 devops-cli-service[bot] force-pushes the plan branch, from 89fe83557 to c52047a80.
  4. The prepare phase of the implement Job reports: "The run left item fix(ci): DevContainer Image averages over the 360 s limit #7970 out: The check Plan Check of its plan pull request still runs." Each container exits 0.
  5. 02:09:44 the Service records result=stopped class=ci_infra tokens=0 seconds=213. At 02:10 it clears the stop by the rule continue ("continuation 1 of 4") and creates a second Job.

Expected vs Actual Behavior

Expected: the implement row starts no Job for an item with an active stage Job, and a Job that leaves its item out records no stop and spends no continuation.

Actual: one Job of about 3 minutes is lost, the success metrics count a failure, and the item has one continuation less. After 4 such cases the item stays Blocked.

Environment Diagnostics

Service v0.266.0, runner v0.265.4, repository dan-petty/devops-cli.

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Source

Source: #7997

Alternatives check of 2026-12-01: rejected.
Rejected by ADR 0021. A newer fact can change an ADR.
Tool: Kubernetes Lease (https://github.com/kubernetes/kubernetes), Apache-2.0, last activity 2026-11-27, maintained.
Reason: Searches found no library for per-item exclusion between two Job templates. A Kubernetes Lease covers only the lock part, and ADR 0021 rejects it; the skip result and continuation rules stay project code.

Covers:

  • Per-item named lock with holder identity and expiry
  • Lock records read through the existing Kubernetes client
  • Exclusion between the stage row and the implement row

Lacks:

  • No rule maps the Job labels to a per-item lock
  • No skipped result and no continuation accounting
  • Each renewal is an API write and needs a pod token

Proposed design

Problem statement

The implement row can start a Job for an item while a stage Job for the same item runs. The stage Job pushes a new head, the Plan Check starts again, and the implement Job leaves its item out. The Service records a ci_infra stop, counts a failed attempt, and spends one continuation. The same wrong stop occurs when the plan pull request waits for a merge. The change makes the implement round skip an item with a running stage Job. It also writes a skipped result for a Job that leaves its item out, so the Service records no stop and spends no continuation.

Acceptance criteria

Requirement: Running stage Job blocks the implement round

The implement round SHALL create no implement Job for an item that a running stage Job works on.

Scenario: Item with a running stage Job

Requirement: Free item still starts

The implement round SHALL create an implement Job for a free Staged or Planned item when another item has a running stage Job.

Scenario: Free item beside a busy item

  • WHEN The stage Job list names a running stage Job for one item, and another Staged item is free.
  • THEN The round creates one implement Job, and the item of that Job is the free item.

Requirement: Publish writes the skip result

The publish phase SHALL record implement.result as skipped when the run state names a left-out reason.

Scenario: Left-out state at publish

  • WHEN The state file of the run says that the run ended, and it names a left-out reason, such as a pending Plan Check or a plan that waits for a merge.
  • THEN The item records implement.result as skipped, and it records no implement.stopped.

Requirement: Skip result records no stop

The implement report SHALL record no stop for a Job whose item records implement.result as skipped.

Scenario: Job with the skip result

  • WHEN An implement Job ended, and its item records implement.result as skipped.
  • THEN The report records implement.job_state as succeeded, and it writes no implement.stopped and no implement.failure.

Requirement: Skip spends no continuation

The Service SHALL count a Job that records implement.result as skipped as no failed attempt and no continuation.

Scenario: Skip result in the counters

  • WHEN The report runs for an implement Job whose item records implement.result as skipped.
  • THEN The counter devops_cli_service_implement_failures_total takes no increment, and implement.continuations keeps its value.

Requirement: Skip leaves the item selectable

The implement round SHALL select the item again when its stage Job ended and its Plan Check passed.

Scenario: Item after the skip

  • WHEN The item records implement.result as skipped and no stop, and the stage Job list names no running Job for it, and its Plan Check passed.
  • THEN The next selection returns the item as an implement target.

Existing Tool Considered

Kubernetes Lease (https://github.com/kubernetes/kubernetes), Apache-2.0, maintained. The alternatives check in the issue body records the verdict rejected. ADR 0021 rejects a Lease for each lock, and the check found no library for per-item exclusion between two Job templates. The block lists what the tool covers and lacks. The proposal maps the stage Job labels to the item in the implement round, and it adds the skipped result and the continuation rule in project code. Estimated cost: about 20,000 tokens to build, 10,000 to keep, 10,000 to fix, and about 2 days.

Key questions

  • How does the implement round know that an item has a running stage Job?: The round lists the stage Jobs with stage_jobs_selector(). It takes the running Jobs of its repository by the owner and repository labels. It passes the item-to-Job map to plan_implement, and the plan leaves each busy item out with a reason that names the stage Job. (best practice) [sources: docs/CLUSTER.md:106, src/devops_cli/roadmap/stage/stage_submit.py:296, src/devops_cli/roadmap/implement/implement_submit.py:28, src/devops_cli/k8s/cluster_job.py:162, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md:63]
    • Chosen: Read the stage Job list. The stage row uses the same list as the lock, and the Job labels name the item, the owner and the repository.
    • Rejected: Read the check runs of the plan pull request in the round. The round reads a head that the stage Job has not pushed yet, so it cannot see the new head.
    • Rejected: Use a Kubernetes Lease for each item. ADR 0021 rejects a Lease for each lock, because each renewal is an API write and agent pods hold no API token.
    • Rejected: Use the item status label. No status label names a running stage Job.
  • How does a left-out implement Job report that it did no work?: The publish phase reads a state that ended with a left-out reason. It writes implement.result as skipped and exits 0. The report treats skipped as no stop, so it writes no implement.stopped and spends no continuation. (best practice) [sources: src/devops_cli/roadmap/implement/implement_phases.py:1036, src/devops_cli/roadmap/implement/implement_submit.py:157, src/devops_cli/roadmap/stores/store.py:421, src/devops_cli/roadmap/stores/store.py:451, src/devops_cli/roadmap/implement/implement_submit.py:221]
    • Chosen: Add the result skipped and write it in publish. The enum holds the ends of a run, publish is the last phase, and the Service decides a stop by the result value.
    • Rejected: Write the result in prepare. The record says that implement.result is the last mark of the end, and publish is the last phase.
    • Rejected: Reuse the result yielded. yielded means that an agent or a person claimed the item, so the record would name the wrong cause.
    • Rejected: Exit 75. The Service reads no exit status of an implement Job as a skip; it reads implement.result.
    • Rejected: Record a stop of class head_moved. A stop still counts a failed attempt and can spend a continuation.
  • Which left-out reasons write the skip result?: Every left-out reason writes skipped. The prepare phase judges the item again at the next round, so a persistent reason leaves the item out before it starts a Job. A plan pull request that waits for a merge is one such reason. (best practice) [sources: src/devops_cli/commands/roadmap_jobs.py:1033, src/devops_cli/roadmap/implement/implement.py:341, src/devops_cli/roadmap/implement/implement.py:495]
    • Chosen: Every left-out reason. The next round judges the item again, so a persistent reason starts no Job.
    • Rejected: Only a check that still runs. The reason is a message, not a value, and the other transient reasons keep the wrong stop.
    • Rejected: Only a reason that names a check. A check that cannot be read or that was cancelled also leaves the item out, and the Job did no work in each case.
  • Which check decides that the Plan Check still runs?: The prepare phase calls _pull_reason. It reads the check runs of the head of the plan pull request with read_check_runs. A check in bucket CheckBucket.PENDING gives implement_left_check_running, and the message names the check. In the reproduction the pending check is Plan Check. [sources: src/devops_cli/roadmap/implement/implement.py:547, src/devops_cli/roadmap/implement/implement.py:565, src/devops_cli/lang/en/messages.py:4008, .github/workflows/pr-checks.yml:132, tests/roadmap/implement/test_roadmap_implement_selection.py:883]
  • Which labels identify the stage Job of one item?: The stage Job carries the component, part-of, managed-by, owner, repository and item labels. stage_job_labels writes them, and stage_jobs_selector selects the Jobs by the component label. The round takes the Jobs of its repository by the owner and repository labels. [sources: src/devops_cli/k8s/cluster_job.py:149, src/devops_cli/k8s/cluster_job.py:162, src/devops_cli/roadmap/stage/stage_submit.py:296, docs/CLUSTER.md:106]
  • Which rule records a stop when an implement Job ends with no result?: _settles_as_stop returns true for an open item that is In Progress, or Ready or Planned with no stop. _report then sets Blocked and records implement.stopped as job. The clear rule continue spends one continuation when the class has the action retry. [sources: src/devops_cli/roadmap/implement/implement_submit.py:221, src/devops_cli/roadmap/implement/implement_submit.py:341, docs/CLUSTER.md:57]
  • Which tests cover the implement round, the phases and the stage Job list?: tests/roadmap/implement/test_roadmap_implement_submit.py covers the round and the report. tests/roadmap/implement/test_roadmap_implement_selection.py covers the selection. tests/roadmap/implement/test_roadmap_implement_phases.py covers the phases. tests/roadmap/stage/test_roadmap_stage_submit.py covers the stage Job list. [sources: tests/roadmap/implement/test_roadmap_implement_submit.py, tests/roadmap/implement/test_roadmap_implement_selection.py, tests/roadmap/implement/test_roadmap_implement_phases.py, tests/roadmap/stage/test_roadmap_stage_submit.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
    • Priority: The race wastes continuations and can block an item after four occurrences, increasing error rates without a hard CI failure.
    • Related: fix(roadmap): implement refuses items with failing plan checks #3976, which asks for a different change. Both stop the implement job from starting when the plan is not ready, but #3976 checks for already-failed checks while the candidate checks for an active stage Job running concurrently.
  3. added
    priority/p1-high
    on Dec 1, 2026
  4. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. dan-petty commented on Dec 1, 2026

    @dan-petty
    OwnerAuthor

    Second case, 2026-12-01 (UTC), with another reason for the same result, item dan-petty/danielpetty.com#149 and plan pull request #154:

    1. 03:33:59 the Service marks fix(security): remediate session 20260911-060650 findings and enhance review self-improvement loop #154 ready for review.
    2. 03:34:27 the implement row creates Job devops-cli-implement-danielpetty-com-149-ee87c1.
    3. The prepare phase reports: "Its plan pull request fix(security): remediate session 20260911-060650 findings and enhance review self-improvement loop #154 is ready for review and awaiting merge." The Job ends at 03:35:09, and each container exits 0.
    4. The Service records class=ci_infra tokens=0 seconds=42 (runner v0.268.2).

    So a Job that leaves its item out is recorded as an infrastructure stop for more than one reason of the left-out list. While a plan waits for a merge, each such Job can spend one continuation.

  6. added
    owner/agent
    on Dec 1, 2026
  7. devops-cli-service commented on Dec 1, 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 (9)

    Tools considered:

    Searches run:

    • open source job scheduler skip result does not count failed attempt retry budget, results: 5
    • Kubernetes prevent duplicate Job for same item distributed lock library, results: 5
    • kubernetes lease mutex per resource name prevent concurrent jobs python client, results: 5
    • github actions check runs pending wait for check before starting job library, results: 5
    • kueue kubernetes job queue admission prevent duplicate concurrent workloads, results: 5
    • kubernetes documentation Jobs label selector list running jobs by label, results: 5
    • python distributed lock library kubernetes lease github, results: 5
    • Kubernetes Lease coordination k8s.io API reference documentation, results: 5
    • kubernetes python client CoordinationV1Api Lease create replace, results: 5

    Sources:

  8. added
    status/ready
    and removed
    status/new
    on Dec 1, 2026
  9. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

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

  10. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Dec 1, 2026
  11. removed
    status/in-review
    owner/agent
    on Dec 1, 2026
  12. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Live since 2026-12-01 12:40 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/p1-highscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions