Skip to content

refactor(platform): step live runs as a host on the shared walker #5258

Open

Description

@tale-code-bot

Step 3 of 3 of #4927: option 1, one walker behind ports, as triage decided on TALE-195 on 2026-10-30. It follows step 2 (#5257), which gives the in-process executor one walker behind ports. Like the other steps, it changes no behaviour.

What this step asks

The durable stepper (services/platform/backend/core/automations/stepper.ts) becomes a host on step 2's walker. Its own walk goes:

  • walkAutomation;
  • the loop half of stepNode;
  • the document sorted twice per turn, once for the effects order and once for the walk.

What stays is host, plugged into the walker's ports:

  • the lease and the claim, and fenced writes;
  • the ledger: durableLedger, callThroughLedger, StaleClaim, InDoubtPark (backend/core/automations/ledger.ts);
  • in-doubt handling on resume;
  • the hand-off on shutdown;
  • the subautomation pins;
  • the run record;
  • the agent lane.

Step 1 already moved the walk's types into services/platform/lib/engine/core/walk/: limits, progress, the ledger port, the progress sink and the approval gate's port. The types still in stepper.ts move to the walker or stay with the host here: WalkResult, StepOutcome and RunContext, which carry RunFailureCode and ActionCtx. So does the choice of whether AgentCursor (durable agent-lane state, in core/walk/progress.ts because NodeCursor names it) becomes opaque to the walk.

How much of stepper.ts is walk

#4927 left this "not examined". I counted it by section at 6f46e442691d4a811c89fa624b5c9e959d43ba60, step 1's head on feature-train 1a17c9efbaaae3b1526915f646581447f71788d3. There stepper.ts is 2,683 lines; it was 2,771 before step 1 moved the types out.

Lines Section Side
1–127 Header and imports (none)
128–163 Turn budget, poll intervals, CORE_TYPES host
165–329 Approvals: the gate, the agent host factory, a node type's effect and idempotency host
330–415 WalkResult, RunContext, yieldNote, asPromptText both
416–929 Node bodies (runNodeBody: transform, llm, agent, subautomation, connector) behind step 2's calls port
930–1058 walkAutomation: the next node, the hand-off between nodes, the output walk
1059–1194 StepArgs, StepOutcome, the credential probe, the input preview, the pins host
1195–1764 stepNode both (below)
1765–2253 The agent lane (stepAgentNode) host, behind the agent port
2254–2683 The action: settleLiveTurns, stepRunImpl, stepRunTurn, stepClaimedRun, durableSink host

Inside stepNode:

  • Walk: the skip verdict, the forEach and repeatUntil loop with its cursor, and the execution cap.
  • Host:
    • the approval park;
    • the agent lane's entry;
    • the pins' commit;
    • the ledger's errors;
    • the cut on shutdown;
    • the failure record.

By section, the walk is the 129 lines of walkAutomation plus the loop half of stepNode's 570. The host is 1,256 lines:

  • the turn budget, the poll intervals and CORE_TYPES: 36;
  • approvals: 165;
  • the step's helpers: 136;
  • the agent lane: 489;
  • the action: 430.

The rest:

  • the 514 lines of node bodies go behind the calls port;
  • the 86 lines of WalkResult, RunContext, yieldNote and asPromptText serve both sides;
  • 127 lines are header and imports.

What was not done:

  • stepNode was not split line by line.
  • The design pass of 2026-10-09 counted about 1,600 lines of code that carries invariants; that was not recounted.

Constraints

From #4927:

Done means

  • stepper.ts keeps no walk of its own: no loop over the nodes, items or passes. It drives the shared walker through the ports.
  • These pass unedited:
    • every backend/core/automations/stepper*.test.ts;
    • both parity suites: stepper.record-parity.test.ts and lib/engine/core/analysis/flow.parity.test.ts;
    • the real-Postgres lanes, on a fresh database.
  • lib/engine/selftest/purity.test.ts stays green.
  • The fast gate (format, typecheck, build) is green, and so is knip:check.

Parent: #4927

Activity

  1. added
    improvement
    service: platform
    agent-ready
    on Nov 1, 2026
  2. yannickmonney commented on Nov 14, 2026

    @yannickmonney
    Contributor

    Decision

    The durable stepper becomes a host on step 2's walker (lib/engine/core/execute/walker.ts). That walker becomes resumable and port-driven, so one walk serves both hosts.

    The walker's contract

    • Progress: it takes the run's progress (RunCheckpoints, including NodeCursor and executions). The next step is always the first step in order that has no checkpoint, and the execution cap counts across turns. A long loop commits its cursor every few items or seconds. Finished steps commit through RunSink.commit. It hands off at step, item and pass boundaries under today's rule: a turn always advances one step, and a stopping server hands off before the first step.
    • Ledger rule, stated once: only live calls are ledgered:
      • llm calls, recallable;
      • connector writes at any depth, recallable only when idempotent;
      • connector reads only inside a subautomation, recallable.
        Mock calls and top-level reads never touch the ledger, as today.
    • Ledger answers: in_doubt parks the run, and stale ends the turn. fail stops the run: it is never isolated as an item failure, and the write is logged as one that may have happened. failed replays the stored code, and the host turns it back into its failure. The host classifies each attempt's failureCode.
    • Calls port, widened: a connector call plan carries the declared effect and whether the action is idempotent. The call takes the mode, credential, path and signal, and returns the output and its effects. The durable host keeps the connector door for mock and live calls, and keeps its failure codes. The in-process host keeps its local check and its mocks. The llm call receives the attempt address.
    • Host hooks (WalkHost, in core/walk/ports.ts):
      • beforeEffect: the credential probe, the approval gate and its preview;
      • agentStep: the durable agent lane;
      • pins: the subautomation version pins;
      • interruption: a stale claim, an in-doubt park, a run stop, or the cut on shutdown.

    Answers

    • Leaves stepper.ts: walkAutomation, the loop half of stepNode, the duplicate transform, llm and connector bodies, and the second sort.
    • Stays host: the lease, the claim and fenced writes, the ledger and its failure classification, the connector door and the llm door, in-doubt handling, the hand-off on shutdown, the pins, the run record and the agent lane.
    • WalkResult: replaced by the widened WalkOutcome.
    • StepOutcome: becomes internal to the walker. The agent port gets AgentStepOutcome.
    • RunContext: stays in the host.
    • RunFailureCode: stays in the backend. A subautomation's failure keeps its inner code.
    • AgentCursor: stays typed, and is opaque to the walker by a rule a guard enforces.
    • Walker placement: execute/.

    Rationale

    The #4516 invariants stay in the host, and the walker reaches them only through ports. Writing today's ledger rule into the shared body keeps both hosts ledgering the same calls without adding rows. Widening the calls port lets the durable host keep its connector door and failure codes. Turning fail into a run stop keeps a loop from walking past a person's decision. Choosing the next step by checkpoint, with persisted executions and periodic cursor commits, makes a resumed run behave like a fresh one.

    Implementation (three PRs on feature-train, no behaviour change in any)

    1. One step body. Widen the calls port and the ledger finish, and extract the body with the ledger rule. The stepper uses it with durable ports. Done when the stepper suites, both parity suites and the real-Postgres lanes pass unedited, and fake-ledger tests show four things: a call is made only on go; mock calls and top-level reads skip the ledger; fail stops a loop with onItemError: continue; failure codes are unchanged.
    2. Resumable walker. Add progress, sink and WalkHost, with execute() as the first host. Done when execute() output is unchanged, and tests pass for resuming mid-forEach and mid-repeatUntil, the cap across a resume, the cursor cadence, the hand-off boundaries and an approval park. A guard keeps AgentCursor out of the walker.
    3. Stepper as host. Delete walkAutomation and the loop half of stepNode. Subautomations walk through walkSteps and keep their inner code. A guard bans topoSort, decideNode, resolveForEach and repeatSettled in backend/core/automations/. Done when the done list passes unedited, the attempt rows are unchanged, ENGINE_PROTOCOL is still 2, and the perf bench is flat.
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

    agent-readyimprovementservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions