omnirun 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {omnirun-0.2.0 → omnirun-0.2.1}/DESIGN.md +7 -4
  2. {omnirun-0.2.0 → omnirun-0.2.1}/PKG-INFO +1 -1
  3. {omnirun-0.2.0 → omnirun-0.2.1}/TESTING.md +23 -10
  4. {omnirun-0.2.0 → omnirun-0.2.1}/pyproject.toml +1 -1
  5. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/__init__.py +1 -1
  6. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/colab.py +2 -2
  7. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/kaggle.py +38 -16
  8. omnirun-0.2.1/src/omnirun/backends/tarsafe.py +38 -0
  9. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/bootstrap.py +28 -2
  10. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_bootstrap.py +32 -0
  11. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_kaggle.py +43 -0
  12. omnirun-0.2.1/tests/test_tarsafe.py +53 -0
  13. {omnirun-0.2.0 → omnirun-0.2.1}/.envrc +0 -0
  14. {omnirun-0.2.0 → omnirun-0.2.1}/.github/workflows/checks.yml +0 -0
  15. {omnirun-0.2.0 → omnirun-0.2.1}/.github/workflows/ci.yml +0 -0
  16. {omnirun-0.2.0 → omnirun-0.2.1}/.github/workflows/publish.yml +0 -0
  17. {omnirun-0.2.0 → omnirun-0.2.1}/.gitignore +0 -0
  18. {omnirun-0.2.0 → omnirun-0.2.1}/.python-version +0 -0
  19. {omnirun-0.2.0 → omnirun-0.2.1}/AGENTS.md +0 -0
  20. {omnirun-0.2.0 → omnirun-0.2.1}/CLAUDE.md +0 -0
  21. {omnirun-0.2.0 → omnirun-0.2.1}/README.md +0 -0
  22. {omnirun-0.2.0 → omnirun-0.2.1}/flake.lock +0 -0
  23. {omnirun-0.2.0 → omnirun-0.2.1}/flake.nix +0 -0
  24. {omnirun-0.2.0 → omnirun-0.2.1}/main.py +0 -0
  25. {omnirun-0.2.0 → omnirun-0.2.1}/research/colab-kaggle.md +0 -0
  26. {omnirun-0.2.0 → omnirun-0.2.1}/research/gpu-marketplaces.md +0 -0
  27. {omnirun-0.2.0 → omnirun-0.2.1}/research/launcher-landscape.md +0 -0
  28. {omnirun-0.2.0 → omnirun-0.2.1}/research/ml-job-queues.md +0 -0
  29. {omnirun-0.2.0 → omnirun-0.2.1}/research/slurm-ssh.md +0 -0
  30. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/__init__.py +0 -0
  31. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/base.py +0 -0
  32. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/jobdir.py +0 -0
  33. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/local.py +0 -0
  34. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/marketplace.py +0 -0
  35. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/runpod.py +0 -0
  36. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/slurm.py +0 -0
  37. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/ssh.py +0 -0
  38. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/thunder.py +0 -0
  39. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/backends/vast.py +0 -0
  40. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/chooser.py +0 -0
  41. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/cli.py +0 -0
  42. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/config.py +0 -0
  43. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/daemon.py +0 -0
  44. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/execlayer/__init__.py +0 -0
  45. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/execlayer/base.py +0 -0
  46. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/execlayer/local.py +0 -0
  47. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/execlayer/ssh.py +0 -0
  48. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/models.py +0 -0
  49. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/queue.py +0 -0
  50. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/repo.py +0 -0
  51. {omnirun-0.2.0 → omnirun-0.2.1}/src/omnirun/store.py +0 -0
  52. {omnirun-0.2.0 → omnirun-0.2.1}/tests/__init__.py +0 -0
  53. {omnirun-0.2.0 → omnirun-0.2.1}/tests/conftest.py +0 -0
  54. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_chooser.py +0 -0
  55. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_cli.py +0 -0
  56. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_colab.py +0 -0
  57. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_local_backend.py +0 -0
  58. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_marketplaces.py +0 -0
  59. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_queue.py +0 -0
  60. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_repo.py +0 -0
  61. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_slurm.py +0 -0
  62. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_ssh_backend.py +0 -0
  63. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_ssh_exec.py +0 -0
  64. {omnirun-0.2.0 → omnirun-0.2.1}/tests/test_store.py +0 -0
  65. {omnirun-0.2.0 → omnirun-0.2.1}/uv.lock +0 -0
