feat(hooks): C4 — internal/hooks thin runner + hook_run ledger CRUD (spec 11) - #5
Merged
Conversation
…spec 11) Run declarative lifecycle hooks at saga phase boundaries: - internal/state hook_run CRUD: HookSatisfied (lock-free read), RecordHookRun (idempotent; success-only, under the flock), DeleteHookRuns (--force-hooks re-arm). The cardinal rule — a row reflects only success — makes hooks resumable for free. - internal/hooks: Execer (host via os/exec from the documented base dir; exec via `docker compose exec -T -w -e NAME=VALUE`, the only transport that takes per-run env values, DECISIONS D10) + OSExecer production impl. Runner applies per-hook timeout, retries (fixed backoff), and onFailure (abort/warn/continue). RunPhase orders a phase's hooks, skips ledger-satisfied idempotent/once hooks, and records success INSIDE the flock — the hook BODY runs OUTSIDE it so a long hook never serializes other invocations (spec 08 #1 rule). run:exec without a service is rejected (the transport rule config can't express). Thin runner: ${ref}/${env}/${self}/secret:// interpolation happens upstream in the saga and arrives via PhaseOpts.ExtraEnv (secrets last); the package never imports internal/state (Ledger/Locker interfaces) or resolves secrets. Full workspace-scope ordering is X3. Unit tests (fake Execer + fake Ledger): host/exec routing, retries→success, retries exhausted, timeout, abort/warn/continue, idempotent skip, record-on- success-not-failure under the lock, env ordering. A hermetic OSExecer host test (real os/exec) + a `//go:build integration` test exec'ing into a real busybox compose stack with inline -e env injection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Chunk C4 (M2-remainder)
Runs the declarative lifecycle hooks at saga phase boundaries, with the firstRun idempotency that replaces Postgres
initdb.d. Per spec 11.What
internal/statehook_run CRUD:HookSatisfied(lock-free read),RecordHookRun(idempotent; success-only, under the flock),DeleteHookRuns(--force-hooksre-arm). A row reflects only success → hooks are resumable for free.internal/hooks:Execer—hostviaos/execfrom the documented base dir;execviadocker compose exec -T -w -e NAME=VALUE(the only transport that takes per-run env values, DECISIONS D10).OSExeceris the production impl.Runner— per-hook timeout, retries (fixed backoff), onFailure (abort/warn/continue).RunPhase— orders a phase's hooks, skips ledger-satisfied idempotent/oncehooks, records success inside the flock while the hook body runs outside it (spec 08 feat(state): C1 — saga_phase v2 migration + resumability CRUD #1 rule: a longnpm installmust not serialize other invocations).run:execwithout aserviceis rejected.Layering
Thin runner —
${ref}/secret://interpolation happens upstream in the saga and arrives viaPhaseOpts.ExtraEnv(secrets last). The package never importsinternal/state(usesLedger/Lockerinterfaces) or resolves secrets. Full workspace-scope ordering is X3.Tests
OSExecerhost test (real os/exec) + a//go:build integrationtest exec'ing into a real busybox compose stack with inline-eenv injection. Verified locally against Engine 29.5.3.Gate
make cigreen;go test -tags=integration ./internal/hooksgreen locally.🤖 Generated with Claude Code