Skip to content

A step cannot reference a prior step's output, so values leave an Op only as search attributes #1290

Closed

Description

@lex00

A step cannot reference a prior step's output, so values leave an Op only as search attributes

An Op is a sequence of steps that cannot talk to each other. The only way a step's
result escapes today is outcomeAttribute, which stringifies it into a Temporal search
attribute for the UI:

phase("Diff", [{
  kind: "activity",
  fn: "lifecycleDiff",
  args: { env: "prod", live: true },
  outcomeAttribute: { name: "Drift", from: "drifted" },
}]),

That is a filter for the Temporal UI, not a value. A later step cannot consume it. So an
Op that wants to act on what an earlier step computed — apply only the stacks that
drifted, tag an image with the digest the build produced, gate on a count — cannot be
written as an Op at all. It drops to shell() steps passing data through files, or out
of Ops entirely into raw Temporal.

This is the concrete shape of "Ops don't use TypeScript to the fullest." Everywhere else
in chant a value produced by one declaration flows into another with types intact. In an
Op it does not flow at all.

The mechanism already exists

packages/core/src/attrref.ts — AttrRef is a typed reference to another entity's
attribute, resolved by the build pipeline (discovery/resolve.ts:12,
resolveAttrRefs). It is how a Subnet references its VPC without either executing.

It is inert by construction: an AttrRef is a reference, not an expression over a
value. That property is exactly what an Op needs, and it is why this can be added
without Ops becoming programs.

Proposed shape

A step can be named, and a later step can reference its declared output:

const diff = activity("lifecycleDiff", { env: "prod", live: true }, { id: "diff" });

phase("Diff", [diff]),
phase("Apply", [
  activity("applyStacks", { stacks: diff.out.driftedStacks }),
]),

diff.out.driftedStacks produces an AttrRef-shaped node in the serialized Op, not a
value. The build validates the path against the activity's declared return schema; the
generated workflow.ts binds the earlier step's result to a variable and passes it. The
serializer already emits const __r0 = await lifecycleDiff(…) for outcomeAttribute,
so the codegen half is close to what exists.

The line not to cross

References only. No expressions. diff.out.count > 0, diff.out.stacks.map(...),
or a template literal over a reference all turn the Op from data into a program, and the
property that you can read an Op and know what it will do is gone. EVL already rejects
that class of thing in resource props; the same restriction has to apply here, and
should be enforced by a lint rule rather than left as a convention.

Deliberately out of scope: conditional steps and loops over outputs. Those are the
natural next request and they are the point where an Op stops being inert. If a workflow
needs them, raw Temporal is the documented answer and should stay the answer.

Open questions

  • Does this want to compose with depends, so a step can reference an output from a
    different Op? Probably not in a first pass — cross-Op data flow needs a durable place
    to put the value, which is a much larger design.
  • Parallel phases destructure Promise.all results. Referencing an output from inside a
    parallel phase needs the binding to be stable, which the current __r0 counter is not
    obviously safe for.
  • Depends on typed activity contracts. Without a declared return schema there is nothing
    to validate diff.out.driftedStacks against, and this becomes another stringly path.

Verification

An example Op where a later step consumes an earlier step's output, asserted to build,
lint, and produce a workflow.ts that threads the value. Plus a negative test: an
expression over a step output fails lint.

Activity

  1. lex00 commented on Aug 1, 2026

    @lex00
    ContributorAuthor

    Depends on #1288 — without a declared return schema there is nothing to validate a step-output path against, and this degrades into another stringly path. Pairs with #1289: the same schemas a foreign runtime needs are the ones this validates against.

  2. added
    area:ops
    design
    on Aug 23, 2026
  3. lex00 commented on Aug 26, 2026

    @lex00
    ContributorAuthor

    Note for this issue from the pre-merge review of PR #1947 (Stage 1 activity contracts, #1288): pathExistsInSchema in packages/core/src/op/activity-contract.ts intentionally returns false (build error) for any outcomeAttribute.from path against a non-ZodObject return schema (e.g. a future z.record(...) or z.array(...)), rather than skipping like the no-contract case. No live trigger today since all declared returns schemas are z.object(...), but step-output references will lean on returns heavily — decide whether to support path traversal into records/arrays or keep the hard error, explicitly.

  4. lex00 commented on Aug 26, 2026

    @lex00
    ContributorAuthor

    Landed via #1950: stepOutput(step, path) / the .out proxy give a step's args a typed reference to a prior step's output, validated at build (TMP013: unknown producer, bad path against the producer's returns schema, ordering/same-phase/self/duplicate-id checks, contract-less producer, plus a primitive-type compatibility check between the producer's path type and the consumer's declared arg type). The temporal serializer compiles references into real dataflow (captured const, optional-chained path) — no more search-attribute round-trips — and refuses scope-invalid refs even when called outside chant build's lint gate. The local executor resolves references with identical semantics, so chant run stays a first-class peer. The record/array pathExistsInSchema hard-error stays deliberate, with whole-value refs as the escape hatch; union-aware type compatibility is deferred to #1288 Stage 2.

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

    area:opsdesign

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions