7.4 KiB
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.hostsis the fifth registry.pipewright.hosts.HostProvider(inhosts/base.py): implementasync create(host_id, state_dir) -> Hostandasync delete(host). Optional:extend(host, seconds) -> new_expiry,list_remote(),delete_remote(remote),alive(host),capacity(),labels(),kvm(),gpu(),cost_per_hour, andrun(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; extraboat).
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}}. Seehosts/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) withcpus,memory,requires: {kvm, gpu, labels, disk},prefer: [labels],image_source: {build | load | pull},volumes: {name: mount}.hostandhostsare mutually exclusive. These placement keys are excluded from memo identity (moving a sandbox to another host does not invalidate results; changingimagedoes).
Sandboxes
pipewright.sandbox.base.LEASE_CONTEXT(ContextVar of(priority, budget)), set bySandboxProvider.lease()aroundcreate(). Providers that place sandboxes on host pools use it;create()keeps its signature.SandboxProvider.accounts_vm_hours() -> bool(defaultcapabilities.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 optionalhost),DockerSandbox(..., docker_host=, env=, host_lease=)andDockerSandbox.host(the poolHostor None).Sandbox.reverse(port) -> "host:port" | None(async): an address reachable from inside the sandbox that connects to 127.0.0.1:porton the orchestrator. Default None (usehost_address()). Docker sandboxes on host pools implement it with an SSH reverse tunnel (HostPool.reverse(host, port): onessh -N -Rper host and port, plus a relay on the Docker bridge gateway and a best-effortiptablesaccept for it); thecliharness uses it automatically, so CLI agents on pool hosts reach the logging proxy. Pool-hosted Docker pools acceptnetwork: 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/memoryequal to the host's usable capacity.
Graphs: imports and new node types
GraphSpec.imports: dict[alias, ImportSpec]withImportSpec(graph, project, store, run, where); inputs may referencealias: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)turnsalias:noderefs into virtualgraph.importsource nodes (idsalias:node).Engine.specis the expanded spec (Engine.source_specthe 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) andgraph.import. map.exprgains an optionalkeyexpression (new item key, e.g.payload.name).sink.jsonlgainsmode: append | rewrite. (behaviour) The default isappend: rows are appended for items not yet written (sidecar<path>.pwindex); rows of items that no longer reach the sink stay. Usemode: rewritefor the old "file = exactly this run" semantics.
Store
- Writes are buffered and committed in batches (
Store.commit()flushes; buffered rows are visible to everyStoreobject 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). Theitemstable has a newrun_idcolumn (migrated automatically).
Engine / ops / CLI
RunOptions.shard=(i, n)andRunOptions.group; sinks are skipped in shard runs (run once more without--shardto 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 hasorigin: {run_id, graph}),ops.query(...),ops.hosts(action, pool=, count=, project=, start=).funnel_for_runaccepts a list of run ids; imported nodes carryimported_from.- Run stats (
pw status --json) includehosts: {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:
Objwraps nested values lazily (on attribute/index access,get,values,items);evaluate/eval_itemresults are unchanged.
Rate limits (shared across processes)
- Provider
rate:acceptsshared: true | "<key>"andshared_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 withctx.count("rollouts.terra", n=1)(NodeContext). Over the limit, that call raisesBudgetExceeded: the item is recordedpending(resumed by a later run) while other items and nodes continue. Unlimited counters are tracked too.BudgetTracker(counters=...),BudgetTracker.count(name, n);snapshot()gainscounters/counter_limits.
Funnels
funnel_for_runaddsresultper node when the node returned one (sinks:{path, rows, appended, ...}), shown bypw funnel/pw runand in--json.