@@ -282,10 +282,13 @@ Worker access to private repos — **no git credentials ever leave the laptop**:
282
282
  bundle base64 inside the kernel's `run.py`** (next to the base64 bootstrap) — *not* a
283
283
  dataset. The old dataset approach 409'd every kernel that referenced a still-processing
284
284
  dataset (a systematic race) and needed a create/delete lifecycle; embedding removes
285
- both. A size guard (`MAX_EMBED_B64`, 40 MiB, covering bundle + env together) rejects
286
- oversized repos, so this suits code-sized repos (data is never shipped jobs fetch
287
- their own). The bootstrap clones/fetches from the bundle into the object store. In the
288
- public-repo case no bundle is embedded, so the ceiling is a non-issue.
285
+ both. A size guard (`KAGGLE_MAX_SOURCE_BYTES`, ~1 MiB, measuring the whole `run.py`
286
+ kernel source embedded bootstrap + bundle + env against Kaggle's real push limit,
287
+ overridable per backend via `max_source_bytes`) rejects oversized pushes early with a
288
+ size-naming error instead of an opaque Kaggle-side failure, so this suits code-sized
289
+ repos (data is never shipped — jobs fetch their own). The bootstrap clones/fetches from
290
+ the bundle into the object store. In the public-repo case no bundle is embedded, so the
291
+ ceiling is a non-issue.
289
292
 
290
293
  This keeps the invariant intact: a public clone needs no credentials, and private repos
291
294
  still never touch origin from the worker. What changed is that public-repo workers now
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omnirun
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Run jobs from your repo anywhere: Slurm over SSH, any SSH box, Kaggle, Colab, or marketplace GPUs
5
5
  Author-email: Dmitrii Mukhutdinov <flyingleafe@gmail.com>
6
6
  License: MIT
@@ -116,15 +116,27 @@ bootstrap script — there is **no per-job dataset** anymore. This replaced a
116
116
  dataset-based design that hit a systematic **409** (Kaggle rejects a kernel
117
117
  referencing a still-processing dataset). Consequence: kaggle no longer creates or
118
118
  deletes any datasets; nothing worker-side to reap. Only caveat is bundle size — a
119
- code-only repo bundle is well under the embed cap; a repo with large committed
120
- blobs will be rejected client-side before push.
121
-
122
- **Newly added (unit-tested, NOT yet live-verified):** for a **public** repo the
123
- kernel now clones the repo directly over its own internet connection and no bundle
124
- is embedded (`repo.remote_clone_plan` gates on public + reachable). Kaggle also now
125
- injects a gitignored `<repo>/.env` (base64-embedded as `ENV_B64`, decoded to a 0600
126
- file and sourced) parity with Colab. Both paths pass unit tests; a live Kaggle
127
- (and Colab) job against a public repo has not been re-run yet.
119
+ code-only repo bundle is well under the source cap; a repo with large committed
120
+ blobs is rejected client-side before push (see the measured cap below).
121
+
122
+ **Public-repo direct clone — LIVE-VERIFIED (this session).** A CPU kernel was
123
+ submitted against `github.com/flyingleafe/omnirun` (public) at the pushed master
124
+ tip with `env=none`: the worker ran `git clone --bare` over its own connection,
125
+ checked out the exact sha (`Preparing worktree (detached HEAD 6fcedf0)`
126
+ `CLONE OK cwd=…/.trees/6fcedf04a860`, `has_pyproject=True`), no bundle embedded,
127
+ and `proof.txt` was pulled back. So a **public repo of any size** runs on Kaggle,
128
+ unconstrained by the source cap. Kaggle also injects a gitignored `<repo>/.env`
129
+ (base64 `ENV_B64` → 0600 file → sourced) — unit-tested, parity with Colab.
130
+
131
+ **Kernel-source cap — MEASURED (this session).** Pushing `run.py` payloads of
132
+ increasing size to the kernels API: `<=1 MiB` (1,048,570 B) **accepted**,
133
+ `>=1.1 MiB` **rejected with HTTP 400** — so Kaggle's limit is **1 MiB**. The
134
+ pre-submit guard (`KAGGLE_MAX_SOURCE_BYTES = 1 MiB`, override via
135
+ `max_source_bytes`) now measures the full `run.py` (bootstrap + any bundle + any
136
+ `.env`) against this and fails early naming size, instead of the old 40 MiB
137
+ `MAX_EMBED_B64` guard that let 1–40 MiB pushes fail opaquely on Kaggle's side.
138
+ (Aside: the current kaggle client exposes `kernels_delete(ref, no_confirm=True)`,
139
+ used here to clean up the probe kernels — a future `gc`/`cancel` could use it.)
128
140
 
