Skip to content

feat(roadmap): add the stage Job template and one-item entry point #5483

Closed

Description

@dan-petty

Problem or Motivation

This is part 1 of 2 of #4559 (Phase 1 of the roadmap pipeline split, owner approval of 2026-11-13). Stage runs in the roadmap Service pod. About 19 releases and ConfigMap edits a day restart that pod (Recreate). Since 2026-11-07, 53 of 71 restarts stopped a running stage round. On 2026-11-13 Prometheus showed 3 staged and 8 failed stage items in 24 hours (devops_cli_roadmap_stage_total).

Before the Service can submit stage Jobs (part 2, #4559), the cluster must admit a stage Job, and the stage command must run one item in a Job. This part adds that, with no change to the rows of the Service. A person can then run one stage Job by hand after the release, and the live run measures the GitHub requests of one cold-cache Job before part 2 ships.

Proposed Solution & Architectural Design

Manifests (Argo CD applies them before the image rolls, so the template, the policy and the Role rows land in this pull request):

  • k8s/devops/cronjob-stage.yaml: suspended CronJob roadmap-stage, in the form of cronjob-runner.yaml. Image ghcr.io/dan-petty/devops-cli/service (the Image Updater kustomize override sets its digest, as for cronjob.yaml). Container stage, args ["--version"]. ServiceAccount devops-cli, automountServiceAccountToken: false. No envFrom. secretKeyRef of Secret devops-cli for 3 keys only: DEVOPS_CLI_SERVICE_GITHUB_APP_PRIVATE_KEY, DEVOPS_CLI_AI_API_KEY, DEVOPS_CLI_MCP_STAGE_TOKEN (all 3 exist in the live Secret on 2026-11-13, so no new Secret key is needed before the roll). OTEL_SERVICE_NAME=roadmap-stage, OTEL_RESOURCE_ATTRIBUTES=service.instance.id=roadmap-stage (fix(telemetry): keep one metric stream per workload #4697). Pod labels app.kubernetes.io/name: devops-cli-job and app.kubernetes.io/component: roadmap-stage. emptyDir home and /tmp, ConfigMap devops-cli-config. Requests 250m and 1Gi, limits 1 CPU and 2Gi (the Service pod peaked at 1.46 GiB in 7 days with every row). activeDeadlineSeconds: 10800, backoffLimit: 2, podFailurePolicy: Ignore on DisruptionTarget, FailJob on exit codes NotIn [75]. Exit 75 is the evicted exit of attempt_kill.py (fix(roadmap): a named fix-plan run can skip the 6-hour wait #5413), so an eviction or a drain runs the pod again and a real failure does not.
  • k8s/devops/roadmap-service/admissionpolicy.yaml: a branch on the name prefix devops-cli-stage-. A stage Job may use the Service image, valueFrom.secretKeyRef of the 3 keys of Secret devops-cli and no other valueFrom, backoffLimit: 2 only with the podFailurePolicy above, and the stage resources. A runner Job keeps every current rule (runner image, envFrom, backoffLimit: 0, the size table). A new policy, or a new validation set, admits DELETE of a Job by roadmap-service only when oldObject is a stage Job.
  • k8s/devops/roadmap-service/role.yaml: get on CronJob roadmap-stage, delete on jobs.
  • k8s/devops/searxng/networkpolicy-client.yaml and searxng/networkpolicy.yaml: the stage planner has the web_search tool, and today no policy lets a Job pod reach SearXNG on TCP 8080. Admit the pods with app.kubernetes.io/component: roadmap-stage. The MCP server policy already admits devops-cli-job pods.

Code:

  • src/devops_cli/k8s/cluster_job.py: a STAGE_TEMPLATE (roadmap-stage, container stage) and TemplateName.STAGE, so devops k8s run-job --template stage works. The stage Job name is RepoRef.unit_name(ServiceRow.STAGE, <plan key>, item) (ADR 0022, at most 63 characters, the same inputs give the same name, so a second create gets 409). The labels are roadmap.devops-cli/owner, roadmap.devops-cli/repo (RepoRef.owner_label, RepoRef.repo_label), roadmap.devops-cli/item and the component. src/devops_cli/k8s/cluster_job_api.py: ClusterJobs.delete_job (propagation Background; 404 is no error).
  • devops roadmap stage --job-item <n>: the normal selection narrowed to item n, with every rule (named=False: the rejected-plan rule, the failure wait, the recorded split, the queue limit). --item stays for a person and keeps its overrides. The two options together are refused. The option reads and writes only item n: its rejection, its orphan and its result.
  • The Job entry point (the --job-item path): network.set_model_call_limit(1) before the first model call; sigterm_raises() around the plan (fix(roadmap): a named fix-plan run can skip the 6-hour wait #5413); a TimeBudget of the new setting roadmap.stage.time_budget_seconds, cut to the Job deadline that the Service passes as a plain env value, less a margin for one more model run and the publish (tool < step < Job deadline). Exit 0 for a result, 1 for a failure, 75 for evicted, 143 for deadline.
  • Check-in: new StageRecordKey values stage.job, stage.job_at, stage.job_deadline (the check-out that part 2 writes) and stage.job_result. At its end the Job writes stage.job_result and clears the check-out marks in one write, only when stage.job names its own Job (plain env value DEVOPS_CLI_ROADMAP_STAGE_JOB). An evicted kill keeps the check-out, because the Job controller runs the pod again. A deadline kill records the class and checks in.
  • A pod that runs again in the same Job and finds its own stage.pending mark (the check-out names its Job) judges that mark an orphan at once, removes the branch, and plans the item again in the same run. The 3600 s age rule stays for every other mark.
  • A request budget for the pod: the entry point makes a RequestBudget (src/devops_cli/server/service.py) with no record and the new setting roadmap.stage.github_requests_per_hour, and installs it with set_request_gate, as the Service does. So every GitHub request of the stage Job counts in a budget (exit check of Phase 1 in feat(roadmap): track the roadmap pipeline split into jobs #5482). The shared budget in Valkey (feat(service): share the GitHub budget and holds in Valkey #4563) replaces it later.
  • ensure_checkout gets a blobless clone (git clone --filter=blob:none, ADR 0021 section 6) for the Job clone.
  • The stage Job calls plan_stage and StageWriter, the code that the Service uses today, and holds no push or rebase code of its own. The shared push and open steps (fix(roadmap): the final push of the implement Job can miss the latest main #4957, refactor(roadmap): one open step for every pull request #5020) replace code inside StageWriter later, and the Job gets them with no change.
  • The planner run tool of feat(k8s): manifest and admission policy for planner sandboxed run job #4003 and feat(roadmap): wire sandboxed run tool into stage toolbox and prompt #4098 stays off in a stage Job: stage_run_allowlist.py is imported by no module on 2026-11-13, so no wiring exists to turn off. A later item adds a narrow Role for the run Job template.

Tracker #5482, Phase 1: this item is the stage template (this issue) and the Job side of the stage step (folded into #5499 and #4559 part 2), with the stage part of #5498 (the 3 named keys and the repository token of DEVOPS_CLI_SERVICE_GITHUB_APP_TOKEN_REPOSITORY) and of #5497. The Job runs the plan and publish code of today, so it does not wait for #4957, #5020, #5026 or the scaffold step. Those steps change code inside StageWriter later. A kill replans the item until the plan record moves to Valkey (#4564).

Overlap: #4558 (labels of the runner Job in cluster_job.py; this part labels only the stage Job, with the same RepoRef builders), #5440 (settings of roadmap.stage).

Target Subsystem

SDLC, Git & PR Governance (src/devops_cli/roadmap/stage/, src/devops_cli/k8s/cluster_job.py, src/devops_cli/commands/roadmap.py, k8s/devops/).

Existing Tool Considered

Kubernetes Jobs, podFailurePolicy (GA since Kubernetes 1.31; the cluster runs v1.37.2+k3s1), ValidatingAdmissionPolicy (GA since 1.30), the runner Job pattern of #2667 and attempt_kill.py of #5413. No other tool. Cost: about 120,000 tokens and 4 hours to build, about 5,000 tokens a month to keep, about 20,000 tokens to fix.

Acceptance Criteria

Tests first (each fails before the change):

  • A gate test reads k8s/devops/cronjob-stage.yaml and finds the Service image, ServiceAccount devops-cli, no token, the 3 named secret keys and no envFrom, the resources, activeDeadlineSeconds: 10800, backoffLimit: 2 and the podFailurePolicy.
  • The CEL test of the admission policy admits the stage Job that build_job makes from the template, and refuses each variant: the runner image, envFrom, a 4th key or another Secret in secretKeyRef, a fieldRef, a token mount, another ServiceAccount, backoffLimit: 2 with no podFailurePolicy, a deadline above 14400. It refuses a runner Job with backoffLimit: 2. It admits the DELETE of a stage Job and refuses the DELETE of a runner Job.
  • A test reads role.yaml and finds get on CronJob roadmap-stage and delete on jobs.
  • A network policy test admits a stage Job pod to SearXNG on TCP 8080 and still refuses a runner Job pod.
  • A test builds the stage Job: the args go to container stage, the Job and the pod have the component, owner, repo and item labels, the name has at most 63 characters, and the same item and plan key give the same name.
  • --job-item leaves out an item with a rejected plan and an item in its failure wait, each with the reason of the normal selection. --item still overrules them.
  • With a fake client, the entry point holds one model call slot and starts no second call.
  • SIGTERM before the time budget ends exits 75 and keeps the check-out; after the budget exits 143 and records deadline; a normal end writes stage.job_result and clears the check-out only when stage.job names the Job.
  • A pod that runs again with its own stage.pending mark and a pushed branch removes the branch and stages the item in the same run.
  • The entry point installs a request gate whose limit is roadmap.stage.github_requests_per_hour, and a request past the limit waits.
  • A structural test finds no direct git push or git rebase call in the entry point module.

Live proof after the release (real calls against the cluster and GitHub):

  • uv run devops k8s run-job --template stage -- roadmap stage --repo dan-petty/devops-cli --job-item <n> --confirm on a real Ready item opens the draft pull request. A kubectl -n devops rollout restart deploy/roadmap-service during the Job does not stop it.
  • The GitHub requests of that cold-cache Job (devops_cli_github_requests_total{job="roadmap-stage"}) are measured and stated in a comment on feat(roadmap): run each stage item in its own Job #4559, against the 3,357 requests a day of the stage row.
  • kubectl -n devops get jobs -l app.kubernetes.io/component=roadmap-stage,roadmap.devops-cli/item=<n> lists the Job.

Source: #4559

Activity

  1. added
    source/agent
    on Nov 13, 2026
  2. added
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 13, 2026
  3. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 13, 2026
  5. added
    status/in-review
    and removed
    status/in-progress
    on Nov 13, 2026
  6. removed
    status/in-review
    owner/agent
    on Nov 13, 2026
  7. devops-cli-service commented on Nov 13, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-13 20:55 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