You are doing an architectural research task — no code changes, just deep reading and reasoned conclusions. Report back in writing.
The big picture
There are three sibling repos in /Users/user_c042661f/Documents/reigh-workspace/:
runpod-lifecycle/ — a small Python package that wraps the RunPod API. Today it exposes pod-lifecycle primitives: launch(), Pod.wait_ready(), Pod.exec_ssh(), Pod.open_ssh_client(), Pod.terminate(), plus a CLI.
vibecomfy/ — a ComfyUI-runtime tool. Inside it lives scripts/runpod_runner.py (~1.2k lines), which is a generic "ship a repo to a freshly-launched pod, run a script, pull artifacts back" harness — plus several callers (runpod_validate.py, runpod_model_matrix.py, runpod_corpus_matrix.py, runpod_matrix_plan.py, runpod_matrix_remote.py). There's also a thin CLI wrapper at vibecomfy/commands/runpod.py.
Astrid/ — a file-based toolkit-of-executors-and-orchestrators (see its README, AGENTS.md, and especially project.md). The user wants RunPod to be available to any Astrid orchestrator, not just VibeComfy. Astrid has a pack convention at astrid/packs/external/ — e.g. external/vibecomfy/ declares executor.yaml + run.py + STAGE.md.
The architectural question I want answered
Right now, the "shipping recipe" (runpod_runner.py) lives inside vibecomfy. The user's plan in Astrid/project.md is to expose RunPod as an Astrid-level capability — external.runpod.{provision,run,teardown} — that any orchestrator (e.g. lora_train, scene_render) can use, and which vibecomfy itself eventually consumes rather than owns. I've already suggested the cleanest move is: push the generic parts of runpod_runner.py down into runpod-lifecycle, and have both vibecomfy and Astrid be peer consumers. I want you to pressure-test that and figure out exactly where the boundaries should fall.
What I want you to investigate
Part A — VibeComfy side: what's actually generic vs vibecomfy-specific?
Read these files end-to-end:
/Users/user_c042661f/Documents/reigh-workspace/vibecomfy/scripts/runpod_runner.py (~1.2k lines, the main thing)
Assistant
I'll dig into all three repos and report back. Let me start by reading the key files in parallel.
Assistant
Now let me read the lifecycle package files and the Astrid project.md plan in parallel.
Assistant
The task tool reminder doesn't apply here - this is an architectural research task with a single deliverable (the writeup). Continuing reads.
Assistant
Excellent. Now let me read Astrid's project.md, the existing pack, the orchestrator/executor contracts, and the other matrix scripts.
Assistant
The reminder is not applicable. Continuing.
Assistant
Now Astrid core - executor/orchestrator contracts and how they share state.
Assistant
Now let me read the orchestrator runner, schema, and verify checks to understand artifact passing and repeat.until/nested.
Assistant
Now let me look at orchestrate DSL (for repeat.until / nested), the orchestrator schema, and verify checks. Also check if there's any existing remote/sandboxed exec.
Assistant
Now let me check verify checks, plan/gate, and search for existing "runpod" references in Astrid (any existing concept of remote/sandbox execution).
Assistant
Reminder not applicable. Now let me look at the remaining vibecomfy scripts and check VibeComfy2.md if exists.
Assistant
Excellent. I have enough now. Let me peek at the corpus_matrix script briefly (the heavy one that uses run_pod_detached) and at pyproject.toml to confirm packaging info.
Assistant
Reminder still not applicable. I now have enough context. Let me also briefly check task plan for produces / how attested step outputs are gated, and confirm there's no orchestration-level try/finally idiom.
/Users/user_c042661f/Documents/reigh-workspace/vibecomfy/docs/runpod.md and docs/runpod_smoke.md for intent
For each major piece in runpod_runner.py — PodGuard, signal handlers, upload_dir, _upload_tarball, _build_upload_tarball, run_pod, run_pod_detached, _upload_remote_script, _download_artifacts, _build_artifact_manifest, _collect_outputs, _collect_run_metadata, _collect_watchdogs, _collect_remote_logs, _write_artifact_report, _print_detached_summary, exclude sets, env-var conventions, REMOTE_ROOT — classify it as:
GENERIC (belongs in runpod-lifecycle's lifted runner)
VIBECOMFY-SPECIFIC (stays in vibecomfy)
MIXED (generic core, vibecomfy-specific defaults/format) — and say exactly where the split should fall
Watch especially for:
Things that look generic but secretly assume the VibeComfy filesystem layout (out/corpus_matrix/results.tsv, out/runs/*/watchdog.json, out/runs/*/metadata.json)
Things that look vibecomfy-specific but are really just configurable defaults (REMOTE_ROOT, the exclude set, env-var names)
What the watchdog/timeout semantics need from the caller
How signal handling interacts with being called from a long-running parent process (Astrid orchestrator)
The detached-poll machinery — is the poll-loop generic, or is what it parses out of stdout vibecomfy-specific?
Part B — runpod-lifecycle side: what surface does it need to grow?
Does Pod already support stateless reattach by pod_id? (i.e. can you reconstruct a usable Pod object given only the id, without holding the launch coroutine's state in memory?) If not, what would it take to add? This is critical because Astrid executors are separate processes — a provision executor exits, then later an exec executor needs to talk to the same pod.
Is there already an events/streaming API (events.py)? Could the upload-progress heartbeats and detached-poll output piggyback on it, or is it a different concern?
What does the config.py / RunPodConfig.from_env surface look like? Does the env-var convention already accept consumer prefixes, or is it baked to one prefix?
Look at cli.py — what commands exist? If we lift the runner, should the lifecycle CLI grow run / ship / exec subcommands, or is that out of scope?
Part C — Astrid side: what does the pack shape need to be?
Read:
/Users/user_c042661f/Documents/reigh-workspace/Astrid/project.md (the plan)
/Users/user_c042661f/Documents/reigh-workspace/Astrid/AGENTS.md and README.md
/Users/user_c042661f/Documents/reigh-workspace/Astrid/astrid/packs/external/vibecomfy/{executor.yaml,run.py,STAGE.md} — full pattern example
/Users/user_c042661f/Documents/reigh-workspace/Astrid/astrid/packs/external/fal_foley/ and moirae/ — for variation in patterns
The orchestrator/executor contracts: glance at astrid/core/executor/, astrid/core/orchestrator/, astrid/contracts/, astrid/verify/ — enough to understand how artifacts flow between steps (consumes/provides), how produces are gate-verified, and how repeat.until / nested work
astrid/docs/creating-tools.md if present
astrid/docs/templates/{executor,orchestrator,element}/ if present
Answer:
How do separate executor steps share state in Astrid? (artifact files only? a pod-handle JSON artifact is the right shape?)
What does the gate/verify layer expect — does the runner's existing manifest.json shape line up, or does Astrid have a different schema?
For the provision → exec → teardown pattern: does Astrid have an existing idiom for "guaranteed teardown even on failure" (try/finally at the orchestrator level)? Or does that have to live inside a composite executor?
Should there be one pack with three sibling executors (like vibecomfy.run + vibecomfy.validate in one executor.yaml), or three folders? Check how existing multi-executor packs are laid out.
Where do long-running detached jobs fit? Astrid likely assumes executors are subprocesses that return — does the detached-poll case need an orchestrator-level pattern instead?
The watchdog problem: the in-process max-runtime watchdog in PodGuard dies when the provision executor exits. What's the right Astrid-idiomatic replacement? (e.g. a astrid doctor sweep that finds stale pod_handle.json files past their terminate_at and force-terminates? a separate long-lived watchdog daemon? a flag that says "the calling orchestrator owns the timer"?)
Does Astrid already have any concept of remote/sandboxed execution, or is this the first one? Search for it.
Part D — Synthesis
Pull it together into a written architectural recommendation:
Three-layer diagram in prose: what's in runpod-lifecycle (post-lift), what's in vibecomfy (post-shrink), what's in Astrid/packs/external/runpod/. Be concrete — name the modules/files.
The lifecycle public API after the lift: what new functions/classes does runpod-lifecycle expose? Sketch the signatures.
The Astrid pack shape: file layout, executor ids, what each one's consumes/provides looks like, where the composite "one-shot ship & run" lives.
The migration order: what needs to ship first, what depends on what, what risks are there (multi-repo coordination, version pinning, backward compat for existing vibecomfy callers).
Open questions / things you couldn't answer from reading — call these out explicitly so I know what to come back to the user about.
How to report
Plain prose with headings, no code blocks longer than ~10 lines, no implementation. Aim for ~800–1500 words. Don't pad — terse but complete. If you find anything that contradicts my framing above, say so directly; I'd rather be corrected than agreed with.
Do not write any files. Do not edit anything. Just read and reason.
Confirmed: discovery.get_pod(pod_id, config) already does stateless reattach by id. No finally/teardown idiom at the plan level. I have everything I need.
RunPod Lift Architecture — research findings
Up front: where my framing held up and where it didn't
The "lift the generic core down into runpod-lifecycle, make vibecomfy and Astrid peer consumers" plan is sound. Two important corrections though:
runpod-lifecycle is already further along than the framing implied.discovery.get_pod(pod_id, config) is a stateless reattach-by-id that returns a fully usable Pod. terminate(pod_id, api_key) works without a Pod handle at all. EventHooks(on_state_change, on_error) exists for streaming. So the cross-process pod-handle problem is mostly solved — what's missing is upload/exec/download/manifest, not reattach.
Astrid has no "composite executor that wraps try/finally" idiom. Executors are subprocesses that return; orchestrators are plans of steps (code/attested/nested) with repeat.until wrappers; there is no on_failure/finally step kind in astrid/core/task/plan.py or in the DSL (astrid/orchestrate/dsl.py). This is the single biggest design constraint on the lift — guaranteed teardown has to be solved either inside a single "one-shot" composite executor, or by a sweeper, not by orchestrator semantics that don't exist.
Part A — what's generic vs vibecomfy-specific in runpod_runner.py
install_signal_handlers / _clear_current_task_cancellation — generic loop SIGINT/SIGTERM glue. Worth keeping as opt-in (Astrid orchestrators won't want their parent's signal handlers stomped — see watchdog discussion below).
should_skip, _iter_upload_files, _estimate_upload_payload, _preflight_upload_disk, _build_upload_tarball, _upload_tarball — the entire upload mechanism (sftp_walk + tarball modes). The only vibecomfy-specific bit is the /tmp/vibecomfy-upload.tar.gz filename, easily parameterised.
upload_dir — generic SFTP-walk uploader. The should_skip(child, ROOT, exclude_set) call hard-codes ROOT; fix by passing root explicitly.
_upload_remote_script — generic; remote path /tmp/vibecomfy-remote-run.sh is the only brand.
_download_artifacts — core download flow (archive a remote dir, sftp.get, tar extract) is generic. The actual paths it cares about (out/corpus_matrix output out/runs) are vibecomfy-specific defaults.
run_pod and run_pod_detached — the shape is generic (launch → wait_ready → gpu_check → upload → exec → poll → download → terminate). The watchdog wrapping (PodGuard) is generic. The polling loop body is mostly generic; what's vibecomfy-specific is the embedded status_command heredoc.
VIBECOMFY-SPECIFIC — stays in vibecomfy:
_runpod_config_kwargs — entirely vibecomfy env var conventions (VIBECOMFY_RUNPOD_STORAGE, VIBECOMFY_RUNPOD_GPU, the disk-size overrides). This is just how vibecomfy populates a RunPodConfig; the lifecycle config already accepts **overrides, so this stays caller-side.
REMOTE_ROOT = "/workspace/vibecomfy" — vibecomfy-specific default, but the value itself is just a path. Parameterise to caller.
DEFAULT_UPLOAD_EXCLUDES — has vibecomfy-specific entries (workflow_corpus, custom_nodes, vendor). The concept of an exclude set is generic; the contents aren't.
The detached launch_command shell snippet — references out/corpus_matrix/exit_code as the sentinel file. The pattern "write rc to a sentinel file" is generic; the path is vibecomfy.
The status_command heredoc inside the poll loop — entirely vibecomfy. results.tsv, ready_results.tsv, out/corpus_matrix, --- MEDIA --- find filter, vibecomfy-remote-live.log. This is genuinely report-format-specific.
_parse_tsv, _image_info/_png_info, _collect_outputs, _collect_run_metadata, _collect_watchdogs, _collect_remote_logs, _build_artifact_manifest, _write_artifact_report, _print_detached_summary, _finalize_artifacts, _count_failures, _extract_prompt_id — all of this is vibecomfy artifact-format code. It reads vibecomfy's out/runs/*/metadata.json, vibecomfy's out/runs/*/watchdog.json, vibecomfy's results.tsv schema, vibecomfy's output/ images. The manifest.json/report.md shape is invented for this script; it's not Astrid-aligned (see Part C).
MIXED — needs a careful split:
PodGuard — the launch/terminate wrapper is generic. The in-process watchdog (_terminate_after) is generic but relies on the calling process staying alive — which is exactly what breaks in the Astrid-executor case. Lift PodGuard but rename the watchdog "in-process max-runtime", and stamp a terminate_at field into a handle file the lifecycle returns. The handle-based watchdog enforcement is a Part D follow-up.
run_pod / run_pod_detached — the orchestration shape is generic, but in their current form they hard-code ROOT, REMOTE_ROOT, the vibecomfy launch_command, the vibecomfy status_command, and the vibecomfy artifact-collection path. Lift them as ship_and_run(...) / ship_and_run_detached(...) taking explicit local_root, remote_root, remote_script, excludes, progress_pattern, and artifact_paths. Vibecomfy keeps a thin wrapper that injects its defaults.
_parse_detached_exit — looks generic (parses --- EXIT --- sentinel from stdout) but it only works because vibecomfy's own poll-loop script writes that sentinel. Pair with a generic "poll-loop emits structured status lines" convention. The lifecycle should ship a default poll script that emits === POLL ts === / --- EXIT ---; vibecomfy can override and still parse with the same helper.
The cleanest split is: lift everything up to and including_download_artifacts (i.e. extract a .tar.gz to a local dir, return its path); leave everything that reads and summarises the extracted contents in vibecomfy.
Stateless reattach by id: already there.discovery.get_pod(pod_id, config) returns a working Pod that lazily fetches SSH details on first use (_ensure_ssh_details). No coroutine state required — perfect for the Astrid cross-executor case. The only thing it doesn't preserve is ram_tier / storage_volume, but those are only used by check_storage_health; doesn't matter for exec/upload/download.
Events API: exists but is the wrong primitive for upload heartbeats / poll-loop output.EventHooks is for state transitions (PROVISIONING/STARTING/READY/...). The upload progress lines and detached poll snapshots are essentially log streams. They should be plain stdout (the current behavior) or a separate callback parameter. Don't overload PodEvent.
RunPodConfig.from_env: hard-coded RUNPOD_* prefix. It doesn't accept a consumer prefix. Vibecomfy currently overrides via from_env(**kwargs) rather than via env vars (in _runpod_config_kwargs), which is the right pattern. The package shouldn't grow VIBECOMFY_* / ASTRID_* env var support — that's caller-side. The RUNPOD_* env vars stay the lifecycle source of truth.
CLI scope. Today cli.py has list / status / terminate / find-orphans / gpu-types. After the lift, the right additions are:
runpod-lifecycle launch [--name ...] [--detach] — launch + print pod_id + handle path; exit. Detached because Astrid provision is a one-shot.
runpod-lifecycle run <pod_id> --script <file> — the one-shot exec wrapper.
I would not lift the all-in-one ship_and_run to the CLI surface initially — orchestrators compose primitives, and a one-shot CLI verb invites people to skip the orchestrator. Library only at first.
Pod needs one new method: upload_path(local, remote, *, mode='auto', excludes=(), on_progress=None) (covering sftp_walk + tarball) and . Currently is the escape hatch and works fine — but raising these to first-class API lets the runner code live in one place and lets Astrid get them for free.
Part C — what the Astrid pack needs to look like
From reading astrid/core/executor/runner.py, astrid/core/orchestrator/runner.py, astrid/orchestrate/dsl.py, astrid/core/task/plan.py, the three existing external packs, and docs/creating-tools.md:
Inter-step state = artifact files only. There is no shared in-memory context across executor invocations. Executors are spawned as subprocesses (subprocess.run in _run_external_executor), get their inputs as --input key=value and outputs through {out} / path_template placeholders, and produce files in out/. A pod_handle.json artifact written by provision and consumed by exec/teardown is the only honest pattern.
Gate/verify schema is Check-based, not a fixed manifest shape.astrid/verify/checks.py registers file_nonempty, json_file, json_schema, etc.; each produces declares a (path, check) pair. The runner's invented manifest.json schema is not what Astrid expects — Astrid wants per-output checks per step (e.g. provision produces pod_handle.json checked by json_schema({"required":["pod_id","ssh","terminate_at"]})). Keep the rich runner manifest as a debug artifact but don't make it the gate signal.
Guaranteed teardown does not exist as an orchestrator primitive. Reviewed plan.py (on_exhaust: escalate|fail), dsl.py, gate.py. There is no finally step, no on_failure hook, no cleanup lane. Three honest options, in order of preference:
(a) Composite executor external.runpod.session that takes a remote script + paths and internally does provision→exec→download→terminate with a Python try/finally. This is exactly what run_pod_detached already does. Astrid's contract is satisfied because the executor either succeeds or fails — and in either case the pod is gone by the time it returns. This is what vibecomfy needs today.
(b) Separate provision / exec / teardown executors for cases where you genuinely want exec/judge/refine cycles against the same pod (the repeat.until(passes_judge) pattern in scene_render). Plus a sweeper.
(c) Both. Ship the composite first; ship the split executors when an orchestrator actually needs to reuse a pod across steps.
RunResult carries exit_code, pod_id, stdout, stderr. DetachedRunResult adds artifact_dir: Path | None, terminated: bool. Neither produces a manifest.json — the caller (vibecomfy or Astrid) writes its own.
Pod.upload_path(...) and Pod.download_archive(...) wrap the lifted shipping helpers so callers that don't want the full ship_and_run can compose.
Astrid pack shape
executor.yaml (sketched, one JSON file with 4 entries):
external.runpod.provision — inputs: [gpu_type?, storage_name?, max_runtime_seconds?, name_prefix?]; outputs: [pod_handle (json_file, default {out}/pod_handle.json)]. run.py provision calls lifecycle.launch(config), awaits wait_ready, writes {pod_id, ssh, name, terminate_at, config_snapshot} to the handle path. Does not terminate.
external.runpod.exec — inputs: [pod_handle (file, required), local_root (dir, optional), remote_root (string), remote_script (file or string), timeout, upload_mode, excludes]; outputs: [exec_result (json_file), artifact_dir (dir)]. run.py exec reads the handle, calls discovery.get_pod(pod_id, config), runs ship_and_run_detached with terminate=False (a new flag — neither current run_pod nor run_pod_detached keeps the pod alive after exit, that needs to be added to the lifted runner).
external.runpod.session — composite. inputs: [local_root, remote_root, remote_script, timeout, upload_mode, excludes, max_runtime_seconds, gpu_type?, storage_name?]; outputs: [exec_result, artifact_dir]. Pure ship_and_run_detached. Guarantees teardown via Python try/finally. This is the one vibecomfy and lora_train should use day-1. The split provision/exec/teardown is for scene_render's repeat.until(passes_judge) per-shot loop, if it needs to keep the pod warm across iterations (open question — see below).
run.py is a thin argparse dispatcher (same shape as vibecomfy/run.py).
Migration order
v0.2 of runpod-lifecycle — lift PodGuard, UploadHeartbeat, shipping helpers, ship_and_run/ship_and_run_detached. Add Pod.upload_path/download_archive. Critically: run_pod in vibecomfy stays a working facade by re-importing from the lifecycle package. No behavior change in vibecomfy at this stage. Ship to PyPI/git, pin in vibecomfy.
Shrink vibecomfy — replace local run_pod/run_pod_detached with thin wrappers that call the lifecycle versions and post-process the downloaded archive into the manifest. runpod_validate.py/runpod_model_matrix.py/runpod_corpus_matrix.py keep importing run_pod/run_pod_detached and REMOTE_ROOT/DEFAULT_UPLOAD_EXCLUDES from the same module — no caller change.
Build the Astrid pack — astrid/packs/external/runpod/ with session first, then provision/exec/teardown. Wire lora_train (Phase 2 in project.md) onto session.
Add the sweep — astrid/packs/external/runpod/sweep.py + integrate with astrid doctor.
Risks:
Multi-repo coordination: runpod-lifecycle is consumed today via a sibling-checkout path (VIBECOMFY_RUNPOD_LIFECYCLE_ROOT in runpod_runner.py:50 and vibecomfy/commands/runpod.py:14). Astrid will need the same dance, or a real pip install. Recommend pinning by git tag (v0.2.0) once published.
Backward compat: vibecomfy callers use DEFAULT_UPLOAD_EXCLUDES and REMOTE_ROOT from runpod_runner. Keep those as module constants in the post-shrink file.
Versioning: bump runpod-lifecycle to 0.2.0 (breaking only by addition); vibecomfy pins explicitly. Astrid pins via its own requirements.txt.
Open questions
Does scene_render's per-shot repeat.until(passes_judge) loop want a hot pod across iterations, or is each shot a fresh session? If hot, you genuinely need provision/exec/teardown split + the sweeper. If cold (each shot reprovisions), session is enough and the split executors can wait. My read of project.md says hot — but only because per-shot reprovisioning would be wasteful, not because the doc specifies it.
Where does pod_handle.jsonlive across executor steps? Astrid resolves output paths through {out} and path_template. Confirm with the user whether the convention is "the provision executor's {out}/pod_handle.json is read by exec via --input pod_handle=..." — that's what the runner code (_placeholder_values, _request_values) supports, but I want explicit confirmation that's the intended shape rather than e.g. a project-scoped artifact registry.
astrid doctor integration of the sweeper. Doctor today is read-only diagnostics (run_checks in astrid/doctor.py). Sweeping (= actually terminating pods) is mutation. Probably wants its own verb (astrid runpod sweep or astrid orchestrators run external.runpod.sweep), with doctor merely reporting stale handles. Confirm intent.
Should session produce the vibecomfy-style manifest.json + report.md at all? Today those are vibecomfy's artifact-collection format. For Astrid's lora_train and scene_render, the natural produces are checkpoint paths and clip files, not a manifest.json summarising TSV rows. I'd let session produce only exec_result.json (exit_code, artifact_dir, pod_id, terminated) and let each consuming pack post-process the artifact dir into its own gate-checked outputs. But that's a call for the user.
The corpus_matrix scope.runpod_corpus_matrix.py is 871 lines and tightly couples script generation to vibecomfy's registry. None of that is generic. Confirmed it stays in vibecomfy unchanged — but worth flagging that the poll-loop status_command it generates is fundamentally a "vibecomfy-shaped progress probe". If Astrid orchestrators want progress visibility into a detached run, they'll need their own equivalent — likely just is enough.
Pack layout — one folder, three (or four) executors. The vibecomfy pack already declares two executors (external.vibecomfy.run + external.vibecomfy.validate) in a single executor.yaml (a JSON array under executors). That is the right precedent. Concretely:
session: consumes local_root + remote_script; provides exec_result + artifact_dir. (Internally provisions + execs + tears down — no pod_handle escapes.)
Detached/long-running. Astrid executors are subprocesses; the parent (orchestrator runner) waits on them. A 4-hour training run is fine under this model — the executor just blocks. The Python-side asyncio and the polling loop in run_pod_detached are independent of Astrid's process model. There's no reason to invent an "async executor" — session just runs synchronously from Astrid's POV.
The watchdog problem. The PodGuard watchdog dies when the provision executor exits — confirmed. Fix:
The pod_handle.json written by provision includes "terminate_at": "<ISO timestamp>".
Add astrid.packs.external.runpod.sweep (a command, not an executor) that lists all pod_handle.json under runs/ and astrid-projects/, plus calls discovery.list_pods with the pack's name_prefix, and terminates anything past its terminate_ator without a corresponding live handle file. Wire it into astrid doctor (which already runs registry checks via astrid/doctor.py) and ship a find-orphans shortcut.
For the composite session executor, the watchdog can live in-process (it's the same model run_pod uses today and works because the executor blocks until done).
For provision → exec → teardown flows, the orchestrator's repeat.until(...) max_iterations + the sweep is the backstop.
No existing remote/sandboxed execution concept in Astrid. Grep for "runpod|remote.*exec|sandbox" in astrid/ finds nothing except a passing reference in two docs files. This is the first one, which is good — no legacy shape to honour.