Repository navigation
fix(pod): a start waits for the container to be RUNNING, not just for the command to return - #107
Merged
Merged
Conversation
… 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)
Review — PASSHead SHA: Security screen: PASS — no secrets, no exfiltration, no weakened guardrails, no new dependencies; Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
charly starton a pod unit ransystemctl --user start <svc>and returned as soon as the job wasqueued. The engine then creates the container and only afterwards starts it — and a
created-but-not-running container has an empty mount namespace:
podman execinto it succeeds andsees none of its mounts. So
startreturning 0 did not mean the container was up, and a caller thattouched a bind-mounted path immediately raced it (
opencharly/charly#1301).Measured on the real unit (
pod-cdi-keepid-bind, keep-id + CDI + a bind at/data), threeconsecutive runs before the fix:
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 reportsrunning, 1 s cadence, 10 s per attempt, 60 sdeadline, through the shared
poll.PollUntilprimitive (the same one the declared-readiness waituses). 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—startEngineBinis now the ONE resolution of the engine binary (host-suppliedparam first, then the plan's), used by both waits (R2: it was inlined twice).
lifecycle.go—podStartcalls the wait immediately afterpodContainerStart, before thedeclared 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 onewaits for the container to exist and always runs.
Head:
de0d1c42553ceaae19401238f6061ba2b7547efcDiff: 4 files changed, 181 insertions(+), 4 deletions(-) — 2 new files, 2 edited
How tested
The four new tests, and the one that is the change's own discriminator:
TestPollContainerRunning_WaitsThroughCreatedUntilRunning— a venue reportingcreated, created, runningmust be inspected at least three times. A single read is exactly the defect; this testfails if the poll returns early.
TestPollContainerRunning_FailsAContainerThatNeverRuns— a container stuck atcreatedfails thewait instead of hanging or passing.
TestWaitContainerRunning_InspectsTheContainersOwnState— the inspect names the container.TestWaitContainerRunning_RefusesAPlanWithNoContainerOrEngine— refuses rather than silentlyskipping; a start that cannot be waited on is the bug.
Live, on the R10 bed and on the unit itself:
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 startrestarted that unitmid-step, the already-present bounded probe saw the OLD container's
/data, and the write hit the newone. 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 pastedabove. 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:
State.Statusuntilrunningcreatedhas an empty mount namespace,runningimplies the mounts are set; 3/3 restarts present at the first exectest -ePodLifecyclePlancarries no destinations (onlyContainerName/EngineBin), so B would need a second inspect to learn them — a strictly larger wait for the same signalRulebook compliance
/charly-internals:go,/charly-check:check,/charly-internals:strict-policy,/charly-internals:git-workflowand this repo'sAGENTS.mdloaded before editing.opencharly/charly#1301is the tracked defect this closes.startEngineBinis one helper serving both post-start waits; the readiness wait's inlinedcopy is deleted.
poll.PollUntilon the engine's own state, with adeadline that fails a container that never comes up.
charly startnow behaves as documented (start returns a started container).git statusread before staging; work in a session worktree; branch offorigin/main./home/atrawog/claude3/opencharly/charly/bin/charly 2026.330.2135,with the plugin host-built from this worktree.
disposable: truesubject only;charly check run check-pod-cdi-usernsPASS (steps=6,0 skipped), including the destroy→regenerate→start leg.
deploystart contract behave asDESIGN.md's lifecycle expects.disposable: trueand every run above tore it down.Change classification
No breaking change. A start now blocks until the container it started reports
running; nocommand, 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#1301is the issue this PR closes: it was filed andclaimed (assigned) when the race was first measured, and a
STATUSon its thread records that theremedy's code lives in this repo (
candy/plugin-deploy-pod/lifecycle.go'spodStart), not incharlycore, so the fix lands here and the issue is closed on merge.
opencharly/plugin-preempt#15remains thepreempt:vfio-refusal tracker that this run's teardown line belongs to (updated earlier, unchanged bythis diff).
Agent:
cdi-audit· Claude Code sessionf760307f-53b4-4f48-87da-00f95e5300edAssisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)