Skip to content

fix(pod): a start waits for the container to be RUNNING, not just for the command to return - #107

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/start-waits-for-container
Nov 27, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/start-waits-for-container

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

charly start on a pod unit ran systemctl --user start <svc> and returned as soon as the job was
queued. The engine then creates the container and only afterwards starts it — and a
created-but-not-running container has an empty mount namespace: podman exec into it succeeds and
sees none of its mounts. So start returning 0 did not mean the container was up, and a caller that
touched a bind-mounted path immediately raced it (opencharly/charly#1301).

charly start <pod>                 → rc=0
charly cmd <pod> "test -e /data"   → rc=1   ("No such file or directory")
…                                    PRESENT ~1.6s later (measured below)

Measured on the real unit (pod-cdi-keepid-bind, keep-id + CDI + a bind at /data), three
consecutive runs before the fix:

fresh create:  start rc=0 → immediate test -e /data = PRESENT
restart #1:    start rc=0 (1778ms) → /data ABSENT at +0ms, PRESENT at +1645ms
restart #2:    start rc=0 (1748ms) → /data PRESENT at +1ms      (the race did not fire)

The window is real and intermittent (1.6 s here, ~11 s in the filing), which is exactly why the fix
is a bounded wait on the engine's own state and not a delay.

The fix

  • start_ready.go (new) — waitContainerRunning / pollContainerRunning: inspect
    {{.State.Status}} until the container reports running, 1 s cadence, 10 s per attempt, 60 s
    deadline, through the shared poll.PollUntil primitive (the same one the declared-readiness wait
    uses). A failed inspect is transient (not created yet, or the engine still replacing it); the
    deadline is what fails a container that never comes up.
  • readiness.go — startEngineBin is now the ONE resolution of the engine binary (host-supplied
    param first, then the plan's), used by both waits (R2: it was inlined twice).
  • lifecycle.go — podStart calls the wait immediately after podContainerStart, before the
    declared readiness probe, the tunnel and the caller.

The wait is deliberately separate from the declared readiness wait: that one waits for the
application to accept work and only runs when the deploy authors a probes.readiness; this one
waits for the container to exist and always runs.

Head: de0d1c42553ceaae19401238f6061ba2b7547efc
Diff: 4 files changed, 181 insertions(+), 4 deletions(-) — 2 new files, 2 edited

How tested

$ charly box validate
charly box validate: OK — checked 3 candies, 2 boxes, 9 deploys, 6 distros, 7 builders; 0 warnings, 0 errors

$ (cd candy/plugin-deploy-pod && go test ./...)
ok  	github.com/opencharly/plugin-deploy-pod/candy/plugin-deploy-pod	0.780s
?   	github.com/opencharly/plugin-deploy-pod/candy/plugin-deploy-pod/cmd/serve	[no test files]

$ (cd candy/plugin-deploy-pod && go test -run 'ContainerRunning|ContainerReady' -count=1 .)
ok  	github.com/opencharly/plugin-deploy-pod/candy/plugin-deploy-pod	0.057s

The four new tests, and the one that is the change's own discriminator:

  • TestPollContainerRunning_WaitsThroughCreatedUntilRunning — a venue reporting created, created, running must be inspected at least three times. A single read is exactly the defect; this test
    fails if the poll returns early.
  • TestPollContainerRunning_FailsAContainerThatNeverRuns — a container stuck at created fails the
    wait instead of hanging or passing.
  • TestWaitContainerRunning_InspectsTheContainersOwnState — the inspect names the container.
  • TestWaitContainerRunning_RefusesAPlanWithNoContainerOrEngine — refuses rather than silently
    skipping; a start that cannot be waited on is the bug.

Live, on the R10 bed and on the unit itself:

$ charly check run check-pod-cdi-userns
[deploy-add] PASS after 1.835s   [check-live] PASS after 25.136s
[update] PASS after 2.946s       [cleanup] PASS after 1.919s
PASS (steps=6)                    (summary .check/check-pod-cdi-userns/2026.331.1636, 0 skipped)

$ for i in 1 2 3; do charly start <pod>; charly cmd <pod> "test -e /data"; charly stop <pod>; done
cycle 1: start rc=0 immediate test=PRESENT
cycle 2: start rc=0 immediate test=PRESENT
cycle 3: start rc=0 immediate test=PRESENT

An RCA the first bed run forced, recorded because it changed the evidence. The first run of the bed
FAILED at the bind write — and the cause was mine, not the fix's: a leftover deploy of the same name
from the pre-fix spike was still running, so charly config + charly start restarted that unit
mid-step, the already-present bounded probe saw the OLD container's /data, and the write hit the new
one. Missed control: I ran an R10 bed with a contaminant on its subject name. The deploy was removed,
the host confirmed clean (Status: not configured, unit gone), and the bed then passed as pasted
above. The run is one, not a retry against a root-caused defect.

Spike

R12's spike-equivalent exemption applies, and the spike round is the three candidate signals
measured above plus the discriminator test:

candidate instrument result
A — poll State.Status until running the unit test's sequence fake + the live restart measurement wins: created has an empty mount namespace, running implies the mounts are set; 3/3 restarts present at the first exec
B — poll each declared mount destination with test -e the plan rejected: PodLifecyclePlan carries no destinations (only ContainerName/EngineBin), so B would need a second inspect to learn them — a strictly larger wait for the same signal
C — a fixed delay after start the measurement forbidden by R3, and refuted by the data: the window was 1.6 s in one run and ~11 s in the filing

Rulebook compliance

  • R0 — /charly-internals:go, /charly-check:check, /charly-internals:strict-policy,
    /charly-internals:git-workflow and this repo's AGENTS.md loaded before editing.
  • R1 — the bed's first-run failure is RCA'd above (a contaminant on the subject name), not retried;
    opencharly/charly#1301 is the tracked defect this closes.
  • R2 — startEngineBin is one helper serving both post-start waits; the readiness wait's inlined
    copy is deleted.
  • R3 — no sleep, no blind retry: a bounded poll.PollUntil on the engine's own state, with a
    deadline that fails a container that never comes up.
  • R4 — charly start now behaves as documented (start returns a started container).
  • R5 — the readiness wait's duplicated engine resolution is deleted, not shadowed.
  • R6 — git status read before staging; work in a session worktree; branch off origin/main.
  • R7 — the discriminator test fails on a single read; the live restart measurement is pasted.
  • R8 — no external service is mocked; the bed drives the real engine, GPU and quadlet.
  • R9 — the run names its binary: /home/atrawog/claude3/opencharly/charly/bin/charly 2026.330.2135,
    with the plugin host-built from this worktree.
  • R10 — disposable: true subject only; charly check run check-pod-cdi-userns PASS (steps=6,
    0 skipped), including the destroy→regenerate→start leg.
  • R11 — no DESIGN shape or field changes; the change makes the deploy start contract behave as
    DESIGN.md's lifecycle expects.
  • R12 — spike-equivalent, named and tabulated above.
  • DISP — the subject deploy is disposable: true and every run above tore it down.

Change classification

No breaking change. A start now blocks until the container it started reports running; no
command, flag, field or shape changes. Rollback is a revert of this one squash commit — the previous
behaviour (return while the container may still be created) is what the issue documents as the defect.

Filed issues

None filed by this round. opencharly/charly#1301 is the issue this PR closes: it was filed and
claimed (assigned) when the race was first measured, and a STATUS on its thread records that the
remedy's code lives in this repo (candy/plugin-deploy-pod/lifecycle.go's podStart), not in charly
core, so the fix lands here and the issue is closed on merge. opencharly/plugin-preempt#15 remains the
preempt: vfio-refusal tracker that this run's teardown line belongs to (updated earlier, unchanged by
this diff).

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

