Repository navigation
feat(service): portable lifecycle fields + the unit_options escape hatch - #58
Conversation
The spec leg of batch B2. Purely additive: every field is optional and its absence
renders exactly as today.
Four PORTABLE fields on #CandyService, each expressible by at least two of the
three inits - the admission rule that keeps a single-init knob out of the shared
schema:
type systemd Type=; supervisord approximates oneshot via startsecs=0;
OpenRC distinguishes forking via command_background
requires a HARD dependency, distinct from after:'s ordering. systemd
Requires=; OpenRC depend(){ need ... }, which its template already
emits for localmount. supervisord ignores it
restart_sec systemd RestartSec=; OpenRC --respawn-delay
watchdog_sec systemd WatchdogSec=; OpenRC --healthcheck-timer
restart_sec/watchdog_sec accept "5s" or a bare 5, matching stop_timeout's existing
shape rather than inventing a second convention.
And ONE escape hatch for everything init-specific:
unit_options: {[init]: {[directive]: string | [...string]}}
It exists so #ServiceRenderContext does not grow a field per init-specific knob.
That struct is a kind-AGNOSTIC envelope every init's template renders against;
putting NotifyAccess, Slice, KillMode, RuntimeDirectory and a hardening block into
it would make it systemd's typed shape wearing a generic name - the leak the
boundary law names. With this map a FOURTH init needs no schema change, exactly as
the openrc init entity needed no Go change.
A directive value may be a scalar or a list; a list emits the directive once per
element, which is what systemd expects for repeatable directives such as
RuntimeDirectory= or ReadWritePaths=.
Both #CandyService and #ServiceRenderContext gain the fields: a field on the entry
that never reaches the context is unreachable from any template, so the pair is
asserted together.
Coverage fails without the change - verified by reverting both schema files and
re-running, not by inspection: 12 subtests fail, including that type: is an ENUM
(a typo must not reach a template and render an invalid Type=) and that
unit_options takes a scalar and a list side by side.
Assisted-by: Claude Code Anthropic Opus 5 (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01Gf42A3bau77JigFYLALrnq
Review — BLOCKHead SHA: Change class: schema change (CUE) + regenerated Go + tests. Security screen: PASS — no scope mismatch, no secrets/exfiltration, no weakened guardrails, no supply-chain changes. The diff matches the description. Blocks
Verdict: BLOCK ollama/deepseek-v4-flash — pi-review-action. |
Review — PASSHead SHA: Change class: schema change (CUE) + regenerated Go + tests. Security screen: PASS — no scope mismatch (diff matches description: 4 files, all accounted for), no secrets/exfiltration, no weakened guardrails, no supply-chain changes. Comment intake: The single Checklist: All applicable rules PASS or NA.
Verdict: PASS ollama/deepseek-v4-flash — pi-review-action. |
Summary
The
specleg of batch B2 — service-schema expansion. Purely additive: every field is optionaland its absence renders exactly as today.
Four portable lifecycle fields on
#CandyServiceEach is expressible by at least two of the three inits. That is the admission rule, and it is
what keeps a single-init knob out of the shared schema:
typeType=command_backgroundfor forkingstartsecs=0approximates oneshotrequiresRequires=depend(){ need … }restart_secRestartSec=--respawn-delaywatchdog_secWatchdogSec=--healthcheck-timerrequiresis a hard dependency, distinct fromafter:'s ordering — OpenRC's template alreadyemits
need localmount, so the concept exists there today with no way to author it.restart_sec/watchdog_secaccept"5s"or a bare5, matchingstop_timeout's existing shaperather than inventing a second convention.
One escape hatch for everything init-specific
Keyed init-name → directive → value. It exists so
#ServiceRenderContextdoes not grow a fieldper init-specific knob.
That struct's own doc calls it "the data an init system's service_template renders against" — a
kind-agnostic envelope. Putting
NotifyAccess,Slice,KillMode,RuntimeDirectoryand ahardening block into the one struct all three inits render from would make it systemd's typed shape
wearing a generic name — the leak the boundary law names. With this map, a fourth init needs no
schema change, exactly as the
openrcinit entity needed no Go change.A directive value may be a scalar or a list; a list emits the directive once per element, which
is what systemd expects for repeatable directives like
RuntimeDirectory=orReadWritePaths=.Both structs, together
#CandyServiceand#ServiceRenderContextgain the fields in the same change. A field on the entrythat never reaches the context is unreachable from any template, so the pair is asserted together
rather than trusted.
How tested
Coverage that fails without the change
The diff adds 8 test cases: 5 subtests in
TestCandyServiceAcceptsPortableLifecycleFields, plus3 standalone tests. Reverting only the two schema files to the parent commit, with the tests in
place — 7 of the 8 fail:
The eighth,
TestCandyServiceTypeIsConstrained, passes on the old schema too —#CandyServiceis closed, so an unknown
type:field is rejected there for the wrong reason. It is a forwardguard, not a discriminator: it fails only if someone later widens
type:to a barestring, whichwould silently let a typo render an invalid
Type=directive. Stating that plainly rather thancounting it as coverage for this change.
TestCandyServiceUnitOptionsTakeScalarsAndListsputs a scalar and a list side by side in one map, sothe disjunction is exercised rather than assumed from reading the CUE.
All validate against the shipped schema, compiled the way consumers compile it
(
schemaconcat.ConcatSchemaover the embedded FS).Gates
Generated Go, both structs:
Rulebook compliance
/charly-image:layer(theservice:schema and init polymorphism) and/charly-internals:plugin(the boundary law governing where init-specific shape may live) loadedbefore editing.
$TMPDIRtests that fail from a/tmpcheckout were diagnosed inspec#57 and the suite here is run from outside
/tmp.restart_sec/watchdog_secreusestop_timeout's string-or-int shape rather than adding a second convention.smuggled into the shared envelope.
git statuschecked; branch off freshmain; no force-push, no bypass.consumer legs below, which is why the tier is capped.
parent commit, with the verbatim run pasted above. The eighth is identified as a forward guard
rather than counted as coverage.
task cue:genregenerated, no hand-edited generated Go.Change classification
cue:gen+ module suite + lint + revert-controlled coverage.analysed on a live system— the schema compiles, regenerates and validatesagainst real values, but nothing renders these fields yet.
Not covered — the consumer legs, in order
sdk— carry the five fields throughBuildServiceRenderContext(the pure entry→contextprojection), so they reach a template at all.
plugin-init+charly— render them: systemdType=/Requires=/RestartSec=/WatchdogSec=plus aunit_options.systemdrange; OpenRCneed/--respawn-delay/--healthcheck-timer. Until then these fields are authorable and inert, which is why this legclaims nothing about rendered output.
wait_for:, is deliberately not in this leg. Nine hand-rolledwhile [ ! -e "$SOCKET" ]loops exist today (labwc, kde-selkies ×2, chrome-cdp, wayvnc ×3,swaync, waybar, waybar-labwc, sway) and R4 forbids the sleeps and magic numbers they carry, but
each init needs a genuine lowering (systemd
ExecStartPre=, supervisord a rendered pre-exec,OpenRC
depend(){ need … }) and the honest gate is deleting real duplication with those bedsstaying green. That is its own unit of B2.
Assisted-by: Claude Code Anthropic Opus 5 (analysed on a live system)