Repository navigation
feat: scheduled leaf dispatch (Archetype C cron trigger on-ramp) - #13
Conversation
Signed-off-by: Paolo Dettori <[email protected]>
…l (single kubectl apply) Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…onfig) Signed-off-by: Paolo Dettori <[email protected]>
…ter ksvc) Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…tent retry Signed-off-by: Paolo Dettori <[email protected]>
…(gate soundness) Signed-off-by: Paolo Dettori <[email protected]>
…chestrator to pre-create them) Signed-off-by: Paolo Dettori <[email protected]>
…der set -u) Signed-off-by: Paolo Dettori <[email protected]>
…o-op fires) Signed-off-by: Paolo Dettori <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Self-review (automated): clean, well-structured PR — additive feature with good test coverage (unit + live gate). One suggestion below on pod security posture; no blocking issues.
Areas reviewed: TypeScript, Shell, YAML, Docs
Commits: 11, all DCO signed-off
CI: passing
| restartPolicy: Never | ||
| serviceAccountName: serverless-harness | ||
| containers: | ||
| - name: cron-dispatch |
There was a problem hiding this comment.
suggestion: Missing securityContext on the container/pod spec. Consider adding:
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: false
readOnlyRootFilesystem: trueThis dispatcher only does HTTP POSTs — it doesn't need write access or elevated privileges.
There was a problem hiding this comment.
Done in e961a5f (live-gate re-verified, 3/3 PASS). Added a pod + container securityContext:
runAsNonRoot: true+runAsUser: 65532— the harness image (node:22-alpine) has noUSERso it runs as root;runAsNonRootalone would refuse to start, hence the explicit nonroot uid.allowPrivilegeEscalation: false,capabilities.drop: [ALL],seccompProfile: RuntimeDefault.readOnlyRootFilesystem: true+ a writable/tmpemptyDir — node/tsx need a writable temp dir, so the read-only rootfs needs that one carve-out.
The dispatcher only reads the mounted config and makes HTTP POSTs, so it runs fine fully locked down. (Left the leaf-worker/service pods as-is for now — same hardening there is a sensible follow-up.)
…v-esc, read-only rootfs, drop caps) Signed-off-by: Paolo Dettori <[email protected]>
Summary
Adds the Archetype C trigger on-ramp: a Kubernetes
CronJobbecomes the start signal that dispatches a static, config-defined list of leaf sessions onto the unchanged async path (POST /run-leaf {async:true}). No external orchestrator process needs to be running — the schedule fires a thincron-dispatchpod that enqueues the work and exits; the existingleaf-queue→ KEDAScaledJob→runLeaf→ done-marker pipeline does the rest.Design:
docs/specs/2026-06-28-scheduled-leaf-dispatch-design.md· Plan:docs/superpowers/plans/2026-06-28-scheduled-leaf-dispatch.mdWhat's added
cron-dispatch.ts— pure logic (applyFire/dispatchAll/loadConfig/exitCodeFor, fully unit-tested with an injectedpost) + a guarded entrypoint that POSTs each templated envelope{async:true}to the in-cluster Knative service.deploy/knative/leaf-cron.yaml— one manifest, two docs: theleaf-cron-configConfigMap (item list with the__FIRE__template token) + theleaf-cronCronJob (concurrencyPolicy: Forbid, fire id via thejob-namedownward-API label, reuses theserverless-harnessSA + harness image — no new RBAC).deploy/knative/leaf-cron-smoke.sh— gated (CRON_LIVE_SMOKE=1) live gate.Idempotency
The fire id = the dispatcher's Kubernetes Job name (stable across a Job's pod retries, unique per fire). It's substituted into
sessionIdandresultRef, so each scheduled fire is a fresh run (fire-stamped result dir) while a retried dispatcher re-POSTs identicalsessionIds → idempotent resume/overwrite (no duplicate runs).Notable fix (approved scope change)
The live gate revealed the fire-stamped result dir
/work/nightly/<fire>/results/was never created — the async path only worked because its orchestrator pre-created the dir, and cron has no orchestrator (and the fire id is dynamic). Fixed by addingmkdirSync(dirname(...), {recursive:true})to the result write (run-leaf.ts) and the marker write (done-marker.ts) — a no-op when the dir exists, so the sync/async paths are unaffected. This also hardens orchestrator-less async use. (This touchedrunLeaf, overriding the plan's "unchanged" constraint — an explicit, approved decision.)Testing
CRON_LIVE_SMOKE=1 deploy/knative/leaf-cron-smoke.shon Kind — all 3 claims PASS: CronJob present; akubectl create job --from=cronjob/leaf-cronfire dispatches the list → all leaves complete with correct verdicts under the fire-stamped dir; idempotent retry (re-firing the same id re-runs the dispatcher to completion, reuses the same dir, markers still done).Follow-up (non-blocking)
server.ts'sisMainModuleguard to the exact-match idiom used incron-dispatch.ts(cross-package consistency; the new code is already correct).Assisted-By: Claude Code