Pins Across Instances

PARTIAL

A pinned execution tree runs against the catalog as it was when its root started. On one server that is a single number. The root records a watermark, the largest catalog_id at its start, and every child resolves with catalog_id <= watermark (watermark_now and resolve_execute in noetl/server src/services/catalog_cas.rs, behind NOETL_CATALOG_PINNING). A version registered after the root started is invisible to the tree.

That number cannot hold a reference to another instance, for two reasons:

  1. B's catalog ids mean nothing on A. They come from B's database. Comparing one with A's watermark compares two unrelated counters.
  2. An import lands after the root started. When A imports B's body mid-run, the new row on A gets a catalog_id above the root's watermark. A watermark rule would either hide it or, if bypassed, let every later call fetch whatever B holds now.

So server v3.161.0 adds two more pins, one on each side. Both are in src/services/catalog_remote.rs (checked at v3.165.5) and both are live only with NOETL_CATALOG_REMOTE_CALLS (caller) or NOETL_CATALOG_REMOTE_SERVE (owner), on top of NOETL_CATALOG_CAS and NOETL_CATALOG_PINNING.

Off by default, off on prod

These tables are created only when a remote flag is on and the CAS tables are ready (ensure_schema). None of the flags is set in the prod manifests in noetl/ops at 7695b1b. Everything below is the behaviour of released code that the two-runtime kind test exercised, not something a public deployment runs.

The caller pin: one answer per root and reference

noetl.execution_remote_pin
  root_execution_id  BIGINT  ┐ primary key
  reference          TEXT    ┘
  instance_id, path, version, digest, mode, created_at

The first time a reference to B is resolved inside a tree, A writes what it resolved to: B's path, version and digest. Every later call in the same tree, from any step and at any depth, gets that digest. This holds in both modes. In import mode A looks up its local import by that digest. In delegate mode A sends that digest to B.

The key is canonical. RemoteTarget::key writes every spelling as noetl://<instance>/<reference>, so these three calls share one pin:

# in the root, a direct reference
tool: { kind: playbook, path: "noetl://ni-…/xc/leaf" }
# elsewhere, the import name
tool: { kind: playbook, path: "peer/ni-…/xc/leaf" }
# inside the imported peer/ni-…/xc/target, a bare name (home-instance resolution)
tool: { kind: playbook, path: xc/leaf }

A version or digest in the reference is part of it, so xc/leaf@2 and xc/leaf are different references with different pins. A direct source such as gs://… or db://… called from inside a pinned tree is pinned the same way, keyed by its URI (PinKey::Source). Before v3.161.0 it was fetched again on every call.

Races: the first writer wins

Two steps of one tree can resolve the same new reference at the same moment. Each one asks B, and each one gets an answer. If B registered a new version between the two asks, the answers differ. The write settles it:

INSERT INTO noetl.execution_remote_pin (...) VALUES (...)
ON CONFLICT (root_execution_id, reference) DO NOTHING;
-- then read the row back

pin_put returns the row that is stored, not the one the caller tried to write. The loser silently adopts the winner's digest. A logs "remote pin race: another call in this tree pinned first", and both calls run the same body. In import mode the loser's own import may stay on A as an unused row. The tree never runs it.

Conflicting digests: refused, never swapped

A step can name the digest it expects: #sha256:… on a noetl:// reference, @sha256:… on a name, or the tool's digest: key. If the tree already pinned a different digest for that reference, the call fails with 422: "<key>: this tree pinned <A's digest>, asked for <the step's digest>". The server does not re-pin the tree or fetch the newer body, and the step that asked does not run. The same holds when B answers with a body that does not match its own digest (verify_fetched) and when the step's digest does not match what B holds. Each is an error, and a cached copy is never used to cover it.

A cached import is not the authority

An import leaves a row on A under peer/<B>/<path>. It is tempting to treat that row as the answer next time. Inside a pinned tree, the server does not:

  1. If the root already has a remote pin for the reference, use it. B is not contacted in import mode. A reads its import by the pinned digest, and if that import has been removed the call fails with 404 ("pinned to … but that import is gone").
  2. Otherwise ask B (a signed catalog.resolve), import, and pin.
  3. Only if B cannot answer, and A has a cached import, pin the tree to the cached copy. A logs "owner unreachable; pinning this tree to the local import". A validation error (a wrong digest, a bad reference) is not "cannot answer". It fails the call.

Step 3 is a fallback for availability, and it is recorded. Once the tree is pinned to the cached copy, every later call in the tree uses it, even after B comes back. A fresh root asks B again.

The kind run found the bug this ordering fixes, and the fix (8c25af52, "a cached peer/ import never outranks the owner in a new tree") shipped in the same release, v3.161.0. A fresh tree ran a leaf v2 that an earlier tree had imported, while B already held v3.

Delegate mode has no fallback

Step 3 exists only for import. A delegated call needs B to run it, so if B is unreachable the call fails: 502 for a transport error, or 404 if B's lease in A's registry has lapsed. A held pin does not change that.

Home-instance resolution

A playbook imported from B was written against B's catalog. When it calls xc/leaf by a bare name, it means B's xc/leaf, not a same-named playbook that happens to exist on A. With NOETL_CATALOG_REMOTE_CALLS on, home_rewrite turns a bare child path called from a parent whose pinned path is peer/<B>/… into peer/<B>/<child>. It leaves alone anything that already starts with peer/, contains ://, or is a digest. The rewritten name is then a remote reference and gets the caller pin above. In the kind test, the imported peer/<B>/xc/target called xc/leaf, and A pinned noetl://<B>/xc/leaf.

The owner pin: one tree on B per calling root

Delegate mode runs the target on B, and the target can call B's own sub-playbooks. Those must hold still too, across all of A's calls from one root, not just within one delegated execution.

noetl.catalog_remote_origin
  origin_instance  TEXT    ┐ primary key
  origin_root      BIGINT  ┘
  local_root, watermark, pinned_at_ms, created_at

On the first catalog.execute from (A, origin_root), B takes its own watermark at that moment and stores it. The insert uses ON CONFLICT … DO NOTHING followed by a read, so the first writer wins here as well. Every later delegated execution from that pair starts with that pin as an override (pin_override on ExecuteRequest), so B's sub-playbooks resolve as if every call were part of one tree on B.

  • A new root on A gets a fresh pin on B, and sees B's newer versions.
  • The same root id from a different instance gets a different pin. The key includes the instance id, which comes from the caller's signature, not from the request body.
  • A peer never widens B's policy. The override carries the default policy, so a hot-reload rule does not apply to delegated runs.
  • The pin is B's watermark at A's first delegated call, not at A's root start. Nothing aligns the two instances' clocks (17.6).

One root, end to end

This is the kind test's delegate run (noetl/ops ci/kind/e2e_catalog_remote_exec.sh, step 4), written as a timeline. The target calls xc/leaf by a bare name:

 time   A (root R)                           B
 ────   ──────────                           ─
 t0     R starts; Phase-1 watermark on A
 t1     step first: noetl://B/xc/target ──►  no origin pin for (A,R): take B's
        caller pin: target → v1                watermark W1, run target v1;
                                               xc/leaf → v1 (≤ W1)
 t2                                          register target v2 and leaf v2
 t3     step second: same reference      ──►  origin pin (A,R) exists: W1
        caller pin hit: target → v1            run target v1; xc/leaf → v1
 t4     R completes: both calls leaf v1
 t5     new root R2 calls again          ──►  no pin for (A,R2): W2 > v2
        new caller pin: target → v2            target v2; xc/leaf → v2

The import run (step 5) has the same shape on A alone. Both calls ran peer/<B>/xc/target v2 on A, with its leaf home-resolved to peer/<B>/xc/leaf v2, while B registered v3 between them. A fresh root then saw v3, and B ran no execution at all.

Where the pins are, and where they are not

The caller pin and the call row are tables on A (execution_remote_pin, catalog_remote_call). The owner pin and the reverse row are tables on B (catalog_remote_origin, catalog_remote_exec). A child that A imports has its own Phase 1 pin row with reason import. A delegated call adds nothing to A's event log beyond the parent step's events (17.2).