Skip to content

feat(service): wait_for — a declared readiness precondition on a service start - #60

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/service-wait-for
Aug 28, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/service-wait-for

Conversation

@atrawog

@atrawog atrawog commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

The spec leg of batch B2's last item, and the highest-leverage one: it exists to delete real
duplication rather than to add surface.

Nine hand-rolled versions of the same poll exist in the candy corpus today — labwc,
kde-selkies ×2, chrome-cdp, wayvnc ×3, swaync, waybar, waybar-labwc, sway — each re-deriving a
socket wait with its own hardcoded timeout, which is exactly the sleeps and magic numbers R4 forbids:

$ grep -rl 'while \[ ! -e\|until \[ -e\|while \[ ! -S' pod-*/ | wc -l
8      # 9 loops

And one of them is already wrong. pod-labwc/labwc-wrapper:

TIMEOUT=30
ELAPSED=0
while [ ! -e "$PIXELFLUX_SOCKET" ] && [ "$ELAPSED" -lt "$TIMEOUT" ]; do
    sleep 0.5
    ELAPSED=$((ELAPSED + 1))
done

It declares 30 seconds and sleeps 0.5s per iteration while counting +1, so it actually gives up
after 15. That is the failure mode a hand-rolled loop has and a declared one cannot.

wait_for: {paths: ["${XDG_RUNTIME_DIR}/wayland-1"], timeout: "30s"}

Two design decisions worth stating

paths is required and non-empty (paths!: [_, ...]). A wait_for waiting for nothing is a
no-op that reads like a guard, which is worse than no guard at all.

That requirement is only enforceable under final validation — the structural form accepts the
empty case. My first version of the test used the structural helper and passed vacuously; it is
now unifyDefFinal, and it caught the schema genuinely not requiring the field until paths! was
used.

Paths only, deliberately. All nine existing loops wait on a filesystem path — a Wayland socket,
an IPC socket, a lock file — and none polls a TCP port. A ports: form would need a probe tool
the base images do not all carry, so it waits for a real second consumer rather than being designed
against a hypothetical one. R3's trigger is the second occurrence.

timeout accepts "30s" or a bare 30, matching stop_timeout rather than inventing a second
convention.

How tested

Coverage that fails without the change

Reverting only the implementation (both schema files, the generated Go, and the projection) while
keeping the tests — they do not even compile:

spec/service_render_context_portable_test.go:72: unknown field WaitFor in struct literal of type ServiceEntry
spec/service_render_context_portable_test.go:72: undefined: ServiceWaitFor
spec/service_render_context_portable_test.go:78: ctx.WaitFor undefined
--- FAIL: TestCandyServiceAcceptsWaitFor

An earlier attempt at this control used git stash, which stashed the tests too and passed
vacuously — the same trap as the validation helper. The control above reverts implementation files
by name.

Gates

$ task cue:gen          # SDD; reproducible, second run is a no-op
GEN=0
$ go test ./...
18 packages ok, 0 failures
$ golangci-lint run
0 issues.

Rulebook compliance

  • R0 — /charly-image:layer (the service: schema and init polymorphism) loaded before editing.
  • R1 — two anomalies, both root-caused rather than worked around: the required-field assertion
    passing vacuously under structural validation, and the git stash control being vacuous.
  • R2 — nothing deferred.
  • R3 — this field exists to remove duplication; and it reuses stop_timeout's string-or-int
    shape rather than adding a parallel convention.
  • R4 — the point of the change: replaces nine hand-rolled sleeps and hardcoded timeouts with a
    declaration each init lowers natively.
  • R5 — N/A here — the nine wrappers are consumers, deleted when they migrate (see below).
  • R6 — git status checked; branch off fresh main; no force-push, no bypass.
  • R7/R10 — N/A for a schema leg with no runtime path of its own; the lowering legs own that gate.
  • R8 — the emitted artifact is the generated Go, asserted by regeneration being a no-op.
  • B12 — coverage fails without the change, verified by reverting.
  • B13 — SDD honoured: CUE first, regenerated, no hand-edited generated Go.
  • B16 — no pin moved.

Change classification

  • Class: schema change (CUE) + regenerated Go + the render-context carry.
  • Verification gate: reproducible cue:gen + module suite + lint + revert-controlled coverage.
  • Attribution tier: analysed on a live system — the schema and projection are exercised
    directly, but nothing lowers wait_for into a real pre-start yet.

Not covered — and why the migration is separate

The lowering. Each init lowers this in its own idiom: systemd ExecStartPre=, supervisord a
rendered pre-exec ahead of command=, OpenRC start_pre(). That is the plugin-init + charly
legs, landing next, and the reason this PR claims nothing about emitted units.

The point of lowering it per-init rather than emitting a wrapper is that the wait becomes
supervised: a timeout fails the unit and surfaces in its status, instead of a wrapper exiting
non-zero and looking like a crash.

Migrating the nine wrappers is deliberately not bundled here. Their honest gate is
check-selkies-labwc-pod and friends staying green while the loops are deleted — beds that build
pixelflux from source and Chrome from the AUR. Bundling an unrunnable gate into this cutover would
make the whole thing unprovable; the migration is its own unit, and the labwc timeout bug above is
its first fix.

Assisted-by: Claude Code Anthropic Opus 5 (analysed on a live system)

…ice start

The spec leg of batch B2's last item.

Nine hand-rolled versions of the same poll exist in the candy corpus today -
labwc, kde-selkies x2, chrome-cdp, wayvnc x3, swaync, waybar, waybar-labwc, sway -
each re-deriving a socket wait with its own hardcoded timeout, which is exactly
the sleeps and magic numbers R4 forbids. One of them is already wrong:
pod-labwc/labwc-wrapper declares TIMEOUT=30 but sleeps 0.5s per iteration while
counting +1, so it actually gives up after 15 seconds. That is the failure mode a
hand-rolled loop has and a declared one cannot.

    wait_for: {paths: ["${XDG_RUNTIME_DIR}/wayland-1"], timeout: "30s"}

paths is REQUIRED and non-empty (paths!: [_, ...]): a wait_for waiting for nothing
is a no-op that reads like a guard, which is worse than no guard. Required-field
violations surface only under FINAL validation, so the test that pins this
validates concretely - the structural form accepts the empty case and would have
passed vacuously.

PATHS ONLY, deliberately. All nine existing loops wait on a filesystem path - a
Wayland socket, an IPC socket, a lock file - and none polls a TCP port. A ports:
form would need a probe tool the base images do not all carry, so it waits for a
real second consumer instead of being designed against a hypothetical one (R3's
trigger is the SECOND occurrence, not the first).

timeout accepts "30s" or a bare 30, matching stop_timeout rather than inventing a
second convention.

Carried into #ServiceRenderContext in the same change: a readiness precondition
the templates cannot see is a precondition that never runs. A service that
declares none leaves it nil, so a template omits the whole pre-start branch rather
than emitting an empty one.

Coverage fails without the change - verified by reverting only the implementation
and keeping the tests, which then do not compile (undefined: ServiceWaitFor).

Assisted-by: Claude Code Anthropic Opus 5 (analysed on a live system)

Claude-Session: https://claude.ai/code/session_01Gf42A3bau77JigFYLALrnq
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: ba73b4edaf7a (branch: feat/service-wait-for)

Security screen: PASS — no scope mismatch, no secrets/exfiltration, no weakened guardrails, no supply-chain changes; diff matches the description exactly.

Checklist: All applicable rules PASS or NA.

  • Change class: schema (CUE) + regenerated Go + render-context carry. Gate (cue:gen no-op, module suite, lint, revert-controlled coverage) is appropriate for a schema leg with no runtime lowering; the lowering legs own the bed gate.
  • SDD (B13): CUE-first, cue_types_gen.go regenerated in the same commit, no hand-edited generated Go, no banned @go(-) tags; generated ServiceWaitFor/WaitFor fields match the CUE defs (required paths! → no-omitempty Paths, type=string timeout coercion).
  • R1/R2/R3/R4: two anomalies RCA'd (vacuous structural validation, vacuous git stash control); migration of the nine wrappers is a separate-repo concern with named next legs (plugin-init + charly) and a concrete unrunnable-gate justification — not a vague follow-up; field exists to remove duplication; replaces hand-rolled sleeps/magic numbers.
  • B16 placement: CORRECT — wire shape in spec (CUE-first), projection carry in spec/service_render_context.go; no core capability, no alias files, no sdk-kit imports.
  • Attribution: analysed on a live system is justified (schema/projection exercised directly, no runtime lowering yet); Assisted-by footer in exact form.
  • Tests: unifyDefFinal correctly surfaces the required-field violation; revert-controlled coverage is internally consistent; TestBuildServiceRenderContextCarriesWaitFor covers both carry and nil-when-absent.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 28, 2026 17:19
@github-actions
github-actions Bot merged commit aabca5c into main Aug 28, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 28, 2026
@aitrawog
aitrawog deleted the feat/service-wait-for branch September 25, 2026 19:09
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