129
141
  - Provide: API token at `~/.config/kaggle/kaggle.json` (kaggle.com → Settings →
130
142
  Create New Token) or `KAGGLE_USERNAME`/`KAGGLE_KEY` env vars. The account
@@ -202,7 +214,8 @@ module.
202
214
 
203
215
  **Kaggle** (`src/omnirun/backends/kaggle.py`) — CONFIRMED LIVE (P100 job ran; output pulled)
204
216
  - [x] Bundle delivery (private/unpushed repo): **embedded base64 in `run.py`**, no dataset — sidesteps the 409 the old dataset design hit. `dataset_create_new`/`dataset_delete` are no longer used.
205
- - [ ] Public-repo **direct clone** (worker `git clone` over its own connection, no bundle) — unit-tested via `repo.remote_clone_plan`; not yet run live on Kaggle.
217
+ - [x] Public-repo **direct clone** (worker `git clone` over its own connection, no bundle) — **LIVE-VERIFIED**: CPU job cloned `flyingleafe/omnirun` at master tip, ran in the worktree, `proof.txt` pulled.
218
+ - [x] Kernel-source push cap — **MEASURED**: 1 MiB (≤1 MiB accepted, ≥1.1 MiB → HTTP 400); `KAGGLE_MAX_SOURCE_BYTES` guard set to match, overridable via `max_source_bytes`.
206
219
  - [ ] `.env` injection (`ENV_B64` embedded → 0600 file → sourced) — unit-tested; not yet run live on Kaggle.
207
220
  - [x] `kernels_status` response shape + status strings (`queued/running/complete/error/cancelAcknowledged`).
208
221
  - [x] `kernels_output` kwarg + downloaded log format (`<slug>.log`).
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "omnirun"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "Run jobs from your repo anywhere: Slurm over SSH, any SSH box, Kaggle, Colab, or marketplace GPUs"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -1,3 +1,3 @@
1
1
  """omnirun — run jobs from your repo anywhere."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.2.1"
@@ -32,7 +32,7 @@ from datetime import datetime, timedelta, timezone
32
32
  from pathlib import Path
33
33
  from typing import Any
34
34
 
35
- from omnirun.backends import jobdir
35
+ from omnirun.backends import jobdir, tarsafe
36
36
  from omnirun.backends.base import Backend, BackendError, register
37
37
  from omnirun.bootstrap import (
38
38
  HEARTBEAT_STALE_S,
@@ -583,7 +583,7 @@ class ColabBackend(Backend):
583
583
  if not local_tar.exists():
584
584
  raise BackendError("colab download produced no local file")
585
585
  with tarfile.open(local_tar) as tf:
586
- tf.extractall(td, filter="data")
586
+ tarsafe.extract_all(tf, Path(td))
587
587
  outputs = Path(td) / "outputs"
588
588
  if outputs.is_dir():
589
589
  shutil.copytree(outputs, dest, dirs_exist_ok=True)
@@ -34,7 +34,7 @@ from pathlib import Path
34
34
  from typing import Any
35
35
 
36
36
  from omnirun.backends.base import Backend, BackendError, register
37
- from omnirun.backends import jobdir
37
+ from omnirun.backends import jobdir, tarsafe
38
38
  from omnirun.bootstrap import (
39
39
  BootstrapParams,
40
40
  CodeSource,
@@ -76,10 +76,15 @@ MAX_MEM_GB = 30
76
76
  MAX_DISK_GB = 55
77
77
  KAGGLE_ROOT = "/kaggle/tmp/omnirun" # venv + tree scratch; /kaggle/working stays small
78
78
  RESULT_TAR = "omnirun-job.tar.gz"
79
- # Cap on the base64 git bundle embedded in the kernel source. Kaggle rejects
80
- # oversized kernel pushes; fail early with a clear message instead. Generous
81
- # a code-only repo bundle is normally well under a megabyte.
82
- MAX_EMBED_B64 = 40 * 1024 * 1024
79
+ # Cap on the kernel source (run.py) omnirun pushes: the embedded bootstrap +
80
+ # any git bundle (private/unpushed repos) + any out-of-band .env all count
81
+ # against it. Kaggle rejects an oversized push with an opaque HTTP 400, so we
82
+ # guard at the real threshold and fail early naming size as the cause. Measured
83
+ # live against the kernels API: <=1 MiB accepted, >=1.1 MiB rejected — i.e. the
84
+ # limit is 1 MiB. A private/unpushed repo therefore only fits when its bundle is
85
+ # small; a *public* repo is cloned by the worker directly (no bundle shipped) and
86
+ # is unaffected by this cap. Override per backend with `max_source_bytes`.
87
+ KAGGLE_MAX_SOURCE_BYTES = 1024 * 1024
83
88
  LOG_POLL_INTERVAL_S = 30.0 # poll etiquette: >=30s against the kaggle API
84
89
 
85
90
 
@@ -365,6 +370,29 @@ class KaggleBackend(Backend):
365
370
 
366
371
  # ---- submit ---------------------------------------------------------------
367
372
 
373
+ def _guard_source_size(self, harness: str, *, shipped_bundle: bool) -> None:
374
+ """Fail early, with a size-naming message, when the kernel source is over
375
+ Kaggle's real push limit — instead of letting the push fail opaquely."""
376
+ limit = int(self.config.extra("max_source_bytes", KAGGLE_MAX_SOURCE_BYTES))
377
+ size = len(harness.encode())
378
+ if size <= limit:
379
+ return
380
+ # the git bundle (full history + tree at the sha) usually dominates when
381
+ # a private/unpushed repo forces one; a public repo ships no bundle.
382
+ remedy = (
383
+ "push the repo to a public remote so the worker clones it directly "
384
+ "(no bundle shipped), slim the git history (shallow/squash) or exclude "
385
+ "heavy dirs from the tree, "
386
+ if shipped_bundle
387
+ else "slim the tree or "
388
+ )
389
+ raise BackendError(
390
+ f"kaggle kernel source is {size / (1024 * 1024):.1f} MB, over the "
391
+ f"~{limit / (1024 * 1024):.1f} MB Kaggle push limit (the push would "
392
+ f"fail opaquely) — {remedy}run this job on another backend, or raise "
393
+ "the backend's `max_source_bytes` if Kaggle accepts more"
394
+ )
395
+
368
396
  def submit(self, spec: JobSpec, offer: Offer) -> JobHandle:
369
397
  api = self._api()
370
398
  user = self._username(api)
@@ -401,13 +429,6 @@ class KaggleBackend(Backend):
401
429
  env_b64 = (
402
430
  base64.b64encode(envf.read_text().encode()).decode() if envf else ""
403
431
  )
404
- if len(bundle_b64) + len(env_b64) > MAX_EMBED_B64:
405
- raise BackendError(
406
- f"embedded payload is too large for a kaggle kernel "
407
- f"(~{(len(bundle_b64) + len(env_b64)) // (1024 * 1024)}MB base64) "
408
- "— slim the git history (shallow/squash), push a public repo, or "
409
- "run this job on another backend"
410
- )
411
432
 
412
433
  script = generate_bootstrap(
413
434
  notebook_env_spec(spec),
@@ -421,11 +442,12 @@ class KaggleBackend(Backend):
421
442
  )
422
443
  boot_b64 = base64.b64encode(script.encode()).decode()
423
444
 
445
+ harness = _render_harness(job_id, boot_b64, bundle_b64, env_b64)
446
+ self._guard_source_size(harness, shipped_bundle=bool(bundle_b64))
447
+
424
448
  k_dir = stage / "kernel"
425
449
  k_dir.mkdir()
426
- (k_dir / "run.py").write_text(
427
- _render_harness(job_id, boot_b64, bundle_b64, env_b64)
428
- )
450
+ (k_dir / "run.py").write_text(harness)
429
451
  meta: dict[str, Any] = {
430
452
  "id": kernel_ref,
431
453
  "title": slug, # title must slugify to the id slug
@@ -610,7 +632,7 @@ class KaggleBackend(Backend):
610
632
  extract = Path(td) / "extract"
611
633
  extract.mkdir()
612
634
  with tarfile.open(tar) as tf:
613
- tf.extractall(extract, filter="data")
635
+ tarsafe.extract_all(tf, extract)
614
636
  outputs = extract / "outputs"
615
637
  if outputs.is_dir():
616
638
  shutil.copytree(outputs, dest, dirs_exist_ok=True)
@@ -0,0 +1,38 @@
1
+ """Tolerant tar extraction for the notebook backends (kaggle, colab), which
2
+ return a job's outputs as a tarball the client must unpack.
3
+
4
+ Python >=3.12 defaults tar extraction to the PEP-706 ``data`` filter. That
5
+ filter is right (it refuses path traversal, device nodes and links pointing
6
+ outside the destination), but ``extractall`` aborts the *whole* archive the
7
+ first time the filter rejects a member. The common offender is a symlink whose
8
+ target is an absolute path — every Weights & Biases run leaves one at
9
+ ``wandb/*/logs/debug-core.log`` — so a single such link would strand every
10
+ output of an otherwise-successful job.
11
+
12
+ ``extract_all`` applies the same ``data`` filter per member but skips (with a
13
+ warning) any member the filter rejects, so the rest of the tree still lands.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import sys
19
+ import tarfile
20
+ from pathlib import Path
21
+
22
+
23
+ def extract_all(tf: tarfile.TarFile, dest: Path) -> list[str]:
24
+ """Extract every member of ``tf`` under ``dest`` with the safe ``data``
25
+ filter, skipping (not aborting on) any member the filter rejects. Returns
26
+ the names of the skipped members (also warned to stderr)."""
27
+ skipped: list[str] = []
28
+ for member in tf.getmembers():
29
+ try:
30
+ tf.extract(member, dest, filter="data")
31
+ except tarfile.FilterError as e:
32
+ skipped.append(member.name)
33
+ print(
34
+ f"omnirun: warning: skipped unsafe archive entry "
35
+ f"{member.name!r} ({type(e).__name__})",
36
+ file=sys.stderr,
37
+ )
38
+ return skipped
@@ -188,6 +188,33 @@ def _indent(block: str, n: int) -> str:
188
188
  return "".join(pad + line + "\n" for line in block.splitlines())
189
189
 
190
190
 
191
+ def _heredoc_delim(body: str) -> str:
192
+ """A heredoc terminator that provably does not occur as a line in `body`,
193
+ so embedding an arbitrary command in a heredoc can never terminate early."""
194
+ lines = body.splitlines()
195
+ base = "OMNIRUN_CMD_EOF"
196
+ delim = base
197
+ i = 0
198
+ while delim in lines:
199
+ i += 1
200
+ delim = f"{base}_{i}"
201
+ return delim
202
+
203
+
204
+ def _command_block(command: str) -> str:
205
+ """Body of run_cmd(): the user command carried byte-exact via a single-quoted
206
+ heredoc and run with `eval`.
207
+
208
+ A single-quoted heredoc disables every expansion and preserves the body
209
+ literally — newlines, embedded heredocs, quotes, backslashes all survive — so
210
+ multi-line scripts reach the worker unmangled. `eval` runs it in the current
211
+ shell, so env activation, forwarded exports and pre-run lines all still apply.
212
+ Crucially the command is NOT indented: indenting would shift the user's own
213
+ heredoc terminators off column 0 and break them."""
214
+ delim = _heredoc_delim(command)
215
+ return f"eval \"$(cat <<'{delim}'\n{command}\n{delim}\n)\"\n"
216
+
217
+
191
218
  def _default_project_root(slug: str) -> str:
192
219
  return f"$OMNIRUN_ROOT/projects/{slug}"
193
220
 
@@ -307,8 +334,7 @@ status running
307
334
  STARTED_AT=$(now)
308
335
  set +e
309
336
  run_cmd() {{
310
- {_indent(spec.command, 2)}\
311
- }}
337
+ {_command_block(spec.command)}}}
312
338
  # run in a subshell: a bare `exit N` in the user command must not kill
313
339
  # bootstrap.sh itself (result.json would never be written -> job shows LOST)
314
340
  ( run_cmd ) > >(tee "$JOB_DIR/logs/stdout.log") 2> >(tee "$JOB_DIR/logs/stderr.log" >&2)
@@ -133,6 +133,38 @@ def test_failing_command_propagates_exit_code(
133
133
  assert "about to fail" in (job_dir / "logs" / "stdout.log").read_text()
134
134
 
135
135
 
136
+ def test_multiline_heredoc_command_runs_byte_exact(
137
+ sample_repo: Path, job_spec: JobSpec, tmp_path: Path
138
+ ) -> None:
139
+ """Regression (#3): a multi-line command with a heredoc must reach the worker
140
+ byte-identical. The old indent-per-line embedding shifted the heredoc
141
+ terminator off column 0 (breaking it) and prefixed every body line — this
142
+ proves the body is written verbatim, indentation and all."""
143
+ command = (
144
+ 'cat <<EOF > "$OMNIRUN_OUTPUT/cfg.yaml"\n'
145
+ "key: value\n"
146
+ " two-space-indent: kept\n"
147
+ "EOF\n"
148
+ 'echo "MULTILINE OK"'
149
+ )
150
+ spec = job_spec.model_copy(
151
+ update={
152
+ "job_id": JobSpec.make_job_id("heredoc"),
153
+ "command": command,
154
+ "outputs": [],
155
+ }
156
+ )
157
+ root = tmp_path / "omnirun_root"
158
+ script = stage(sample_repo, spec, root)
159
+ proc = run_bootstrap(script)
160
+
161
+ job_dir = root / "jobs" / spec.job_id
162
+ assert proc.returncode == 0, (job_dir / "logs" / "bootstrap.log").read_text()
163
+ cfg = job_dir / "outputs" / "cfg.yaml"
164
+ assert cfg.read_text() == "key: value\n two-space-indent: kept\n"
165
+ assert "MULTILINE OK" in (job_dir / "logs" / "stdout.log").read_text()
166
+
167
+
136
168
  def test_bare_exit_in_command_still_writes_result(
137
169
  sample_repo: Path, job_spec: JobSpec, tmp_path: Path
138
170
  ) -> None:
@@ -496,6 +496,49 @@ def test_pull_outputs(fake_api, backend, tmp_path):
496
496
  assert files == [dest / "model.txt"]
497
497
 
498
498
 
499
+ def test_pull_outputs_tolerates_absolute_symlink(fake_api, backend, tmp_path):
500
+ """Regression (#1): every W&B run leaves a symlink to an absolute path under
501
+ wandb/*/logs/. Python's data filter rejects it; pull must skip that one entry
502
+ and still recover the real outputs rather than aborting the whole archive."""
503
+ buf = io.BytesIO()
504
+ with tarfile.open(fileobj=buf, mode="w:gz") as tf:
505
+ data = b"metric,value\n1,2\n"
506
+ good = tarfile.TarInfo("outputs/results.csv")
507
+ good.size = len(data)
508
+ tf.addfile(good, io.BytesIO(data))
509
+ link = tarfile.TarInfo("outputs/wandb/run-x/logs/debug-core.log")
510
+ link.type = tarfile.SYMTYPE
511
+ link.linkname = "/kaggle/tmp/omnirun/abs/debug-core.log" # absolute target
512
+ tf.addfile(link)
513
+ fake_api.output_files = {"omnirun-job.tar.gz": buf.getvalue()}
514
+ dest = tmp_path / "results"
515
+ files = backend.pull_outputs(make_handle(), dest)
516
+ assert (dest / "results.csv").read_bytes() == data
517
+ assert [p.name for p in files] == ["results.csv"] # link skipped, csv kept
518
+
519
+
520
+ def test_submit_guards_oversized_source(fake_api, monkeypatch):
521
+ """Regression (#2): an oversized kernel source must fail early with a
522
+ size-naming message, not sail past the guard and fail opaquely on Kaggle."""
523
+ monkeypatch.setattr(
524
+ kaggle_mod, "_create_bundle", lambda root, sha, dest: _big_bundle(dest)
525
+ )
526
+ backend = KaggleBackend(
527
+ "kaggle",
528
+ BackendConfig.model_validate({"type": "kaggle", "max_source_bytes": 4096}),
529
+ )
530
+ spec = make_spec(gpu_type="P100")
531
+ offer = backend.probe(spec.resources)[0]
532
+ with pytest.raises(BackendError, match=r"kaggle kernel source is .* over the"):
533
+ backend.submit(spec, offer)
534
+
535
+
536
+ def _big_bundle(dest: Path) -> Path:
537
+ dest = Path(dest)
538
+ dest.write_bytes(b"x" * 8192) # base64 ~11k, over the 4k test limit
539
+ return dest
540
+
541
+
499
542
  def test_cancel_without_api_support_points_at_website(fake_api, backend):
500
543
  with pytest.raises(BackendError, match="kaggle.com"):
501
544
  backend.cancel(make_handle())
@@ -0,0 +1,53 @@
1
+ """Tolerant tar extraction (shared by the kaggle + colab pull paths)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import io
6
+ import os
7
+ import tarfile
8
+ from pathlib import Path
9
+
10
+ from omnirun.backends import tarsafe
11
+
12
+
13
+ def _tar_with_abs_symlink(dest_target: str) -> io.BytesIO:
14
+ buf = io.BytesIO()
15
+ with tarfile.open(fileobj=buf, mode="w:gz") as tf:
16
+ data = b"real output\n"
17
+ good = tarfile.TarInfo("outputs/results.txt")
18
+ good.size = len(data)
19
+ tf.addfile(good, io.BytesIO(data))
20
+ link = tarfile.TarInfo("outputs/wandb/run-x/logs/debug-core.log")
21
+ link.type = tarfile.SYMTYPE
22
+ link.linkname = dest_target
23
+ tf.addfile(link)
24
+ buf.seek(0)
25
+ return buf
26
+
27
+
28
+ def test_extract_all_skips_absolute_symlink_and_keeps_rest(tmp_path: Path) -> None:
29
+ # every W&B run leaves such a link; the default data filter would abort here.
30
+ buf = _tar_with_abs_symlink("/etc/hostname")
31
+ with tarfile.open(fileobj=buf) as tf:
32
+ skipped = tarsafe.extract_all(tf, tmp_path)
33
+ assert skipped == ["outputs/wandb/run-x/logs/debug-core.log"]
34
+ assert (tmp_path / "outputs" / "results.txt").read_bytes() == b"real output\n"
35
+ assert not (tmp_path / "outputs" / "wandb" / "run-x" / "logs").exists()
36
+
37
+
38
+ def test_extract_all_extracts_normal_tree_completely(tmp_path: Path) -> None:
39
+ src = tmp_path / "src"
40
+ (src / "sub").mkdir(parents=True)
41
+ (src / "a.txt").write_text("a")
42
+ (src / "sub" / "b.txt").write_text("b")
43
+ os.symlink("a.txt", src / "rel") # a *relative* symlink is allowed by data filter
44
+ tar = tmp_path / "t.tar.gz"
45
+ with tarfile.open(tar, "w:gz") as tf:
46
+ tf.add(src, arcname="outputs")
47
+ out = tmp_path / "out"
48
+ with tarfile.open(tar) as tf:
49
+ skipped = tarsafe.extract_all(tf, out)
50
+ assert skipped == []
51
+ assert (out / "outputs" / "a.txt").read_text() == "a"
52
+ assert (out / "outputs" / "sub" / "b.txt").read_text() == "b"
53
+ assert (out / "outputs" / "rel").is_symlink()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes