Files
pipewright/docs/changes-for-plugins.md
T

7.4 KiB

Interface changes for plugin packs

Changes made while adding host pools, cross-graph imports, sharding and the batched store. Everything is additive: existing node types, providers, harnesses, sandbox providers, ops.* functions and CLI commands keep working unchanged, except for the two behaviour changes marked (behaviour).

New registry: host providers

  • pipewright.register_host_provider(name, factory) — factory(name, config, project) -> HostProvider. Entry point group: pipewright.hosts. registry.hosts is the fifth registry.
  • pipewright.hosts.HostProvider (in hosts/base.py): implement async create(host_id, state_dir) -> Host and async delete(host). Optional: extend(host, seconds) -> new_expiry, list_remote(), delete_remote(remote), alive(host), capacity(), labels(), kvm(), gpu(), cost_per_hour, and run(host, command, timeout=, stdin=) if hosts are not reached over SSH.
  • pipewright.hosts.vmapi.VMApiHostProvider: base for HTTP VM APIs (bearer secret from a secret ref, retries, per-host SSH config with a pinned host key and ControlMaster).
  • Shipped: static (fixed SSH hosts), fake (tests; host commands are recorded and never run locally), boat (pipewright.contrib.boat, loaded through the entry point; extra boat).

Project file

  • New section hosts: {<pool>: {type, min, max, capacity, reserve, labels, setup, docker_kvm_runtime, idle_shutdown, ttl, extend_margin, budget: {hours, usd}, cost_per_hour, persist, create_retries, create_backoff, create_limit, docker}}. See hosts/pool.py.
  • Project.host_pool(name) -> HostPool (one per Project object, shared by all sandbox pools using it). Project.aclose() drains host pools after sandboxes.
  • Docker sandbox pools gain hosts: <pool> (place containers on a host pool) with cpus, memory, requires: {kvm, gpu, labels, disk}, prefer: [labels], image_source: {build | load | pull}, volumes: {name: mount}. host and hosts are mutually exclusive. These placement keys are excluded from memo identity (moving a sandbox to another host does not invalidate results; changing image does).

Sandboxes

  • pipewright.sandbox.base.LEASE_CONTEXT (ContextVar of (priority, budget)), set by SandboxProvider.lease() around create(). Providers that place sandboxes on host pools use it; create() keeps its signature.
  • SandboxProvider.accounts_vm_hours() -> bool (default capabilities.remote): whether lease time counts as run VM-hours. Return False when something else (a host pool) accounts host time.
  • DockerProvider.docker_argv(*args, host=None) (new optional host), DockerSandbox(..., docker_host=, env=, host_lease=) and DockerSandbox.host (the pool Host or None).
  • Sandbox.reverse(port) -> "host:port" | None (async): an address reachable from inside the sandbox that connects to 127.0.0.1:port on the orchestrator. Default None (use host_address()). Docker sandboxes on host pools implement it with an SSH reverse tunnel (HostPool.reverse(host, port): one ssh -N -R per host and port, plus a relay on the Docker bridge gateway and a best-effort iptables accept for it); the cli harness uses it automatically, so CLI agents on pool hosts reach the logging proxy. Pool-hosted Docker pools accept network: host (no relay; the container uses the loopback end).
  • A plugin that wants a whole host per job can do it without new code: give the docker pool cpus/memory equal to the host's usable capacity.

Graphs: imports and new node types

  • GraphSpec.imports: dict[alias, ImportSpec] with ImportSpec(graph, project, store, run, where); inputs may reference alias:node.port. Graph.import_graph(alias, path, run=..., where=...) returns a handle: handle.node("bucket").port("too_easy"). graph="self" reads this graph's own previous run (re-entrant loops). GraphSpec.base_dir = directory of the graph file.
  • pipewright.imports.expand_imports(spec, project) turns alias:node refs into virtual graph.import source nodes (ids alias:node). Engine.spec is the expanded spec (Engine.source_spec the original). Node ids may now contain : only for these.
  • New node types: store.query (source over stored results; params graph, node, port, run, store, kind, provenance, labels, where, derived_from, limit) and graph.import.
  • map.expr gains an optional key expression (new item key, e.g. payload.name).
  • sink.jsonl gains mode: append | rewrite. (behaviour) The default is append: rows are appended for items not yet written (sidecar <path>.pwindex); rows of items that no longer reach the sink stay. Use mode: rewrite for the old "file = exactly this run" semantics.

Store

  • Writes are buffered and committed in batches (Store.commit() flushes; buffered rows are visible to every Store object on the same path in the same process — they share one connection — and to other processes after the next commit, ≤ 0.5 s or 5000 rows). (behaviour) A second process reading the store mid-run sees writes up to ~0.5 s late.
  • New: Store(path, readonly=True), store.current_run, select_runs(graph, run, exclude) (latest | previous | all | group:<g> | <run id>), group_runs, query(...), descendants(id), roots(id), item_origin(id), resolve_item(id | prefix | key), copy_from(other, ids), memo_preload(sig). The items table has a new run_id column (migrated automatically).

Engine / ops / CLI

  • RunOptions.shard=(i, n) and RunOptions.group; sinks are skipped in shard runs (run once more without --shard to replay from memo and write them). engine.shard_of(key, n).
  • ops.run_graph(..., shard="I/N", group=...), ops.funnel(..., group=...), ops.lineage(..., descendants=, roots=) (each entry now has origin: {run_id, graph}), ops.query(...), ops.hosts(action, pool=, count=, project=, start=). funnel_for_run accepts a list of run ids; imported nodes carry imported_from.
  • Run stats (pw status --json) include hosts: {pool: snapshot}; the final stats are written after the drain, so they include host deletions.
  • CLI: pw run --shard I/N --group G, pw funnel --group G, pw query, pw lineage --roots --descendants, pw hosts list|up|down|orphans. MCP: query, hosts, lineage(descendants, roots), funnel(group), run_graph(shard, group).
  • Expressions: Obj wraps nested values lazily (on attribute/index access, get, values, items); evaluate/eval_item results are unchanged.

Rate limits (shared across processes)

  • Provider rate: accepts shared: true | "<key>" and shared_dir (default ~/.cache/pipewright/rate): the window and the 429 gate live in a SQLite ledger shared by every process using the key. RateLimiter(..., shared=SharedLedger); rate_limiter_from(cfg, name=None, base_dir=None).

Budgets (counters)

  • budgets: {counters: {"rollouts.terra": 60}} in the project file; a node spends it with ctx.count("rollouts.terra", n=1) (NodeContext). Over the limit, that call raises BudgetExceeded: the item is recorded pending (resumed by a later run) while other items and nodes continue. Unlimited counters are tracked too. BudgetTracker(counters=...), BudgetTracker.count(name, n); snapshot() gains counters/counter_limits.

Funnels

  • funnel_for_run adds result per node when the node returned one (sinks: {path, rows, appended, ...}), shown by pw funnel/pw run and in --json.