… the command to return

`charly start` on a pod unit runs `systemctl --user start <svc>`, which returns
as soon as the job is queued. The engine then CREATES the container and only
afterwards starts it - and a created-but-not-running container has an EMPTY
mount namespace: `podman exec` into it succeeds and sees none of its mounts. So
a caller that acts on a bind-mounted path immediately after start races it:

  charly start <pod>                 -> rc=0
  charly cmd <pod> "test -e /data"   -> rc=1 ("No such file or directory")
  ... PRESENT ~1.6s later (measured), ~11s in the filing

Measured 2026-11-27 on a keep-id + CDI pod (bind at /data), three consecutive
runs: two restarts absent-then-present at +1645ms, one create present at once.
The window is real and intermittent, so a fixed delay would be wrong; the fix
polls the ENGINE's own state, bounded by the shared poll primitive
(opencharly/charly#1301).

The wait is deliberately separate from the declared readiness wait: that one
waits for the APPLICATION to accept work and only runs when the deploy authors
a probe; this one waits for the CONTAINER to exist and always runs, before the
readiness probe, the tunnel and the caller.

  - start_ready.go: waitContainerRunning / pollContainerRunning - inspects
    `.State.Status` until "running", 1s cadence, 60s deadline, 10s per attempt.
  - readiness.go: startEngineBin is now the ONE resolution of the engine binary
    (host param first, then the plan), used by both waits (R2).
  - lifecycle.go: podStart calls the wait after podContainerStart.

Proven: go test ./... green; four new tests - the poll must inspect at least
three times when the container reports `created, created, running` (a single
read is exactly the defect), must FAIL a container that never reaches
`running`, must inspect the container's own state, and must REFUSE a plan with
no container name or engine rather than silently skipping the wait.

Live: `charly check run check-pod-cdi-userns` PASS (steps=6, 0 skipped) on a
clean host, and three stop/start cycles each leaving /data present at the first
`charly cmd` after start returned.

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: de0d1c42553ceaae19401238f6061ba2b7547efc (branch: fix/start-waits-for-container)

Security screen: PASS — no secrets, no exfiltration, no weakened guardrails, no new dependencies; shellquote.ShellQuote guards the container name in the inspect script. Diff scope matches the body exactly.
Checklist: All applicable rules PASS or NA (change class: plugin Go code; R0–R12, PIL/ADE/SDD, CONC, HC, ARCH, DISP, QUAL, COORD all satisfied — poll.PollUntil reused (not a new DESIGN mechanism), discriminator test + live-boundary 3-cycle + check-pod-cdi-userns bed pasted, contaminant RCA'd and fixed, footer well-formed). 0 comments to disposition.

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 27, 2026 16:45
@github-actions
github-actions Bot merged commit 7036895 into main Nov 27, 2026
3 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant