Skip to content

Hooks, lifecycles and workflow roles #10

Closed

Description

@marlon-sousa

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

  1. Step hooks are on step success, on step failure, on step retry and on step abnormal termination. Workflow hooks are on workflow success and on workflow failure. Hooks are defined in policies (Foundations).
  2. The sequence for each outcome:
    • success: on step success;
    • failure that is not retriable: on step failure, with the cause failure;
    • retriable failure, with retry budget left: on step retry, with the cause retriable failure, then the next attempt;
    • retriable failure, budget exhausted: only on step failure, with the cause retries exhausted; the retry hook is not called when no retry is possible;
    • abnormal termination: on step abnormal termination always runs first; then the retry hook or the failure hook, by the same rules, with the cause abnormal termination or retries exhausted (proposal 0024);
    • skipped: no hook runs (proposal 0008).

What each hook may return

  1. A hook returns a lifecycle, or nothing. Nothing means the executor's default. The tier 1 lifecycles are FailWorkflow and FinishWorkflow. A lifecycle a hook may not return aborts the journey (abort reason invalid lifecycle); implementations should make it impossible to express where their language allows it.

    Hook Nothing means May return
    on step success the next step, or success after the last FinishWorkflow (succeed now), FailWorkflow (fail now)
    on step failure the journey fails FailWorkflow
    on step retry the step is retried FailWorkflow (give up now; the failure hook is not called)
    on step abnormal termination continue as proposal 0024 says FailWorkflow (stop now)
    on workflow success, on workflow failure nothing to decide no lifecycle in tier 1
  2. FailWorkflow from a success hook leaves the step Succeeded, with its contributions committed; the journey fails.

  3. FailWorkflow carries 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.

  4. Workflow hooks have no lifecycle in tier 1; later tiers will add some.

Workflow hooks

  1. on workflow success runs once when the journey succeeds, including through FinishWorkflow; on workflow failure runs 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

  1. 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

  1. 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).
  2. Every hook can request the attempt number (step hooks) and the journey ID.
  3. 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.
  4. 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

  1. A hook can request a contributor, as a step does; it never has direct access to the data bag.
  2. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Who can use roles: step policies and workflow policies. Steps cannot; they stay isolated (Foundations, premise 1).
  7. 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.
  8. 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

  1. 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

  1. Step hooks react to a step's outcome: on success, on failure, on retry, and on abnormal termination.
  2. 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.
  3. Tier 1 lifecycles: FailWorkflow and FinishWorkflow.
  4. 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.
  5. Hooks never throw. A hook that throws or panics aborts the journey.
  6. Abort means something illegal happened. It ends everything, and no hook runs.
  7. Workflow hooks in tier 1: on workflow success and on workflow failure. In tier 1 they return nothing.
  8. 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.

Tier

Activity

  1. added
    proposal
    status: planned
    tier: 1
    on Oct 1, 2026
  2. marlon-sousa commented on Oct 1, 2026

    @marlon-sousa
    Author
  3. marlon-sousa commented on Oct 1, 2026

    @marlon-sousa
    Author
  4. marlon-sousa commented on Oct 2, 2026

    @marlon-sousa
    Author
  5. marlon-sousa commented on Oct 2, 2026

    @marlon-sousa
    Author
  6. changed the title [-]Hooks and lifecycles[/-] [+]Hooks, lifecycles and workflow roles[/+] on Oct 2, 2026
  7. added
    status: evaluating
    and removed
    status: planned
    on Oct 2, 2026
  8. marlon-sousa commented on Oct 2, 2026

    @marlon-sousa
    ContributorAuthor

    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; FailWorkflow carries 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.

  9. marlon-sousa commented on Oct 2, 2026

    @marlon-sousa
    Author
  10. added
    status: ready
    and removed
    status: evaluating
    on Oct 2, 2026
  11. github-actions commented on Oct 2, 2026

    @github-actions

    Accepted on 2026-10-02 in #31.

  12. locked as resolved and limited conversation to collaborators on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalstatus: readytier: 1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions