Repository navigation
Description
Agreed design as of 2026-10-02, amended the same day (hooks request workflow data exactly as steps do; roles carry operations only). The original proposal is kept at the end.
Hooks, lifecycles and workflow roles (tier 1)
Which hooks run and in what order, what each may return, what they can read and write, and how reusable policies reach the workflow through roles. Builds on proposals 0002 (Foundations), 0008 (Steps), 0009 (Running a workflow) and 0024.
Which hooks run, and in what order
- Step hooks are
on step success,on step failure,on step retryandon step abnormal termination. Workflow hooks areon workflow successandon workflow failure. Hooks are defined in policies (Foundations). - The sequence for each outcome:
- success:
on step success; - failure that is not retriable:
on step failure, with the causefailure; - retriable failure, with retry budget left:
on step retry, with the causeretriable failure, then the next attempt; - retriable failure, budget exhausted: only
on step failure, with the causeretries exhausted; the retry hook is not called when no retry is possible; - abnormal termination:
on step abnormal terminationalways runs first; then the retry hook or the failure hook, by the same rules, with the causeabnormal terminationorretries exhausted(proposal 0024); - skipped: no hook runs (proposal 0008).
- success:
What each hook may return
-
A hook returns a lifecycle, or nothing. Nothing means the executor's default. The tier 1 lifecycles are
FailWorkflowandFinishWorkflow. A lifecycle a hook may not return aborts the journey (abort reasoninvalid lifecycle); implementations should make it impossible to express where their language allows it.Hook Nothing means May return on step successthe next step, or success after the last FinishWorkflow(succeed now),FailWorkflow(fail now)on step failurethe journey fails FailWorkflowon step retrythe step is retried FailWorkflow(give up now; the failure hook is not called)on step abnormal terminationcontinue as proposal 0024 says FailWorkflow(stop now)on workflow success,on workflow failurenothing to decide no lifecycle in tier 1 -
FailWorkflowfrom a success hook leaves the stepSucceeded, with its contributions committed; the journey fails. -
FailWorkflowcarries a reason: a code, an optional message and optional details. The journey's result names the step whose hook failed the journey, and that reason. -
Workflow hooks have no lifecycle in tier 1; later tiers will add some.
Workflow hooks
on workflow successruns once when the journey succeeds, including throughFinishWorkflow;on workflow failureruns once when it fails. Both run at the end, before the result is produced. Neither runs when the journey is aborted.
Hooks that throw, and aborts
- Hooks never throw. A hook that throws or panics aborts the journey (abort reason
hook threw). After an abort, no hook runs.
What hooks can read
- Step hooks can request, from the step they act on: its contributions, including uncommitted ones (Foundations), the failure's reason, the cause of the call, and the error of an abnormal termination (proposal 0008).
- Every hook can request the attempt number (step hooks) and the journey ID.
- Data from the workflow, exactly as steps request it. Every hook can request data from the workflow by key and type, required or optional, just as a step requests its inputs, and the workflow resolves it with the same rules: a missing required value or a wrong type aborts the journey, and a missing optional value is absent. A hook is never given the data bag itself.
- A step hook's request is resolved as an input of the step it acts on would be: through the workflow's input adapter for that step and key if there is one, otherwise from the data bag.
- A workflow hook's request is resolved from the data bag. Input adapters for workflow hooks would extend proposal 0002, which attaches adapters to pairs of step and key, and are not part of tier 1.
- Hooks read data, but business decisions belong in steps: hooks branch on what steps reported and contributed.
12a. Everything a hook receives is read-only for it, as for steps: changing it never changes the data bag or what anyone else receives. Writing goes only through a contributor (#27, which amends proposal 0002).
What hooks can write
- A hook can request a contributor, as a step does; it never has direct access to the data bag.
- A hook's contributions are committed as soon as the hook returns without throwing, whatever the step's outcome; for example, a failure hook can record a decline reason and then fail the journey. A workflow hook's contributions are committed before the result is produced, so they appear in the journey's output. Overwriting is allowed and recorded (proposal 0008), and events say whether a contribution came from a hook or a step.
Workflow roles
- A role is an interface that a workflow can provide: operations the workflow's own code implements, for example "send a notification" or "find a customer's email". A workflow may provide any number of roles.
- Roles carry operations, not data. A hook that needs data asks for it as data from the workflow (item 11), so it depends on keys and types, never on how the workflow stores its data.
- A common base. Implementations may give every role a common base interface, for example to mark roles in a typed language; it carries no data access.
- Policies request roles as parameters. A hook requests each role it needs as a separate declared parameter, the same way it declares the data it requests; it may request several. It then receives the workflow instance through those roles only, never the workflow as a whole. A policy can therefore be attached to any workflow that provides the roles it needs, and be reused across workflows.
- What a role never exposes. A role never gives access to the data bag, the executor or the steps. Data is read only as data from the workflow (item 11) and written only through a contributor (item 13), so every read follows the same rules as a step's and every change appears in the events.
- Who can use roles: step policies and workflow policies. Steps cannot; they stay isolated (Foundations, premise 1).
- Admission checks roles. A policy attached to a workflow that does not provide one of the roles it requests is refused at admission, reported with every other violation; implementations should detect it at compile time where their language allows it.
- Role calls are the workflow's business. Itinera does not record them automatically; a hook that wants them in the event stream emits a
journey_*event itself (Events #11).
Synchronous and asynchronous hooks
- Hooks may be synchronous or asynchronous, under the same executor capability rules as steps (The local executor #12).
Not here
- Policy events, recording which policy caused an event, are settled in Events #11.
- Lifecycles for workflow hooks, transfers, switches and sub workflows belong to later tiers.
- A hook running before a step, which could decide it does not run, belongs to a later tier.
Tier
Original proposal
Summary
Which hooks exist in tier 1, what they may return, and what happens when they return nothing. Policies, and the rule that each hook is defined at most once, are in #2.
Proposal
- Step hooks react to a step's outcome: on success, on failure, on retry, and on abnormal termination.
- A step hook returns a lifecycle, or nothing. Nothing means the executor's default:
- on success: run the next step, or succeed the workflow after the last one;
- on failure: fail the workflow;
- on retry: retry if attempts remain, otherwise the step becomes
Failed; - on abnormal termination: enter the retry loop, or abort if the step is configured to.
- Tier 1 lifecycles:
FailWorkflowandFinishWorkflow. - Each hook allows only some lifecycles. The exact list per hook is part of this proposal. Returning a lifecycle a hook does not allow is an abort. Implementations should make that impossible to express where their language allows it.
- Hooks never throw. A hook that throws or panics aborts the journey.
- Abort means something illegal happened. It ends everything, and no hook runs.
- Workflow hooks in tier 1: on workflow success and on workflow failure. In tier 1 they return nothing.
- What hooks can read. Hooks read the step's outcome, its contributions (through an adapter, Foundations: step isolation, declarative workflows, policies and data flow #2 premise 7) and the run's state, such as the attempt number.
Activity
marlon-sousa commentedon Oct 1, 2026
marlon-sousa commentedon Oct 1, 2026
marlon-sousa commentedon Oct 2, 2026
marlon-sousa commentedon Oct 2, 2026
[-]Hooks and lifecycles[/-][+]Hooks, lifecycles and workflow roles[/+]marlon-sousa commentedon Oct 2, 2026
Claude summary
Posted by Claude (Claude Code) from a maintainer's account, as described in PROCESS.md.
Evaluated with the maintainer outside the thread on 2026-10-02; every question was settled. The issue body now holds the agreed design, with the original proposal kept at the end; the earlier comments are folded in and hidden as outdated. The title now includes workflow roles, added during the evaluation.
Decided: the order hooks run in for each outcome; the lifecycles each hook may return;
FailWorkflowcarries a reason; workflow hooks run once at the end and never on abort; workflow hooks read the data bag by key and type; hooks write only through a contributor, committed when the hook returns; hooks can request the attempt number and the journey ID; hooks may be synchronous or asynchronous; and workflow roles: interfaces a workflow provides, extending a base role with read-only access to the committed data bag, requested by policies so they can be reused across workflows, checked at admission, and never exposing writes to the data bag, the executor or the steps.The conformance checklist is updated in itinera-dev/conformance#10. This proposal is ready for a maintainer to set
status: ready.marlon-sousa commentedon Oct 2, 2026
github-actions commentedon Oct 2, 2026
Accepted on 2026-10-02 in #31.