letify 2.10.4__tar.gz → 2.10.6__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.
- {letify-2.10.4 → letify-2.10.6}/PKG-INFO +1 -1
- {letify-2.10.4 → letify-2.10.6}/docs/SPEC.md +4 -2
- {letify-2.10.4 → letify-2.10.6}/letify/__init__.py +1 -1
- {letify-2.10.4 → letify-2.10.6}/letify/protocol/worker.py +40 -2
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/control.py +21 -7
- {letify-2.10.4 → letify-2.10.6}/letify/store/backends/drive.py +87 -9
- {letify-2.10.4 → letify-2.10.6}/letify-core/Cargo.lock +2 -2
- {letify-2.10.4 → letify-2.10.6}/letify-core/Cargo.toml +1 -1
- {letify-2.10.4 → letify-2.10.6}/letify-ext/package-lock.json +2 -2
- {letify-2.10.4 → letify-2.10.6}/letify-ext/package.json +1 -1
- {letify-2.10.4 → letify-2.10.6}/pyproject.toml +1 -1
- {letify-2.10.4 → letify-2.10.6}/tests/conftest.py +38 -8
- {letify-2.10.4 → letify-2.10.6}/tests/test_drive_store.py +195 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_run_control.py +30 -0
- {letify-2.10.4 → letify-2.10.6}/.github/workflows/ci.yml +0 -0
- {letify-2.10.4 → letify-2.10.6}/.github/workflows/docs.yml +0 -0
- {letify-2.10.4 → letify-2.10.6}/.github/workflows/publish-crates.yml +0 -0
- {letify-2.10.4 → letify-2.10.6}/.github/workflows/publish.yml +0 -0
- {letify-2.10.4 → letify-2.10.6}/.github/workflows/reserve-crates.yml +0 -0
- {letify-2.10.4 → letify-2.10.6}/.gitignore +0 -0
- {letify-2.10.4 → letify-2.10.6}/.researchtree +0 -0
- {letify-2.10.4 → letify-2.10.6}/CLAUDE.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/LICENSE +0 -0
- {letify-2.10.4 → letify-2.10.6}/PROJECT.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/README.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/COMPONENT.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/INTENT.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/NETWORK.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/01-getting-started.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/02-providers.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/03-execution-modes.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/04-environments-and-data.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/05-concurrency.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/06-cost.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/07-troubleshooting.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/08-releasing.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/README.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/01-/354/213/234/354/236/221/355/225/230/352/270/260.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/02-/355/224/204/353/241/234/353/260/224/354/235/264/353/215/224.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/03-/354/213/244/355/226/211-/353/260/251/354/213/235.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/04-/355/231/230/352/262/275/352/263/274-/353/215/260/354/235/264/355/204/260.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/05-/353/217/231/354/213/234-/354/213/244/355/226/211.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/06-/353/271/204/354/232/251.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/07-/353/254/270/354/240/234-/355/225/264/352/262/260.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/08-/353/246/264/353/246/254/354/212/244.md" +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/guide/ko/README.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/locales/README_ko.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/docs/mkdocs.yml +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/README.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/.letify.example +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/00_smoke.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/01_sweep.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/02_resume.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/03_watch.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/README.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/README_ko.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/common.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/examples/nvfp4-lora/recipe.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/cli.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/config/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/config/inventory.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/config/login.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/config/schema.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/config/secrets.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/config/writer.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/cache.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/env.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/exit.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/function.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/instance.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/reduce.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/declare/replicas.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/errors.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/install.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/launcher.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/paths.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/protocol/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/protocol/codec.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/protocol/driver.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/protocol/handle.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/protocol/wire.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/base.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/colab.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/colab_files.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/colab_keepalive.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/elice.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/kaggle.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/kaggle_adapter.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/local.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/modal.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/modal_adapter.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/naming.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/shell.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/tunnel.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/providers/usage.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/client.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/cuda.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/executor.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/frames.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/guard.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/tensor.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/trace.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/remoting/device/value.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/render.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/bootstrap.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/broker.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/channel.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/lease.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/pool.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/session.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/takeover.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/telemetry.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/runtime/workers.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/backends/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/backends/filesystem.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/backends/google_auth.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/backends/layout.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/backends/objects.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/cas.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/handoff.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/pathdata.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/sendorder.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/store/volume.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/stubs.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/tools.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/__init__.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/agent.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/announce.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/link.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/nat.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/pipeline.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/portmap.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/probe.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/quic.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/rendezvous.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/setup.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/sshopts.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify/transport/strategies.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/.gitignore +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/build.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/letify/Cargo.toml +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/letify/LICENSE +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/letify/README.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/letify/src/lib.rs +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/letify-quic/Cargo.toml +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/letify-quic/src/main.rs +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-core/rust-toolchain.toml +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/.vscodeignore +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/LICENSE +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/README.md +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/media/icon.svg +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/src/cli.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/src/extension.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/src/history.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/src/model.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/src/poll.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/src/render.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/test/cli.test.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/test/manifest.test.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/test/model.test.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/test/regressions.test.ts +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify-ext/tsconfig.json +0 -0
- {letify-2.10.4 → letify-2.10.6}/letify_providers.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/scripts/sync-main.sh +0 -0
- {letify-2.10.4 → letify-2.10.6}/scripts/version.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/fake_kaggle_adapter.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/fake_modal_adapter.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_cli.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_cli_output.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_colab_keepalive.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_config.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_core.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_data.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_data_streaming.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_declare.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_device.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_device_compile.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_distributed.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_drive_handoff.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_editor_sessions.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_elice.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_frames.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_install.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_kaggle.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_kaggle_cookie.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_kaggle_link.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_link_log.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_notebook.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_parallel_placement.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_paths.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_portmap.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_protocol.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_providers.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_punch_sockets.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_quic.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_remoting.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_render.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_run_takeover.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_runtime.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_shell_workers.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_ship.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_store.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_strategies.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_stubs.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_transport.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_tunnel_setup.py +0 -0
- {letify-2.10.4 → letify-2.10.6}/tests/test_version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: letify
|
|
3
|
-
Version: 2.10.
|
|
3
|
+
Version: 2.10.6
|
|
4
4
|
Summary: Declarations that become infrastructure.
|
|
5
5
|
Project-URL: Homepage, https://github.com/DarkPyonix/letify
|
|
6
6
|
Project-URL: Documentation, https://github.com/DarkPyonix/letify/tree/main/docs
|
|
@@ -1063,7 +1063,7 @@ A call on a remote runtime is a program running somewhere else. On a laptop the
|
|
|
1063
1063
|
|
|
1064
1064
|
Every call on a runtime gets a run id, 12 lowercase hex characters, when it is sent. The owning process writes `~/.letify/runs/<run id>.json` before the call is sent and removes it when the call returns or raises. The record holds `run`, `function` (the qualified name), `runtime`, `provider` (the account alias), `started_at` (Unix seconds), `pid` (the owning process) and `socket`, the owner's control socket. The directory is created with mode 0700 and each file with mode 0600.
|
|
1065
1065
|
|
|
1066
|
-
Each owning process listens on one Unix socket, `~/.letify/runs/<pid>.sock`, created on the first call and removed at exit. A command reaches a run by reading its record and connecting to that socket; the owner forwards the request to the runtime over the call's own channel. When `~/.letify/runs/<pid>.sock` would exceed 100 bytes, the limit of a Unix socket path, the socket is created as `run-<pid>.sock` in the SSH control directory of [Declared filesystem paths](#declared-paths) instead, and `socket` in the record names
|
|
1066
|
+
Each owning process listens on one Unix socket, `~/.letify/runs/<pid>.sock`, created on the first call and removed at exit. A command reaches a run by reading its record and connecting to that socket; the owner forwards the request to the runtime over the call's own channel. When `~/.letify/runs/<pid>.sock` would exceed 100 bytes, below the limit of a Unix socket path (107 bytes on Linux, 103 on macOS), the socket is created as `run-<pid>.sock` in the SSH control directory of [Declared filesystem paths](#declared-paths) instead. When that path also exceeds 100 bytes, which happens with a deep `LETIFY_HOME` and no `XDG_RUNTIME_DIR`, the socket is created as `run-<h>-<pid>.sock` in `letify-<uid>` below the system temporary directory, where `<h>` is the first 12 hex characters of the SHA-256 of the preferred path. That directory is mode 0700, owned by the user, and not a symbolic link; it is refused otherwise. In every case `socket` in the record names the path actually bound, and the socket is removed at exit. A record whose `pid` no longer exists is stale: it is removed when read and the run is reported as not found. On Windows there is no control socket, and the commands below say so.
|
|
1067
1067
|
|
|
1068
1068
|
The request travels as one JSON object per line on the socket and the answer as one JSON object per line, so a tool that is not letify can drive it.
|
|
1069
1069
|
|
|
@@ -1371,7 +1371,7 @@ An ephemeral provider uses the Drive store for its environment archive when the
|
|
|
1371
1371
|
|
|
1372
1372
|
Whether an archive is worth it is measured, not assumed, because a provider with a fast package index can build faster than it restores. On a Kaggle runtime the same 5.5 GB environment built in 35.4 s and restored from Drive in about 90 s. So after a sync letify packs only when the build took at least twice as long as the archive would take to restore, estimated as the project directory's size over 176 MiB/s, the slower Drive download measured, plus the same size over 170 MB/s, the extraction rate measured on a sandbox disk. The record beside the archive keeps the build seconds and, once a session has restored from it, the restore seconds that session measured; a later session restores only while the measured restore is shorter than the measured build, and syncs otherwise, saying `letify: <runtime>: syncing rather than restoring from Drive, because a restore took <s> s against a <s> s build`. The factor of two is there because packing has a cost of its own that the comparison leaves out: on a Kaggle runtime a 7.2 GB environment that built in 87.6 s against an estimated 81 s restore was packed, which would save about 6 s a session at the price of the pack.
|
|
1373
1373
|
|
|
1374
|
-
The pack to Drive runs on the worker beside the session's calls, not before them. After the interpreter check the session starts the pack as a background job and returns, so the first call starts at once; the worker answers calls on its main thread while a separate thread writes the tar and uploads it, and the archive's ref and build record are written only when the upload completes. The upload session needs the archive's digest and size, so the worker reports them once the tar is written, and a client thread that checks every 2 s creates the resumable session and hands its URL to the worker, which then uploads; the client records and reports the result at the start and end of a call and at session close. A session that ends first leaves no ref, and the next session syncs and may pack again. While it runs the pack says nothing more after `caching the environment, <size> GB`; when it ends it says `letify: <runtime>: cached the environment, <size> GB in <s> s (<rate> MiB/s)`, or the Drive failure line above, on standard error of whichever call or session close observes it first. Closing the session waits up to 60 s for a pack still running and then abandons it, saying `letify: <runtime>: not caching the environment, because the session closed <s> s into the pack`.
|
|
1374
|
+
The pack to Drive runs on the worker beside the session's calls, not before them. After the interpreter check the session starts the pack as a background job and returns, so the first call starts at once; the worker answers calls on its main thread while a separate thread writes the tar and uploads it, and the archive's ref and build record are written only when the upload completes. The upload session needs the archive's digest and size, so the worker reports them once the tar is written, and a client thread that checks every 2 s creates the resumable session and hands its URL to the worker, which then uploads; the client records and reports the result at the start and end of a call and at session close. A session that ends first leaves no ref, and the next session syncs and may pack again. While it runs the pack says nothing more after `caching the environment, <size> GB`; when it ends it says `letify: <runtime>: cached the environment, <size> GB in <s> s (<rate> MiB/s)`, or the Drive failure line above, on standard error of whichever call or session close observes it first. The pack tolerates a tree that changes under it, because the first call runs beside it. A file or directory that disappears between the walk listing it and the tar reading it is left out of the archive, not an error. Temporary bytecode files named `<name>.pyc.<digits>`, which the interpreter writes and renames while a call imports a module, are left out. Other `__pycache__` content stays in the archive, so a restored environment does not recompile on import. The archive digest and size are computed over the bytes written, so they describe exactly the members it holds. Closing the session waits up to 60 s for a pack still running and then abandons it, saying `letify: <runtime>: not caching the environment, because the session closed <s> s into the pack`.
|
|
1375
1375
|
|
|
1376
1376
|
Drive's own limits apply. The archive counts against the Google account's storage, which is the person's own plan. Google documents a daily upload limit of 750 GB per user for Google Workspace accounts, independent of the storage plan; an environment archive is a few gigabytes, so letify does not approach it. Standard use of the Drive API costs nothing, and Google documents that exceeding its request quota is planned to be charged to the project's billing account later in 2026; letify's requests are a handful per session against a quota of 325,000 units per user per minute.
|
|
1377
1377
|
|
|
@@ -1656,6 +1656,8 @@ A handoff is what a volume cannot be: a value written on one provider and read o
|
|
|
1656
1656
|
|
|
1657
1657
|
A name is 1 to 128 characters of letters, digits, `.`, `_` and `-`, and does not start with `.`; anything else raises `ValueError` naming the rule. Names are shared by every project on the machine's Drive store, so a project that wants its own space puts its name in the handoff name.
|
|
1658
1658
|
|
|
1659
|
+
An upload to Drive resumes after a failed piece instead of starting again. When a piece of the resumable upload fails with a network error, a timeout, or HTTP 500, 502, 503 or 504, the sender asks the session where it stands with an empty `PUT` carrying `Content-Range: bytes */<size>`, Google's documented status query. A 308 answer with `Range: bytes=0-N` means the next byte to send is `N+1`, a 308 without `Range` means 0, and a 200 or 201 answer means the upload is complete and the body carries the file id. The sender seeks the file to that offset and continues, so bytes the session already acknowledged are not sent again. It waits 1, 2, 4, 8, 16 and 32 s before the successive attempts and gives up with `RuntimeFailure` on the seventh consecutive failure. Only failures with no progress between them count: a piece that is acknowledged, or a status query that shows a larger offset, resets the count, so a long upload that keeps progressing survives any number of scattered errors. A failed status query counts as a failure. HTTP 404 and 410 mean the session expired and raise `RuntimeFailure` saying so and that the upload must start again. Any other 4xx except 308 is not retried. Each resume prints `letify: Drive upload resumed at <offset> of <size> after <error>` on stderr. The function uses the standard library only, so the worker runs the same code as the client, and this applies to the archive upload of the Drive store and to `stash` alike.
|
|
1660
|
+
|
|
1659
1661
|
The name `unstash` is not `fetch`, because `letify.fetch(tensor)` already reads a tensor back in `host=local`.
|
|
1660
1662
|
|
|
1661
1663
|
Both run in two places with the same result:
|
|
@@ -2376,12 +2376,50 @@ def _op_get_file(request):
|
|
|
2376
2376
|
}
|
|
2377
2377
|
|
|
2378
2378
|
|
|
2379
|
+
def _pack_add(archive, path, arcname, top=True):
|
|
2380
|
+
"""Add ``path`` to ``archive``, leaving out what vanishes before it is read.
|
|
2381
|
+
|
|
2382
|
+
Spec "Google Drive is a store, not a volume": the pack runs beside the session's
|
|
2383
|
+
calls, so a file or directory listed by the walk may be gone by the time it is opened.
|
|
2384
|
+
The interpreter also writes a bytecode file as ``<name>.pyc.<digits>`` and renames it,
|
|
2385
|
+
and that temporary name is left out. The root must exist.
|
|
2386
|
+
"""
|
|
2387
|
+
if not top:
|
|
2388
|
+
stem, _dot, tail = os.path.basename(path).rpartition(".")
|
|
2389
|
+
if tail.isdigit() and stem.endswith(".pyc"):
|
|
2390
|
+
return
|
|
2391
|
+
try:
|
|
2392
|
+
info = archive.gettarinfo(path, arcname)
|
|
2393
|
+
except FileNotFoundError:
|
|
2394
|
+
if top:
|
|
2395
|
+
raise
|
|
2396
|
+
return
|
|
2397
|
+
if info is None:
|
|
2398
|
+
return
|
|
2399
|
+
if info.isreg():
|
|
2400
|
+
try:
|
|
2401
|
+
handle = open(path, "rb")
|
|
2402
|
+
except FileNotFoundError:
|
|
2403
|
+
return
|
|
2404
|
+
with handle:
|
|
2405
|
+
archive.addfile(info, handle)
|
|
2406
|
+
return
|
|
2407
|
+
archive.addfile(info)
|
|
2408
|
+
if info.isdir():
|
|
2409
|
+
try:
|
|
2410
|
+
names = sorted(os.listdir(path))
|
|
2411
|
+
except FileNotFoundError:
|
|
2412
|
+
return
|
|
2413
|
+
for name in names:
|
|
2414
|
+
_pack_add(archive, os.path.join(path, name), arcname + "/" + name, False)
|
|
2415
|
+
|
|
2416
|
+
|
|
2379
2417
|
def _op_pack_dir(request):
|
|
2380
2418
|
"""Pack a directory inside the runtime and return it as one payload."""
|
|
2381
2419
|
buffer = io.BytesIO()
|
|
2382
2420
|
root = request["path"]
|
|
2383
2421
|
with tarfile.open(fileobj=buffer, mode="w:gz") as archive:
|
|
2384
|
-
archive
|
|
2422
|
+
_pack_add(archive, root, os.path.basename(root.rstrip("/")))
|
|
2385
2423
|
payload = buffer.getvalue()
|
|
2386
2424
|
return {
|
|
2387
2425
|
"ok": True,
|
|
@@ -2429,7 +2467,7 @@ def _op_pack_blob(request):
|
|
|
2429
2467
|
hashed = _HashedFile(handle, hasher)
|
|
2430
2468
|
mode = "w:gz" if request.get("gzip", True) else "w"
|
|
2431
2469
|
with tarfile.open(fileobj=hashed, mode=mode) as archive:
|
|
2432
|
-
archive
|
|
2470
|
+
_pack_add(archive, root, os.path.basename(root.rstrip("/")))
|
|
2433
2471
|
digest = _data_finish(hasher)
|
|
2434
2472
|
final = _data_file(directory, digest)
|
|
2435
2473
|
os.makedirs(os.path.dirname(final), exist_ok=True)
|
|
@@ -17,12 +17,14 @@ from __future__ import annotations
|
|
|
17
17
|
|
|
18
18
|
import atexit
|
|
19
19
|
import contextlib
|
|
20
|
+
import hashlib
|
|
20
21
|
import json
|
|
21
22
|
import os
|
|
22
23
|
import secrets
|
|
23
24
|
import socket
|
|
24
25
|
import stat
|
|
25
26
|
import sys
|
|
27
|
+
import tempfile
|
|
26
28
|
import threading
|
|
27
29
|
import time
|
|
28
30
|
from collections.abc import Iterator
|
|
@@ -65,21 +67,33 @@ def runs_directory() -> Path:
|
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
def socket_path(pid: int) -> Path:
|
|
68
|
-
"""Where the process ``pid`` listens
|
|
70
|
+
"""Where the process ``pid`` listens, at most ``SOCKET_LIMIT`` bytes long where it can be.
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
``
|
|
72
|
-
|
|
72
|
+
Spec "Controlling a running call": ``runs/<pid>.sock`` when that fits, else
|
|
73
|
+
``run-<pid>.sock`` in the SSH control directory, else ``run-<h>-<pid>.sock`` in a
|
|
74
|
+
private per-user directory below the system temporary directory, where ``<h>`` hashes
|
|
75
|
+
the preferred path so two state roots never share a name.
|
|
73
76
|
"""
|
|
74
77
|
preferred = runs_directory() / f"{pid}.sock"
|
|
75
78
|
if len(os.fsencode(preferred)) <= SOCKET_LIMIT:
|
|
76
79
|
return preferred
|
|
77
|
-
|
|
80
|
+
shared = paths.ssh_control_directory() / f"run-{pid}.sock"
|
|
81
|
+
if len(os.fsencode(shared)) <= SOCKET_LIMIT:
|
|
82
|
+
return shared
|
|
83
|
+
digest = hashlib.sha256(os.fsencode(preferred)).hexdigest()[:12]
|
|
84
|
+
name = f"run-{digest}-{pid}.sock"
|
|
85
|
+
return Path(tempfile.gettempdir()) / f"letify-{os.getuid()}" / name
|
|
78
86
|
|
|
79
87
|
|
|
80
88
|
def _private_directory(directory: Path) -> None:
|
|
81
|
-
directory.
|
|
82
|
-
|
|
89
|
+
"""Create ``directory`` mode 0700 and refuse a symbolic link or another user's directory."""
|
|
90
|
+
directory.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
91
|
+
info = directory.lstat()
|
|
92
|
+
if stat.S_ISLNK(info.st_mode) or not stat.S_ISDIR(info.st_mode):
|
|
93
|
+
raise OSError(f"{directory} is not a plain directory")
|
|
94
|
+
if info.st_uid != os.getuid():
|
|
95
|
+
raise OSError(f"{directory} is not owned by this user")
|
|
96
|
+
if stat.S_IMODE(info.st_mode) != 0o700:
|
|
83
97
|
directory.chmod(0o700)
|
|
84
98
|
|
|
85
99
|
|
|
@@ -21,7 +21,9 @@ import hashlib
|
|
|
21
21
|
import json
|
|
22
22
|
import os
|
|
23
23
|
import shutil
|
|
24
|
+
import sys
|
|
24
25
|
import threading
|
|
26
|
+
import time
|
|
25
27
|
import urllib.error
|
|
26
28
|
import urllib.parse
|
|
27
29
|
import urllib.request
|
|
@@ -53,21 +55,71 @@ _SCOPES = (
|
|
|
53
55
|
_FOLDER_TYPE = "application/vnd.google-apps.folder"
|
|
54
56
|
|
|
55
57
|
|
|
58
|
+
#: Seconds to wait before each successive attempt after a failed piece. A failure that
|
|
59
|
+
#: follows progress starts the count again, and the seventh in a row raises.
|
|
60
|
+
RESUME_DELAYS = (1, 2, 4, 8, 16, 32)
|
|
61
|
+
|
|
62
|
+
#: HTTP statuses of a piece that are worth asking the session about and trying again.
|
|
63
|
+
_RETRYABLE = (500, 502, 503, 504)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class _Retry(Exception):
|
|
67
|
+
"""A request that failed in a way the session may recover from."""
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _session_status(url: str, headers: dict[str, str], size: int) -> tuple[int, str | None]:
|
|
71
|
+
"""Ask a resumable session where it stands: the next byte it wants and, once done, the id.
|
|
72
|
+
|
|
73
|
+
This is Google's status query, an empty PUT with ``Content-Range: bytes */<size>``.
|
|
74
|
+
"""
|
|
75
|
+
query = urllib.request.Request(url, data=b"", method="PUT", headers=headers)
|
|
76
|
+
query.add_header("Content-Length", "0")
|
|
77
|
+
query.add_header("Content-Range", f"bytes */{size}")
|
|
78
|
+
try:
|
|
79
|
+
with urllib.request.urlopen(query, timeout=300) as response:
|
|
80
|
+
return size, str(json.loads(response.read())["id"])
|
|
81
|
+
except urllib.error.HTTPError as exc:
|
|
82
|
+
if exc.code == 308:
|
|
83
|
+
held = exc.headers.get("Range")
|
|
84
|
+
return (int(held.rsplit("-", 1)[1]) + 1 if held else 0), None
|
|
85
|
+
_refuse(exc)
|
|
86
|
+
raise _Retry(f"status query returned {exc.code}") from exc
|
|
87
|
+
except (urllib.error.URLError, OSError) as exc:
|
|
88
|
+
raise _Retry(str(exc)) from exc
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _refuse(exc: urllib.error.HTTPError) -> None:
|
|
92
|
+
"""Raise ``RuntimeFailure`` for a status that is not worth retrying."""
|
|
93
|
+
if exc.code in _RETRYABLE:
|
|
94
|
+
return
|
|
95
|
+
detail = exc.read()[:300].decode(errors="replace")
|
|
96
|
+
if exc.code in (404, 410):
|
|
97
|
+
raise RuntimeFailure(
|
|
98
|
+
f"Drive upload session expired ({exc.code}): the upload must start again"
|
|
99
|
+
) from exc
|
|
100
|
+
raise RuntimeFailure(f"Drive upload returned {exc.code}: {detail}") from exc
|
|
101
|
+
|
|
102
|
+
|
|
56
103
|
def upload_pieces(
|
|
57
104
|
path: str | os.PathLike[str], url: str, headers: dict[str, str], piece: int
|
|
58
105
|
) -> str:
|
|
59
106
|
"""Send one file to a resumable session URL in pieces and return the new file's id.
|
|
60
107
|
|
|
61
108
|
Every piece but the last is a multiple of 256 KiB, as Drive requires, and is answered
|
|
62
|
-
308 until the last, which is answered with the new file's metadata.
|
|
63
|
-
|
|
64
|
-
|
|
109
|
+
308 until the last, which is answered with the new file's metadata. A piece that fails
|
|
110
|
+
with a network error, a timeout or a 5xx status is not lost: the session is asked where
|
|
111
|
+
it stands and the upload continues from that offset, waiting ``RESUME_DELAYS`` between
|
|
112
|
+
attempts that make no progress. This is plain standard library code that both this
|
|
113
|
+
process and a worker can run, so a handoff made inside a shipped function uploads from
|
|
114
|
+
the runtime and the bytes never cross the client.
|
|
65
115
|
"""
|
|
66
116
|
size = os.path.getsize(path)
|
|
67
117
|
remote_id: str | None = None
|
|
118
|
+
failures = 0
|
|
68
119
|
with open(path, "rb") as handle:
|
|
69
120
|
offset = 0
|
|
70
|
-
while offset < size:
|
|
121
|
+
while remote_id is None and offset < size:
|
|
122
|
+
handle.seek(offset)
|
|
71
123
|
block = handle.read(piece)
|
|
72
124
|
end = offset + len(block)
|
|
73
125
|
send = urllib.request.Request(url, data=block, method="PUT", headers=headers)
|
|
@@ -76,13 +128,39 @@ def upload_pieces(
|
|
|
76
128
|
try:
|
|
77
129
|
with urllib.request.urlopen(send, timeout=3600) as response:
|
|
78
130
|
remote_id = str(json.loads(response.read())["id"])
|
|
131
|
+
offset, failures = end, 0
|
|
132
|
+
continue
|
|
79
133
|
except urllib.error.HTTPError as exc:
|
|
80
|
-
if exc.code
|
|
81
|
-
|
|
82
|
-
|
|
134
|
+
if exc.code == 308:
|
|
135
|
+
offset, failures = end, 0
|
|
136
|
+
continue
|
|
137
|
+
_refuse(exc)
|
|
138
|
+
reason = f"HTTP {exc.code}"
|
|
83
139
|
except (urllib.error.URLError, OSError) as exc:
|
|
84
|
-
|
|
85
|
-
|
|
140
|
+
reason = str(exc)
|
|
141
|
+
# The piece failed: ask the session where it stands, waiting between attempts.
|
|
142
|
+
while True:
|
|
143
|
+
if failures >= len(RESUME_DELAYS):
|
|
144
|
+
raise RuntimeFailure(
|
|
145
|
+
f"Drive upload failed at {offset} of {size} after "
|
|
146
|
+
f"{failures + 1} attempts without progress: {reason}"
|
|
147
|
+
)
|
|
148
|
+
time.sleep(RESUME_DELAYS[failures])
|
|
149
|
+
failures += 1
|
|
150
|
+
try:
|
|
151
|
+
held, remote_id = _session_status(url, headers, size)
|
|
152
|
+
except _Retry as retry:
|
|
153
|
+
reason = str(retry)
|
|
154
|
+
continue
|
|
155
|
+
break
|
|
156
|
+
if held > offset:
|
|
157
|
+
failures = 0
|
|
158
|
+
print(
|
|
159
|
+
f"letify: Drive upload resumed at {held} of {size} after {reason}",
|
|
160
|
+
file=sys.stderr,
|
|
161
|
+
flush=True,
|
|
162
|
+
)
|
|
163
|
+
offset = held
|
|
86
164
|
if remote_id is None:
|
|
87
165
|
raise RuntimeFailure("Drive upload: the session never answered with a file")
|
|
88
166
|
return remote_id
|
|
@@ -138,11 +138,11 @@ dependencies = [
|
|
|
138
138
|
|
|
139
139
|
[[package]]
|
|
140
140
|
name = "letify"
|
|
141
|
-
version = "2.10.
|
|
141
|
+
version = "2.10.6"
|
|
142
142
|
|
|
143
143
|
[[package]]
|
|
144
144
|
name = "letify-quic"
|
|
145
|
-
version = "2.10.
|
|
145
|
+
version = "2.10.6"
|
|
146
146
|
dependencies = [
|
|
147
147
|
"quinn",
|
|
148
148
|
"rcgen",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "letify-status",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.6",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "letify-status",
|
|
9
|
-
"version": "2.10.
|
|
9
|
+
"version": "2.10.6",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/node": "^18.19.0",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "letify-status",
|
|
3
3
|
"displayName": "letify Status",
|
|
4
4
|
"description": "letify quota and GPU activity in the status bar, read from the letify CLI.",
|
|
5
|
-
"version": "2.10.
|
|
5
|
+
"version": "2.10.6",
|
|
6
6
|
"publisher": "darkpyonix",
|
|
7
7
|
"license": "SEE LICENSE IN LICENSE",
|
|
8
8
|
"repository": {
|
|
@@ -1088,6 +1088,12 @@ class FakeDriveServer:
|
|
|
1088
1088
|
self.requests: list[dict[str, Any]] = []
|
|
1089
1089
|
self.refresh_grants: list[dict[str, str]] = []
|
|
1090
1090
|
self.fail_with: int | None = None
|
|
1091
|
+
#: One entry is consumed by each piece of a resumable upload: an HTTP status as text,
|
|
1092
|
+
#: "drop" to close the connection before storing the piece, "drop-after-store" to
|
|
1093
|
+
#: store it and then close without answering, or "expired" for a 404.
|
|
1094
|
+
self.glitches: list[str] = []
|
|
1095
|
+
#: One HTTP status is consumed by each status query (Content-Range: bytes */N).
|
|
1096
|
+
self.status_glitches: list[int] = []
|
|
1091
1097
|
#: When set, a piece of a resumable upload waits for this event before it is taken.
|
|
1092
1098
|
self.hold_uploads: threading.Event | None = None
|
|
1093
1099
|
#: When set, a DELETE waits for this event before it is answered.
|
|
@@ -1228,18 +1234,42 @@ class FakeDriveServer:
|
|
|
1228
1234
|
if self.hold_uploads is not None:
|
|
1229
1235
|
self.hold_uploads.wait(timeout=20)
|
|
1230
1236
|
session = self.sessions[parsed.path[len(session_prefix) :]]
|
|
1237
|
+
|
|
1238
|
+
def progress() -> None:
|
|
1239
|
+
if "id" in session:
|
|
1240
|
+
return reply({"id": session["id"], "name": session["meta"]["name"]})
|
|
1241
|
+
if not session["body"]:
|
|
1242
|
+
return answer(308)
|
|
1243
|
+
return answer(308, extra={"Range": f"bytes=0-{len(session['body']) - 1}"})
|
|
1244
|
+
|
|
1245
|
+
if headers["content-range"].startswith("bytes */"):
|
|
1246
|
+
if self.status_glitches:
|
|
1247
|
+
status = self.status_glitches.pop(0)
|
|
1248
|
+
return answer(status, b'{"error": {"message": "injected"}}')
|
|
1249
|
+
return progress()
|
|
1250
|
+
glitch = self.glitches.pop(0) if self.glitches else None
|
|
1251
|
+
if glitch == "expired":
|
|
1252
|
+
return answer(404, b'{"error": {"message": "session expired"}}')
|
|
1253
|
+
if glitch is not None and glitch.isdigit():
|
|
1254
|
+
return answer(int(glitch), b'{"error": {"message": "injected"}}')
|
|
1255
|
+
if glitch == "drop":
|
|
1256
|
+
handler.close_connection = True
|
|
1257
|
+
return None
|
|
1231
1258
|
start = int(headers["content-range"].split(" ")[1].split("-")[0])
|
|
1232
1259
|
if start != len(session["body"]):
|
|
1233
1260
|
return answer(400, b'{"error": {"message": "out of order"}}')
|
|
1234
1261
|
session["body"] += body
|
|
1235
|
-
if len(session["body"])
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1262
|
+
if len(session["body"]) >= session["size"]:
|
|
1263
|
+
identifier = self._new_id()
|
|
1264
|
+
self.files[identifier] = {
|
|
1265
|
+
**session["meta"], "id": identifier, "content": session["body"],
|
|
1266
|
+
"folder": False, "trashed": False,
|
|
1267
|
+
}
|
|
1268
|
+
session["id"] = identifier
|
|
1269
|
+
if glitch == "drop-after-store":
|
|
1270
|
+
handler.close_connection = True
|
|
1271
|
+
return None
|
|
1272
|
+
return progress()
|
|
1243
1273
|
|
|
1244
1274
|
if headers.get("authorization") != f"Bearer {self.token}":
|
|
1245
1275
|
return answer(401, b'{"error": {"message": "unauthenticated"}}')
|
|
@@ -574,3 +574,198 @@ def test_the_gate_packs_only_when_the_build_took_twice_the_estimated_restore() -
|
|
|
574
574
|
assert "not caching the environment" in said[-1]
|
|
575
575
|
assert judged(restore * 2) is True
|
|
576
576
|
assert judged(restore * 3) is True
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
# -- a resumable upload that survives a failed piece -----------------------------
|
|
580
|
+
|
|
581
|
+
PIECE = 256 * 1024
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
def upload_setup(fake_drive, tmp_path: Path, monkeypatch, pieces: int = 4):
|
|
585
|
+
"""A backend with 256 KiB pieces, no backoff wait, and a file of `pieces` whole pieces."""
|
|
586
|
+
from letify.store.backends import drive
|
|
587
|
+
|
|
588
|
+
monkeypatch.setattr(drive, "UPLOAD_PIECE", PIECE)
|
|
589
|
+
monkeypatch.setattr(drive, "RESUME_DELAYS", (0.0,) * 6)
|
|
590
|
+
data = bytes(range(256)) * (PIECE // 256 * pieces)
|
|
591
|
+
source = tmp_path / "big.bin"
|
|
592
|
+
source.write_bytes(data)
|
|
593
|
+
return backend_for(fake_drive), source, data
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def piece_starts(server: Any) -> list[int]:
|
|
597
|
+
ranges = [r["headers"]["content-range"] for r in server.uploads()]
|
|
598
|
+
return [int(c.split(" ")[1].split("-")[0]) for c in ranges if not c.startswith("bytes */")]
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
def test_an_upload_resumes_at_the_offset_the_session_reports_after_a_dropped_answer(
|
|
602
|
+
fake_drive, tmp_path: Path, monkeypatch, capsys
|
|
603
|
+
) -> None:
|
|
604
|
+
"""Spec: Named handoffs on the Drive store, a failed piece asks the session where it is."""
|
|
605
|
+
backend, source, data = upload_setup(fake_drive, tmp_path, monkeypatch)
|
|
606
|
+
fake_drive.glitches = ["drop-after-store"]
|
|
607
|
+
backend.put_file("digest-a", source)
|
|
608
|
+
assert fake_drive.blobs()["digest-a"] == data
|
|
609
|
+
starts = piece_starts(fake_drive)
|
|
610
|
+
assert sorted(starts) == [0, PIECE, 2 * PIECE, 3 * PIECE]
|
|
611
|
+
assert any(
|
|
612
|
+
r["headers"]["content-range"] == f"bytes */{len(data)}"
|
|
613
|
+
and r["headers"]["content-length"] == "0"
|
|
614
|
+
for r in fake_drive.uploads()
|
|
615
|
+
)
|
|
616
|
+
said = capsys.readouterr().err
|
|
617
|
+
assert f"letify: Drive upload resumed at {PIECE} of {len(data)} after" in said
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def test_an_upload_resends_a_piece_the_session_never_stored_after_a_dropped_connection(
|
|
621
|
+
fake_drive, tmp_path: Path, monkeypatch
|
|
622
|
+
) -> None:
|
|
623
|
+
"""Spec: a 308 whose Range ends before the piece means the piece is sent again."""
|
|
624
|
+
backend, source, data = upload_setup(fake_drive, tmp_path, monkeypatch)
|
|
625
|
+
fake_drive.glitches = ["drop"]
|
|
626
|
+
backend.put_file("digest-b", source)
|
|
627
|
+
assert fake_drive.blobs()["digest-b"] == data
|
|
628
|
+
assert sorted(piece_starts(fake_drive)) == [0, 0, PIECE, 2 * PIECE, 3 * PIECE]
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
@pytest.mark.parametrize("status", ["500", "502", "503", "504"])
|
|
632
|
+
def test_an_upload_resumes_after_a_server_error_on_a_piece(
|
|
633
|
+
status: str, fake_drive, tmp_path: Path, monkeypatch
|
|
634
|
+
) -> None:
|
|
635
|
+
"""Spec: HTTP 500, 502, 503 and 504 are retried through a status query."""
|
|
636
|
+
backend, source, data = upload_setup(fake_drive, tmp_path, monkeypatch)
|
|
637
|
+
fake_drive.glitches = [status]
|
|
638
|
+
backend.put_file("digest-c", source)
|
|
639
|
+
assert fake_drive.blobs()["digest-c"] == data
|
|
640
|
+
assert sorted(piece_starts(fake_drive)) == [0, 0, PIECE, 2 * PIECE, 3 * PIECE]
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
def test_an_upload_whose_last_piece_was_stored_but_not_answered_is_complete_on_the_status_query(
|
|
644
|
+
fake_drive, tmp_path: Path, monkeypatch
|
|
645
|
+
) -> None:
|
|
646
|
+
"""Spec: a 200 answer to the status query completes the upload and carries the file id."""
|
|
647
|
+
backend, source, data = upload_setup(fake_drive, tmp_path, monkeypatch, pieces=2)
|
|
648
|
+
fake_drive.glitches = ["", "drop-after-store"]
|
|
649
|
+
backend.put_file("digest-d", source)
|
|
650
|
+
assert fake_drive.blobs()["digest-d"] == data
|
|
651
|
+
assert sorted(piece_starts(fake_drive)) == [0, PIECE]
|
|
652
|
+
assert backend._ids["digest-d"] in fake_drive.files
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
def test_scattered_failures_with_progress_between_them_never_exhaust_the_retries(
|
|
656
|
+
fake_drive, tmp_path: Path, monkeypatch
|
|
657
|
+
) -> None:
|
|
658
|
+
"""Spec: only consecutive failures without progress count toward the limit."""
|
|
659
|
+
backend, source, data = upload_setup(fake_drive, tmp_path, monkeypatch, pieces=12)
|
|
660
|
+
fake_drive.glitches = ["drop-after-store"] * 2 + ["", ""] + ["drop-after-store"] * 2
|
|
661
|
+
fake_drive.glitches += ["", "drop-after-store"] * 3
|
|
662
|
+
backend.put_file("digest-e", source)
|
|
663
|
+
assert fake_drive.blobs()["digest-e"] == data
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
def test_an_upload_gives_up_after_six_waits_with_no_progress(
|
|
667
|
+
fake_drive, tmp_path: Path, monkeypatch
|
|
668
|
+
) -> None:
|
|
669
|
+
"""Spec: the seventh consecutive failure without progress raises RuntimeFailure."""
|
|
670
|
+
from letify.errors import RuntimeFailure
|
|
671
|
+
from letify.store.backends import drive
|
|
672
|
+
|
|
673
|
+
waits: list[float] = []
|
|
674
|
+
backend, source, _ = upload_setup(fake_drive, tmp_path, monkeypatch)
|
|
675
|
+
monkeypatch.setattr(drive, "RESUME_DELAYS", (1, 2, 4, 8, 16, 32))
|
|
676
|
+
monkeypatch.setattr(drive.time, "sleep", waits.append)
|
|
677
|
+
fake_drive.glitches = ["503"] * 20
|
|
678
|
+
with pytest.raises(RuntimeFailure, match="503"):
|
|
679
|
+
backend.put_file("digest-f", source)
|
|
680
|
+
assert waits == [1, 2, 4, 8, 16, 32]
|
|
681
|
+
assert len(piece_starts(fake_drive)) == 7
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
def test_a_failed_status_query_counts_as_a_failure_and_the_upload_still_resumes(
|
|
685
|
+
fake_drive, tmp_path: Path, monkeypatch
|
|
686
|
+
) -> None:
|
|
687
|
+
"""Spec: a failed status query counts as a failure, then the sender asks again."""
|
|
688
|
+
backend, source, data = upload_setup(fake_drive, tmp_path, monkeypatch)
|
|
689
|
+
fake_drive.glitches = ["503"]
|
|
690
|
+
fake_drive.status_glitches = [503, 503]
|
|
691
|
+
backend.put_file("digest-g", source)
|
|
692
|
+
assert fake_drive.blobs()["digest-g"] == data
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
def test_an_expired_upload_session_fails_saying_it_must_start_again(
|
|
696
|
+
fake_drive, tmp_path: Path, monkeypatch
|
|
697
|
+
) -> None:
|
|
698
|
+
"""Spec: HTTP 404 and 410 mean the session expired and are not retried."""
|
|
699
|
+
from letify.errors import RuntimeFailure
|
|
700
|
+
|
|
701
|
+
backend, source, _ = upload_setup(fake_drive, tmp_path, monkeypatch)
|
|
702
|
+
fake_drive.glitches = ["expired"]
|
|
703
|
+
with pytest.raises(RuntimeFailure, match="expired"):
|
|
704
|
+
backend.put_file("digest-h", source)
|
|
705
|
+
assert len(piece_starts(fake_drive)) == 1
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
def test_a_client_error_on_a_piece_is_not_retried(
|
|
709
|
+
fake_drive, tmp_path: Path, monkeypatch
|
|
710
|
+
) -> None:
|
|
711
|
+
"""Spec: a 4xx other than 308, 404 and 410 is not retried."""
|
|
712
|
+
from letify.errors import RuntimeFailure
|
|
713
|
+
|
|
714
|
+
backend, source, _ = upload_setup(fake_drive, tmp_path, monkeypatch)
|
|
715
|
+
fake_drive.glitches = ["403"]
|
|
716
|
+
with pytest.raises(RuntimeFailure, match="403"):
|
|
717
|
+
backend.put_file("digest-i", source)
|
|
718
|
+
assert len(fake_drive.uploads()) == 1
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
# -- the pack tolerates a tree that changes under it ----------------------------
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
def test_a_file_that_vanishes_during_the_pack_is_left_out_not_fatal(
|
|
725
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
726
|
+
) -> None:
|
|
727
|
+
"""Spec: Google Drive is a store, not a volume, the pack tolerates a changing tree."""
|
|
728
|
+
import os
|
|
729
|
+
import tarfile
|
|
730
|
+
|
|
731
|
+
from letify.protocol import worker as worker_module
|
|
732
|
+
|
|
733
|
+
text = worker_module.SOURCE.rstrip()
|
|
734
|
+
assert text.endswith("_serve()")
|
|
735
|
+
worker: dict[str, Any] = {"__name__": "probe"}
|
|
736
|
+
exec(compile(text[: -len("_serve()")], "worker", "exec"), worker)
|
|
737
|
+
|
|
738
|
+
root = tmp_path / "env"
|
|
739
|
+
(root / "pkg" / "__pycache__").mkdir(parents=True)
|
|
740
|
+
(root / "pkg" / "keep.py").write_text("x = 1")
|
|
741
|
+
(root / "pkg" / "__pycache__" / "keep.cpython-311.pyc").write_bytes(b"pyc")
|
|
742
|
+
temporary = root / "pkg" / "__pycache__" / "uuid.cpython-311.pyc.139776096370992"
|
|
743
|
+
temporary.write_bytes(b"half")
|
|
744
|
+
(root / "pkg" / "gone.txt").write_text("vanishes")
|
|
745
|
+
(root / "gonedir").mkdir()
|
|
746
|
+
|
|
747
|
+
real = os.listdir
|
|
748
|
+
|
|
749
|
+
def listing_then_removal(path: Any = ".") -> list[str]:
|
|
750
|
+
names = real(path)
|
|
751
|
+
if Path(path) == root / "pkg":
|
|
752
|
+
(root / "pkg" / "gone.txt").unlink()
|
|
753
|
+
if Path(path) == root:
|
|
754
|
+
(root / "gonedir").rmdir()
|
|
755
|
+
return names
|
|
756
|
+
|
|
757
|
+
monkeypatch.setattr(os, "listdir", listing_then_removal)
|
|
758
|
+
packed = worker["_op_pack_blob"](
|
|
759
|
+
{"path": str(root), "dir": str(tmp_path / "blobs"), "gzip": False}
|
|
760
|
+
)["value"]
|
|
761
|
+
monkeypatch.undo()
|
|
762
|
+
|
|
763
|
+
archive = Path(worker["_data_file"](str(tmp_path / "blobs"), packed["digest"]))
|
|
764
|
+
assert archive.stat().st_size == packed["size"]
|
|
765
|
+
with tarfile.open(archive, "r:") as tar:
|
|
766
|
+
names = sorted(tar.getnames())
|
|
767
|
+
assert "env/pkg/keep.py" in names
|
|
768
|
+
assert "env/pkg/__pycache__/keep.cpython-311.pyc" in names
|
|
769
|
+
assert "env/pkg/gone.txt" not in names
|
|
770
|
+
assert "env/gonedir" not in names
|
|
771
|
+
assert not any(".pyc." in name for name in names)
|