Skip to content

feat(platform): give connector mocks the run's own state #5331

Open

Description

@tale-code-bot

Part 2 of #5276. TALE-369 split #5276 in two. Part 1, worked there, lets a test answer a step's
calls in order (scenarios: { <step>: [<name>, …] }) and closes #5276. This issue is the rest:
the run's own state in mock mode.

Status quo. A connector action's mock is a pure function of its input. Its body runs in the
code runner with { input } alone: toConnector in services/platform/lib/connectors/registry.ts
(in-process runs) and mock mode in services/platform/lib/connectors/dispatcher.ts (durable
runs). A scenario is a fixed answer, and with part 1 a fixed series. So a test cannot simulate
what the run itself wrote:

  • create then read, update then read, delete then read;
  • a repeated write with the same idempotency key, answered from what the run already wrote;
  • an in-doubt write: the write reached the service, but its answer was lost.

Asked. In mock mode, the run's own state for each connector, so that read-after-write, a
repeated key and an in-doubt write can be proven:

  • One JSON value per connector per run. A mock body receives a copy beside input and returns
    the next value with its output, so the body stays inside the code runner's sandbox. The value
    has a size cap, and a step whose state outgrows it fails with a sentence that says so.
  • The outermost run creates the state and shares it with the automations it calls, so one run
    has one state. It is never shared between runs or organizations, and it is dropped when the
    run ends.
  • A write whose idempotency key the run already used is answered from the run's record of that
    key, the answer it gave the first time, without running the mock again. That is what an
    idempotent live action does.
  • An in-doubt write is a scenario marked as applied (for example error.applied: true). It runs
    the mock, keeps the state change and the answer, then fails as the scenario says. A repeated
    write with the same key is answered from the record.
  • The mocks of the shipped task connector (create, get, list, update_status) keep the
    run's tasks, so a test can prove create then read.

Fit with #4929.

Note. An in-process run never repeats a key today. connectorIdempotencyKey(runId, path, item, pass) in services/platform/lib/engine/core/protocol.ts is unique per call. A key
repeats only with #4928's retries, a durable resume, or "run the step again" on an in-doubt park.
A test of a repeated key needs one of those.

Tests (from #5276's triage):

  • read-after-write;
  • an in-doubt write;
  • a repeated key answered from the record;
  • isolation across two runs and across two organizations;
  • the state is gone once the run ends.

Parent: #5276. Related: #4928, #4929, #4943.

Activity

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

    @yannickmonney
    Contributor

    Decision

    Build the run's own mock state to the design on feat/connector-mock-run-state, rebased onto release/0.6 through feature-train.

    The rule

    • Opt-in per action. An action that declares mockState: true gets { input, state }, where state is a JSON copy of its connector's part (null before any write). It returns { output, state? }: an absent state keeps the current one, and null clears it. Reads return no state. Every other mock stays a pure function of input. Both executors go through one door, lib/connectors/mock-call.ts.
    • One state per run, by connector. The outermost run creates it and called automations share it. It is never shared between runs or organizations, and it ends with the run.
    • Idempotency record. Only writes declared idempotent: true answer a repeated key from the first answer. Other writes run again.
    • In-doubt write. A write's error scenario may set error.applied: true. The mock runs, the state and the keyed answer are kept, and the step then fails. In durable runs that state commits with the failure outcome and is never rolled back.
    • Caps. 256 KiB per connector and 1 MiB per run. A write over either keeps nothing and fails as CONNECTOR_MOCK_STATE_TOO_LARGE, in every locale.
    • Durable runs. The snapshot goes in the checkpoints (mockState) and is committed in the same fenced statement as the step. A step that is cut off is restored to its mark. Finish or cancel drops the key. No protocol stamp.
    • Preview carries no mock state: real reads, and held writes as "would have sent". A note goes on Improvement: durable test runs with stand-ins, preview mode, a wait step and the approval line in the run record #4929.
    • Spec and docs. The branch has no spec rules or docs. AUTO-R81 and CONN-R37 are written new, and code references to CONN-R36, which on release/0.6 is output cutting, are retargeted. The connector docs (en/de/fr) drop "same input, same output" for the opt-in rule.

    Answers

    Rationale. The design keeps the sandbox data-only, copies what an idempotent live action does, commits state atomically with each step, and keeps the pure mocks deterministic. The run-wide cap bounds checkpoint rows. The spec rules and docs fill gaps the branch left.

    Units (into release/0.6 via feature-train)

    1. feat(shared): the mockState and error.applied schema, with its refusals. (S)
    2. feat(platform): in-process state, the door, the idempotency record, the in-doubt write, both caps, the failure reason in every locale, spec rules AUTO-R81/CONN-R37, and the docs. (M)
    3. feat(platform): the durable commit, restore after a cut, the in-doubt state kept with the failure, and drop at the end of the run. (M)
    4. feat(platform): the task connector keeps the run's tasks. (M)
    5. Follow-up on Improvement: run independent steps and a forEach's items at the same time, and try a failed step again after a wait #4928: a retried in-doubt task.create is answered from the record, once retries reuse the key. (S)

    Cross-issue amendments (decisions taken together with #4929):

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-readyfeatservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions