Skip to content

feat(roadmap): add the three-container runner Job, policy and log reads #3700

Closed
3 of 3 issues completed

Description

@dan-petty

Problem

The runner Job template (k8s/devops/cronjob-runner.yaml) has one container, runner, with the App private key and the model key. #3702 adds the phases prepare, agent and publish, but this template runs them as --phase all in one container. So the App key and the agent still share one process tree (#2695).

Three parts stop a three-container Job now:

  • The admission policy (k8s/devops/roadmap-service/admissionpolicy.yaml) refuses each init container. Its per-container rules read only spec.containers.
  • The Service reads the Job log and the end of the pod with no container name (log_tail and pod_end in src/devops_cli/k8s/cluster_job_api.py). During the agent phase, that read fails. So the deadline does not extend, and the Job stops at the first deadline.
  • build_job and template_container (src/devops_cli/k8s/cluster_job.py) look only for the container runner.

Expected

The CronJob devops-cli-runner runs three containers, one after the other:

Container Kind Secret key Volumes
prepare initContainers[0] App private key run at /run/roadmap (read-write), state at /run/roadmap/state (read-write), its own prepare-tmp at /tmp and prepare-home, config (read-only)
agent initContainers[1] DEVOPS_CLI_AI_API_KEY run at /run/roadmap (read-write), its own agent-tmp at /tmp and agent-home, config (read-only); no state
publish containers[0] App private key run and state (read-only), its own publish-tmp at /tmp and publish-home, config (read-only)

The run root /run/roadmap holds state/, work/ and out/ (RunFolders). out/ cannot be a mount point of its own, because make_out refuses an out/ that is there before the outputs (src/devops_cli/roadmap/phases/files.py). prepare records the absolute path of the clone, so prepare and agent mount run at the same path. So state is a second volume on top of the run root, which agent does not mount.

Each container starts with args and its --phase. The pod keeps restartPolicy: Never, activeDeadlineSeconds, uid 1000, readOnlyRootFilesystem, drop ALL and no ServiceAccount token. The agent container takes a row of RUNNER_SIZES. prepare and publish take one small fixed row. Kubernetes sizes the pod by the largest init container or by the sum of the app containers, so the small rows add no capacity.

The policy admits only this layout, and it pins the keys and the mounts per container. The Service and devops k8s run-job read each container by its name.

Acceptance criteria

Service readers

  • log_tail takes a container name. The deadline extension (implement_deadline.py) reads the container that runs: prepare, then agent, then publish. A test shows that a log change in the container agent extends the deadline.
  • pod_end reads initContainerStatuses before containerStatuses. So an OOM kill of agent keeps the class oom.
  • Each other reader of the Job log or of a container status reads by container name. These readers are _outcome of fix_checks_row, _report of implement_submit, stage_submit and follow_live. The Service reads the count line of feat(roadmap): run implement and fix-checks as prepare/agent/publish phases #3702 from the container agent.
  • devops k8s run-job follows each container in turn, and reads the exit status of each container by its name.
  • build_job and template_container accept the old one-container template and the new template. build_job sets the args, the env and the size per container. The three containers get the same TRACEPARENT.
  • The readers are in a Service release before the cluster gets the new template. The PR states how it keeps this order. If one PR cannot keep the order, the template change moves to a new item that waits for that release.

Template

  • The CronJob has the init containers prepare and agent and the container publish, with the volumes and the keys of the table.

Admission policy

  • One CEL variable holds containers and initContainers. Each per-container rule uses it: the image, envFrom, valueFrom, command and the sizes.
  • The policy admits a runner Job only with the init containers [prepare, agent] and the containers [publish].
  • The App key secretKeyRef is allowed only on prepare and publish. DEVOPS_CLI_AI_API_KEY is allowed only on agent.
  • The policy refuses shareProcessNamespace: true. It refuses restartPolicy and restartPolicyRules on each container, init containers included. A restarted publish pushes and comments twice, and a native sidecar runs at the same time as publish.
  • agent does not mount state or a home of prepare or publish. publish mounts run and state read-only.
  • On UPDATE, the policy also admits the old one-container shape during the switch. The Service patches the deadline of a Job that runs.
  • The cluster gets the policy before the template, for example through an Argo CD sync wave.
  • tests/gate/k8s_checks/job_admission_policy.py has a case for each new refusal:
    • a key on the wrong container
    • state in agent
    • shareProcessNamespace: true
    • a restartPolicy on an init container and on the app container
    • a third init container
    • an init container with another image or with command

Live check and documents

  • One live implement Job and one live fix-checks Job run the three phases. The PR gives the result.
  • The bullets Template, Admission policy and Guarantees of k8s/README.md state the new layout. The Guarantees bullet states what the containers share: the network, the IPC namespace and the kernel.

Existing tool considered

Kubernetes gives the order and a Secret per container through init containers. A ValidatingAdmissionPolicy with CEL pins the layout. This item builds nothing new for these.

Order

Merge this item only after a runner image release holds #3702, because the new template runs --phase. Key question 1 of #2695 (where the implement Job ends) needs an answer before this item makes the split live.

Dependencies

Related

Source: #2695

Alternatives check of 2026-11-18: none.
Tool: none found.
Reason: Searches found no open tool for the two-container layout or the safe import; the parent's alternatives check names kubernetes-sigs/agent-sandbox for #3694's command server only, with no Job template, admission policy or import.

Proposed design

Problem statement

The runner CronJob still runs prepare, agent and publish in one container, so the App private key and the agent share one process tree. The Service readers read the Job log with no container name, so the deadline does not extend during the agent phase. This change makes the Service readers and the Job builder ready for three containers. The template switch, the admission policy, the live check and the documents move to a deferred issue that waits for a Service release with these readers and a runner image release that holds #3702. The interim git controls move to a second deferred issue.

Acceptance criteria

Requirement: Container-aware log tail

log_tail SHALL accept a container name and SHALL request the log of that container only.

Scenario: Agent log read

  • WHEN The unit test calls log_tail with the container name agent and a fake Kubernetes client.
  • THEN The test asserts that the client request names agent and returns the log of that container.

Requirement: Deadline follows the running container

The deadline extension in implement_deadline.py SHALL read the log of the container that runs: prepare, then agent, then publish.

Scenario: Agent log change extends the deadline

  • WHEN The deadline test gives pod status with agent running and a changed agent log.
  • THEN The test asserts that the deadline extends from the agent log and not from a pod log read with no container name.

Requirement: Pod end reads init statuses first

pod_end MUST read initContainerStatuses before containerStatuses.

Scenario: Agent OOM keeps class oom

  • WHEN The pod status test sets an OOM kill in initContainerStatuses for agent and a running publish in containerStatuses.
  • THEN The test asserts that pod_end returns the agent exit status 137 with the reason OOMKilled, and the failure class is oom.

Requirement: Readers name their container

Each reader of the Job log or of a container status SHALL pass a container name.

Scenario: Readers pass the agent name

  • WHEN The unit tests run _outcome of fix_checks_row, _log_of and _pod_end_of of implement_submit, _failure_of and _recover of stage_submit, and live_lines of follow_live against a pod whose init container agent runs.
  • THEN The tests assert that each reader requests the agent log or status by name.

Requirement: Count line comes from agent

The Service SHALL read the count line of #3702 from the container agent.

Scenario: Agent count line wins

  • WHEN The unit test gives an agent log with the count line and a publish log with a different count.
  • THEN The test asserts that the Service reads the count line from agent.

Requirement: run-job follows each container

devops k8s run-job SHALL follow each container in turn and SHALL read the exit status of each container by its name.

Scenario: run-job reads three exit statuses

  • WHEN The run-job test builds a Job with prepare, agent and publish and runs the follow loop.
  • THEN The test asserts that the loop follows the three names in order and reads each exit status by name.

Requirement: Job builder keeps the one-container template

build_job and template_container SHALL accept the one-container runner template.

Scenario: Old runner template builds

  • WHEN The cluster_job test builds a Job from the current one-container CronJob template.
  • THEN The test asserts that template_container returns the container runner and that build_job sets its args, env and size.

Requirement: Template container selects by name

template_container SHALL take a container name and SHALL return the container with that name from the Job template.

Scenario: Agent container is selected

  • WHEN The cluster_job test calls template_container with the name agent on a three-container fixture.
  • THEN The test asserts that the returned container has the name agent.

Requirement: Job builder sets each of three containers

build_job SHALL set the args, the env and the size of each named container and SHALL give the three containers the same TRACEPARENT.

Scenario: Three containers get one trace parent

  • WHEN The cluster_job test builds a Job from a three-container template fixture.
  • THEN The test asserts that each named container gets its args, env and size and that all three containers get the same TRACEPARENT.

Existing Tool Considered

The alternatives check of 2026-11-18 in the issue body records the verdict none: it found no third-party tool for the two-container layout or the safe import. The open, maintained tools that cover this need are Kubernetes itself (Apache-2.0, maintained) and its Python client kubernetes-client/python (Apache-2.0, maintained): init containers run in order before the app container, a ValidatingAdmissionPolicy with CEL pins the pod layout, and read_namespaced_pod_log reads one container by name. They lack the project's three-container template, the per-container policy rules and the container-aware Service readers, which this change writes. The written cost from the design in #2695 is about 30k to 60k tokens to build, 10k to 20k tokens a year to keep and fix, and 2 engineer-days.

Key questions

  • How does the Service read the log of the container that runs?: Add a required container parameter to log_tail and pass the running container name from the pod status. implement_deadline reads prepare, then agent, then publish. The Kubernetes Python client's read_namespaced_pod_log takes the container name, and read_pod_log_text already forwards keyword arguments to it. (best practice) [sources: src/devops_cli/k8s/cluster_job_api.py:290, src/devops_cli/k8s/service.py:97, src/devops_cli/roadmap/implement/implement_deadline.py:73, src/devops_cli/roadmap/implement/implement_deadline.py:77]
    • Chosen: Pass the container name from the pod status. The Kubernetes log API reads one container by name, and the pod status names the running container.
    • Rejected: Read the pod log with no container name. A multi-container pod refuses a log read with no container name.
    • Rejected: Always read the container agent. The prepare and publish phases then get no deadline extension.
  • Which container order does the three-container template use?: prepare is initContainers[0], agent is initContainers[1], and publish is containers[0]. The ADR records that the three phases run one after the other, and Kubernetes runs init containers in order before the app container. (best practice) [sources: docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md:23, docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md:29, k8s/devops/cronjob-runner.yaml:41, k8s/devops/roadmap-service/admissionpolicy.yaml:61]
    • Chosen: Two init containers and one app container. Kubernetes runs init containers in order before the app container, so the phases run one after the other.
    • Rejected: Three app containers. App containers run at the same time, so the phases would overlap.
    • Rejected: One container with --phase all. The App key and the agent then share one process tree, which is the problem.
  • How does build_job set values per container?: template_container takes a container name and returns that container from containers or initContainers. build_job sets args, env and size on each named container and copies the same TRACEPARENT to all three. (best practice) [sources: src/devops_cli/k8s/cluster_job.py:206, src/devops_cli/k8s/cluster_job.py:228, k8s/devops/cronjob-runner.yaml:51]
    • Chosen: Change each container by name. The command has a value for each phase, and the old one-container template still works.
    • Rejected: Change only the container runner. The new template has no runner container, so the command would change nothing.
    • Rejected: Change every container the same way. The three phases need different args and sizes.
  • Should the template change ship in the same pull request as the Service readers?: No. Defer the template, the admission policy, the gate tests, the live check and the documents to a new issue. That issue waits for a Service release with these readers and a runner image release that holds feat(roadmap): run implement and fix-checks as prepare/agent/publish phases #3702. (best practice) [sources: k8s/devops/cronjob-runner.yaml:25, src/devops_cli/k8s/cluster_job_api.py:290, docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md:29]
    • Chosen: Defer the template and policy. Argo CD applies the template at the merge commit, before the Service release that holds the readers, so the old readers would fail during the agent phase.
    • Rejected: Ship both in one pull request. The pull request cannot order the Service release before the manifest sync.
  • Which interim git controls does the owner remove after this item?: Delete OriginGit and its ref copying. Delete the git argument parser of _github_pin, but keep the in-process mint and renewal of the token. Delete the process sweeps and adopt_orphans, the private GH_CONFIG_DIR, the origin URL pin, and the symlink stop of implement_step.py and its tests. Do this in one PR after the agent runs in its own container. The ADR records that no new git hardening comes before feat(roadmap): add the three-container runner Job, policy and log reads #3700. (best practice) [sources: src/devops_cli/roadmap/implement/git_isolation.py, src/devops_cli/core/process.py:616, src/devops_cli/core/process_hardening.py:80, src/devops_cli/roadmap/implement/implement_step.py, docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md:33]
    • Chosen: Delete after the three-container template is live. The controls protect nothing when the agent has no App key, no token and no mount of the state folder.
    • Rejected: Delete now. The agent still shares a container with the state folder and the App key in the current template.
  • Does this item depend on feat(roadmap): run implement and fix-checks as prepare/agent/publish phases #3702?: Yes. The ADR records that the implement Job follows feat(roadmap): run implement and fix-checks as prepare/agent/publish phases #3702 part C and that feat(roadmap): add the three-container runner Job, policy and log reads #3700 runs each phase in its own container, and the owner decision of 2026-11-21 puts this item directly after feat(roadmap): run implement and fix-checks as prepare/agent/publish phases #3702 part C. Keep feat(roadmap): run implement and fix-checks as prepare/agent/publish phases #3702 as the dependency. [sources: docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md:29, docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md:33, docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md:49]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#3702

Sub-issues

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added
    source/agent
    on Nov 5, 2026
  2. added
    type/feature
    scope/roadmap
    status/new
    value/high
    effort/high
    on Nov 5, 2026
  3. dan-petty commented on Nov 5, 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 closes a named security gap (#2695) but is a planned feature, not an active exploit or outage.
    • Value: High. It separates the agent shell from the session token, removing a direct token-exposure path for every implement run.
    • Effort: High. It requires a new container, a file-import function, admission-policy edits, real-UID tests, and resolution of four open points.
    • Related: feat(k8s): an admission policy pins the Jobs the roadmap Service may create #2696, which asks for a different change. Both touch the admission policy for runner Jobs, but #2696 created the policy while this item modifies it to admit a two-container layout.
  4. added
    priority/p2-medium
    on Nov 5, 2026
  5. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 72c52c6 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

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

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches returned nothing relevant to a safe import of files from one container's directory into another container's checkout, and the only tool the issue names as considered, vstorm-co/pydantic-ai-backend, is a sandbox-backend library with no artifact import, so it covers neither the import nor the two-container pod layout. The boundary itself comes from Kubernetes primitives (a second container, runAsUser, a shared emptyDir with per-directory modes, and a ValidatingAdmissionPolicy), which are wiring the project must write, not an open tool that covers the need.

    Tool: none found

    Lacks:

    • an import of the shell container's working files into the job's checkout as untrusted input
    • refusal of symbolic links without following them, and refusal of paths outside the step's StageGroup paths
    • a two-container runner Job with per-directory ownership/modes that deny the shell user the job directory
    • admission-policy rules that admit the two-container Job and refuse a third container, an init container, a shared process namespace or a shell container with secrets
    • any maintained library for copying files between containers of one pod with symlink and containment checks

    Tools considered:

    Searches run:

    • kubernetes sidecar container share emptyDir copy files to main container securely, results: 5
    • open source tool copy untrusted files from sandbox directory into checkout refusing symlinks path traversal, results: 5
    • kubernetes-sigs agent-sandbox Sandbox custom resource controller, results: 5
    • pydantic-ai-backend sandbox filesystem artifact import, results: 5
    • github vstorm-co pydantic-ai-backend artifact import between containers, results: 5

    Sources:

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

  7. changed the title [-]feat(roadmap): add the two-container runner Job and file import[/-] [+]feat(roadmap): add the three-container runner Job, policy and log reads[/+] on Nov 20, 2026
  8. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  9. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor

    A layout fact from part B of #3702 (PR #6609), for the three-container template:

    • The run folder of a fix-checks round is <data folder>/roadmap/fix-checks-runs/<run>/, with state/, work/ and out/. The clone of prepare is in work/.
    • The worktree of the agent is in the agent worktree folder of the data folder, not in work/, because add_worktree holds the take-over check of the branch.
    • publish reads only out/ (with a safe read) and a fresh clone that it fetches itself. It never reads the worktree of the agent.

    So the agent container needs work/, out/ and the agent worktree folder of the data folder. The publish container needs only state/ (read) and out/ (read), and it must not mount the agent worktree folder.

  10. 27 remaining items

  11. added
    status/in-review
    and removed
    status/in-progress
    on Nov 22, 2026
  12. removed
    status/in-review
    owner/agent
    on Nov 22, 2026
  13. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-22 13:47 UTC

  14. dan-petty commented on Nov 22, 2026

    @dan-petty
    OwnerAuthor

    The live check of the three-container runner Job passed. #6745 merged first and #6732 merged at 13:22 UTC. CronJob devops-cli-runner holds the init containers prepare and agent and the container publish. Its runner image is 0.194.1 (sha256:f10c82dd…), which holds #6745.

    Both Jobs below were made by the Service, so the policy roadmap-service-jobs admitted each CREATE.

    Job prepare agent publish Result
    fix-checks, PR #6744 (devops-cli-fix-checks-devops-cli-6338-c100b846d3) exit 0, 58 s exit 0, 5 min exit 0, 33 s repaired: publish pushed b83d45d "make check Tests & Coverage (shard 5 of 5) pass"; the PR then merged
    implement, #4244 (devops-cli-implement-devops-cli-4244-5e0764) exit 0, 3 min 16 s exit 0, 11 min 54 s exit 0, 1 min 17 s drafted: draft PR #6779 at 697e37f; the Service recorded implement.result=drafted, implement.pr=6779 and the runner digest

    Next: #6691 deletes the interim git controls.

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/highpriority/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