letify 2.10.3__tar.gz → 2.10.5__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 (213) hide show
  1. {letify-2.10.3 → letify-2.10.5}/PKG-INFO +1 -1
  2. {letify-2.10.3 → letify-2.10.5}/docs/SPEC.md +5 -1
  3. {letify-2.10.3 → letify-2.10.5}/letify/__init__.py +1 -1
  4. {letify-2.10.3 → letify-2.10.5}/letify/protocol/worker.py +47 -4
  5. {letify-2.10.3 → letify-2.10.5}/letify/store/backends/drive.py +87 -9
  6. {letify-2.10.3 → letify-2.10.5}/letify-core/Cargo.lock +2 -2
  7. {letify-2.10.3 → letify-2.10.5}/letify-core/Cargo.toml +1 -1
  8. {letify-2.10.3 → letify-2.10.5}/letify-ext/package-lock.json +2 -2
  9. {letify-2.10.3 → letify-2.10.5}/letify-ext/package.json +1 -1
  10. {letify-2.10.3 → letify-2.10.5}/pyproject.toml +1 -1
  11. {letify-2.10.3 → letify-2.10.5}/tests/conftest.py +38 -8
  12. {letify-2.10.3 → letify-2.10.5}/tests/test_data_streaming.py +30 -0
  13. {letify-2.10.3 → letify-2.10.5}/tests/test_drive_store.py +195 -0
  14. {letify-2.10.3 → letify-2.10.5}/.github/workflows/ci.yml +0 -0
  15. {letify-2.10.3 → letify-2.10.5}/.github/workflows/docs.yml +0 -0
  16. {letify-2.10.3 → letify-2.10.5}/.github/workflows/publish-crates.yml +0 -0
  17. {letify-2.10.3 → letify-2.10.5}/.github/workflows/publish.yml +0 -0
  18. {letify-2.10.3 → letify-2.10.5}/.github/workflows/reserve-crates.yml +0 -0
  19. {letify-2.10.3 → letify-2.10.5}/.gitignore +0 -0
  20. {letify-2.10.3 → letify-2.10.5}/.researchtree +0 -0
  21. {letify-2.10.3 → letify-2.10.5}/CLAUDE.md +0 -0
  22. {letify-2.10.3 → letify-2.10.5}/LICENSE +0 -0
  23. {letify-2.10.3 → letify-2.10.5}/PROJECT.md +0 -0
  24. {letify-2.10.3 → letify-2.10.5}/README.md +0 -0
  25. {letify-2.10.3 → letify-2.10.5}/docs/COMPONENT.md +0 -0
  26. {letify-2.10.3 → letify-2.10.5}/docs/INTENT.md +0 -0
  27. {letify-2.10.3 → letify-2.10.5}/docs/NETWORK.md +0 -0
  28. {letify-2.10.3 → letify-2.10.5}/docs/guide/01-getting-started.md +0 -0
  29. {letify-2.10.3 → letify-2.10.5}/docs/guide/02-providers.md +0 -0
  30. {letify-2.10.3 → letify-2.10.5}/docs/guide/03-execution-modes.md +0 -0
  31. {letify-2.10.3 → letify-2.10.5}/docs/guide/04-environments-and-data.md +0 -0
  32. {letify-2.10.3 → letify-2.10.5}/docs/guide/05-concurrency.md +0 -0
  33. {letify-2.10.3 → letify-2.10.5}/docs/guide/06-cost.md +0 -0
  34. {letify-2.10.3 → letify-2.10.5}/docs/guide/07-troubleshooting.md +0 -0
  35. {letify-2.10.3 → letify-2.10.5}/docs/guide/08-releasing.md +0 -0
  36. {letify-2.10.3 → letify-2.10.5}/docs/guide/README.md +0 -0
  37. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/01-/354/213/234/354/236/221/355/225/230/352/270/260.md" +0 -0
  38. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/02-/355/224/204/353/241/234/353/260/224/354/235/264/353/215/224.md" +0 -0
  39. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/03-/354/213/244/355/226/211-/353/260/251/354/213/235.md" +0 -0
  40. {letify-2.10.3 → letify-2.10.5}/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
  41. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/05-/353/217/231/354/213/234-/354/213/244/355/226/211.md" +0 -0
  42. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/06-/353/271/204/354/232/251.md" +0 -0
  43. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/07-/353/254/270/354/240/234-/355/225/264/352/262/260.md" +0 -0
  44. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/08-/353/246/264/353/246/254/354/212/244.md" +0 -0
  45. {letify-2.10.3 → letify-2.10.5}/docs/guide/ko/README.md +0 -0
  46. {letify-2.10.3 → letify-2.10.5}/docs/locales/README_ko.md +0 -0
  47. {letify-2.10.3 → letify-2.10.5}/docs/mkdocs.yml +0 -0
  48. {letify-2.10.3 → letify-2.10.5}/examples/README.md +0 -0
  49. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/.letify.example +0 -0
  50. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/00_smoke.py +0 -0
  51. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/01_sweep.py +0 -0
  52. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/02_resume.py +0 -0
  53. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/03_watch.py +0 -0
  54. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/README.md +0 -0
  55. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/README_ko.md +0 -0
  56. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/common.py +0 -0
  57. {letify-2.10.3 → letify-2.10.5}/examples/nvfp4-lora/recipe.py +0 -0
  58. {letify-2.10.3 → letify-2.10.5}/letify/cli.py +0 -0
  59. {letify-2.10.3 → letify-2.10.5}/letify/config/__init__.py +0 -0
  60. {letify-2.10.3 → letify-2.10.5}/letify/config/inventory.py +0 -0
  61. {letify-2.10.3 → letify-2.10.5}/letify/config/login.py +0 -0
  62. {letify-2.10.3 → letify-2.10.5}/letify/config/schema.py +0 -0
  63. {letify-2.10.3 → letify-2.10.5}/letify/config/secrets.py +0 -0
  64. {letify-2.10.3 → letify-2.10.5}/letify/config/writer.py +0 -0
  65. {letify-2.10.3 → letify-2.10.5}/letify/declare/__init__.py +0 -0
  66. {letify-2.10.3 → letify-2.10.5}/letify/declare/cache.py +0 -0
  67. {letify-2.10.3 → letify-2.10.5}/letify/declare/env.py +0 -0
  68. {letify-2.10.3 → letify-2.10.5}/letify/declare/exit.py +0 -0
  69. {letify-2.10.3 → letify-2.10.5}/letify/declare/function.py +0 -0
  70. {letify-2.10.3 → letify-2.10.5}/letify/declare/instance.py +0 -0
  71. {letify-2.10.3 → letify-2.10.5}/letify/declare/reduce.py +0 -0
  72. {letify-2.10.3 → letify-2.10.5}/letify/declare/replicas.py +0 -0
  73. {letify-2.10.3 → letify-2.10.5}/letify/errors.py +0 -0
  74. {letify-2.10.3 → letify-2.10.5}/letify/install.py +0 -0
  75. {letify-2.10.3 → letify-2.10.5}/letify/launcher.py +0 -0
  76. {letify-2.10.3 → letify-2.10.5}/letify/paths.py +0 -0
  77. {letify-2.10.3 → letify-2.10.5}/letify/protocol/__init__.py +0 -0
  78. {letify-2.10.3 → letify-2.10.5}/letify/protocol/codec.py +0 -0
  79. {letify-2.10.3 → letify-2.10.5}/letify/protocol/driver.py +0 -0
  80. {letify-2.10.3 → letify-2.10.5}/letify/protocol/handle.py +0 -0
  81. {letify-2.10.3 → letify-2.10.5}/letify/protocol/wire.py +0 -0
  82. {letify-2.10.3 → letify-2.10.5}/letify/providers/__init__.py +0 -0
  83. {letify-2.10.3 → letify-2.10.5}/letify/providers/base.py +0 -0
  84. {letify-2.10.3 → letify-2.10.5}/letify/providers/colab.py +0 -0
  85. {letify-2.10.3 → letify-2.10.5}/letify/providers/colab_files.py +0 -0
  86. {letify-2.10.3 → letify-2.10.5}/letify/providers/colab_keepalive.py +0 -0
  87. {letify-2.10.3 → letify-2.10.5}/letify/providers/elice.py +0 -0
  88. {letify-2.10.3 → letify-2.10.5}/letify/providers/kaggle.py +0 -0
  89. {letify-2.10.3 → letify-2.10.5}/letify/providers/kaggle_adapter.py +0 -0
  90. {letify-2.10.3 → letify-2.10.5}/letify/providers/local.py +0 -0
  91. {letify-2.10.3 → letify-2.10.5}/letify/providers/modal.py +0 -0
  92. {letify-2.10.3 → letify-2.10.5}/letify/providers/modal_adapter.py +0 -0
  93. {letify-2.10.3 → letify-2.10.5}/letify/providers/naming.py +0 -0
  94. {letify-2.10.3 → letify-2.10.5}/letify/providers/shell.py +0 -0
  95. {letify-2.10.3 → letify-2.10.5}/letify/providers/tunnel.py +0 -0
  96. {letify-2.10.3 → letify-2.10.5}/letify/providers/usage.py +0 -0
  97. {letify-2.10.3 → letify-2.10.5}/letify/remoting/__init__.py +0 -0
  98. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/__init__.py +0 -0
  99. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/client.py +0 -0
  100. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/cuda.py +0 -0
  101. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/executor.py +0 -0
  102. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/frames.py +0 -0
  103. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/guard.py +0 -0
  104. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/tensor.py +0 -0
  105. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/trace.py +0 -0
  106. {letify-2.10.3 → letify-2.10.5}/letify/remoting/device/value.py +0 -0
  107. {letify-2.10.3 → letify-2.10.5}/letify/render.py +0 -0
  108. {letify-2.10.3 → letify-2.10.5}/letify/runtime/__init__.py +0 -0
  109. {letify-2.10.3 → letify-2.10.5}/letify/runtime/bootstrap.py +0 -0
  110. {letify-2.10.3 → letify-2.10.5}/letify/runtime/broker.py +0 -0
  111. {letify-2.10.3 → letify-2.10.5}/letify/runtime/channel.py +0 -0
  112. {letify-2.10.3 → letify-2.10.5}/letify/runtime/control.py +0 -0
  113. {letify-2.10.3 → letify-2.10.5}/letify/runtime/lease.py +0 -0
  114. {letify-2.10.3 → letify-2.10.5}/letify/runtime/pool.py +0 -0
  115. {letify-2.10.3 → letify-2.10.5}/letify/runtime/session.py +0 -0
  116. {letify-2.10.3 → letify-2.10.5}/letify/runtime/takeover.py +0 -0
  117. {letify-2.10.3 → letify-2.10.5}/letify/runtime/telemetry.py +0 -0
  118. {letify-2.10.3 → letify-2.10.5}/letify/runtime/workers.py +0 -0
  119. {letify-2.10.3 → letify-2.10.5}/letify/store/__init__.py +0 -0
  120. {letify-2.10.3 → letify-2.10.5}/letify/store/backends/__init__.py +0 -0
  121. {letify-2.10.3 → letify-2.10.5}/letify/store/backends/filesystem.py +0 -0
  122. {letify-2.10.3 → letify-2.10.5}/letify/store/backends/google_auth.py +0 -0
  123. {letify-2.10.3 → letify-2.10.5}/letify/store/backends/layout.py +0 -0
  124. {letify-2.10.3 → letify-2.10.5}/letify/store/backends/objects.py +0 -0
  125. {letify-2.10.3 → letify-2.10.5}/letify/store/cas.py +0 -0
  126. {letify-2.10.3 → letify-2.10.5}/letify/store/handoff.py +0 -0
  127. {letify-2.10.3 → letify-2.10.5}/letify/store/pathdata.py +0 -0
  128. {letify-2.10.3 → letify-2.10.5}/letify/store/sendorder.py +0 -0
  129. {letify-2.10.3 → letify-2.10.5}/letify/store/volume.py +0 -0
  130. {letify-2.10.3 → letify-2.10.5}/letify/stubs.py +0 -0
  131. {letify-2.10.3 → letify-2.10.5}/letify/tools.py +0 -0
  132. {letify-2.10.3 → letify-2.10.5}/letify/transport/__init__.py +0 -0
  133. {letify-2.10.3 → letify-2.10.5}/letify/transport/agent.py +0 -0
  134. {letify-2.10.3 → letify-2.10.5}/letify/transport/announce.py +0 -0
  135. {letify-2.10.3 → letify-2.10.5}/letify/transport/link.py +0 -0
  136. {letify-2.10.3 → letify-2.10.5}/letify/transport/nat.py +0 -0
  137. {letify-2.10.3 → letify-2.10.5}/letify/transport/pipeline.py +0 -0
  138. {letify-2.10.3 → letify-2.10.5}/letify/transport/portmap.py +0 -0
  139. {letify-2.10.3 → letify-2.10.5}/letify/transport/probe.py +0 -0
  140. {letify-2.10.3 → letify-2.10.5}/letify/transport/quic.py +0 -0
  141. {letify-2.10.3 → letify-2.10.5}/letify/transport/rendezvous.py +0 -0
  142. {letify-2.10.3 → letify-2.10.5}/letify/transport/setup.py +0 -0
  143. {letify-2.10.3 → letify-2.10.5}/letify/transport/sshopts.py +0 -0
  144. {letify-2.10.3 → letify-2.10.5}/letify/transport/strategies.py +0 -0
  145. {letify-2.10.3 → letify-2.10.5}/letify-core/.gitignore +0 -0
  146. {letify-2.10.3 → letify-2.10.5}/letify-core/build.py +0 -0
  147. {letify-2.10.3 → letify-2.10.5}/letify-core/letify/Cargo.toml +0 -0
  148. {letify-2.10.3 → letify-2.10.5}/letify-core/letify/LICENSE +0 -0
  149. {letify-2.10.3 → letify-2.10.5}/letify-core/letify/README.md +0 -0
  150. {letify-2.10.3 → letify-2.10.5}/letify-core/letify/src/lib.rs +0 -0
  151. {letify-2.10.3 → letify-2.10.5}/letify-core/letify-quic/Cargo.toml +0 -0
  152. {letify-2.10.3 → letify-2.10.5}/letify-core/letify-quic/src/main.rs +0 -0
  153. {letify-2.10.3 → letify-2.10.5}/letify-core/rust-toolchain.toml +0 -0
  154. {letify-2.10.3 → letify-2.10.5}/letify-ext/.vscodeignore +0 -0
  155. {letify-2.10.3 → letify-2.10.5}/letify-ext/LICENSE +0 -0
  156. {letify-2.10.3 → letify-2.10.5}/letify-ext/README.md +0 -0
  157. {letify-2.10.3 → letify-2.10.5}/letify-ext/media/icon.svg +0 -0
  158. {letify-2.10.3 → letify-2.10.5}/letify-ext/src/cli.ts +0 -0
  159. {letify-2.10.3 → letify-2.10.5}/letify-ext/src/extension.ts +0 -0
  160. {letify-2.10.3 → letify-2.10.5}/letify-ext/src/history.ts +0 -0
  161. {letify-2.10.3 → letify-2.10.5}/letify-ext/src/model.ts +0 -0
  162. {letify-2.10.3 → letify-2.10.5}/letify-ext/src/poll.ts +0 -0
  163. {letify-2.10.3 → letify-2.10.5}/letify-ext/src/render.ts +0 -0
  164. {letify-2.10.3 → letify-2.10.5}/letify-ext/test/cli.test.ts +0 -0
  165. {letify-2.10.3 → letify-2.10.5}/letify-ext/test/manifest.test.ts +0 -0
  166. {letify-2.10.3 → letify-2.10.5}/letify-ext/test/model.test.ts +0 -0
  167. {letify-2.10.3 → letify-2.10.5}/letify-ext/test/regressions.test.ts +0 -0
  168. {letify-2.10.3 → letify-2.10.5}/letify-ext/tsconfig.json +0 -0
  169. {letify-2.10.3 → letify-2.10.5}/letify_providers.py +0 -0
  170. {letify-2.10.3 → letify-2.10.5}/scripts/sync-main.sh +0 -0
  171. {letify-2.10.3 → letify-2.10.5}/scripts/version.py +0 -0
  172. {letify-2.10.3 → letify-2.10.5}/tests/fake_kaggle_adapter.py +0 -0
  173. {letify-2.10.3 → letify-2.10.5}/tests/fake_modal_adapter.py +0 -0
  174. {letify-2.10.3 → letify-2.10.5}/tests/test_cli.py +0 -0
  175. {letify-2.10.3 → letify-2.10.5}/tests/test_cli_output.py +0 -0
  176. {letify-2.10.3 → letify-2.10.5}/tests/test_colab_keepalive.py +0 -0
  177. {letify-2.10.3 → letify-2.10.5}/tests/test_config.py +0 -0
  178. {letify-2.10.3 → letify-2.10.5}/tests/test_core.py +0 -0
  179. {letify-2.10.3 → letify-2.10.5}/tests/test_data.py +0 -0
  180. {letify-2.10.3 → letify-2.10.5}/tests/test_declare.py +0 -0
  181. {letify-2.10.3 → letify-2.10.5}/tests/test_device.py +0 -0
  182. {letify-2.10.3 → letify-2.10.5}/tests/test_device_compile.py +0 -0
  183. {letify-2.10.3 → letify-2.10.5}/tests/test_distributed.py +0 -0
  184. {letify-2.10.3 → letify-2.10.5}/tests/test_drive_handoff.py +0 -0
  185. {letify-2.10.3 → letify-2.10.5}/tests/test_editor_sessions.py +0 -0
  186. {letify-2.10.3 → letify-2.10.5}/tests/test_elice.py +0 -0
  187. {letify-2.10.3 → letify-2.10.5}/tests/test_frames.py +0 -0
  188. {letify-2.10.3 → letify-2.10.5}/tests/test_install.py +0 -0
  189. {letify-2.10.3 → letify-2.10.5}/tests/test_kaggle.py +0 -0
  190. {letify-2.10.3 → letify-2.10.5}/tests/test_kaggle_cookie.py +0 -0
  191. {letify-2.10.3 → letify-2.10.5}/tests/test_kaggle_link.py +0 -0
  192. {letify-2.10.3 → letify-2.10.5}/tests/test_link_log.py +0 -0
  193. {letify-2.10.3 → letify-2.10.5}/tests/test_notebook.py +0 -0
  194. {letify-2.10.3 → letify-2.10.5}/tests/test_parallel_placement.py +0 -0
  195. {letify-2.10.3 → letify-2.10.5}/tests/test_paths.py +0 -0
  196. {letify-2.10.3 → letify-2.10.5}/tests/test_portmap.py +0 -0
  197. {letify-2.10.3 → letify-2.10.5}/tests/test_protocol.py +0 -0
  198. {letify-2.10.3 → letify-2.10.5}/tests/test_providers.py +0 -0
  199. {letify-2.10.3 → letify-2.10.5}/tests/test_punch_sockets.py +0 -0
  200. {letify-2.10.3 → letify-2.10.5}/tests/test_quic.py +0 -0
  201. {letify-2.10.3 → letify-2.10.5}/tests/test_remoting.py +0 -0
  202. {letify-2.10.3 → letify-2.10.5}/tests/test_render.py +0 -0
  203. {letify-2.10.3 → letify-2.10.5}/tests/test_run_control.py +0 -0
  204. {letify-2.10.3 → letify-2.10.5}/tests/test_run_takeover.py +0 -0
  205. {letify-2.10.3 → letify-2.10.5}/tests/test_runtime.py +0 -0
  206. {letify-2.10.3 → letify-2.10.5}/tests/test_shell_workers.py +0 -0
  207. {letify-2.10.3 → letify-2.10.5}/tests/test_ship.py +0 -0
  208. {letify-2.10.3 → letify-2.10.5}/tests/test_store.py +0 -0
  209. {letify-2.10.3 → letify-2.10.5}/tests/test_strategies.py +0 -0
  210. {letify-2.10.3 → letify-2.10.5}/tests/test_stubs.py +0 -0
  211. {letify-2.10.3 → letify-2.10.5}/tests/test_transport.py +0 -0
  212. {letify-2.10.3 → letify-2.10.5}/tests/test_tunnel_setup.py +0 -0
  213. {letify-2.10.3 → letify-2.10.5}/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
3
+ Version: 2.10.5
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
@@ -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
 
@@ -1552,6 +1552,8 @@ A file is complete when both of these hold:
1552
1552
 
1553
1553
  Rule 1 is what makes the rule safe. A writer that pauses between two writes to a file it still holds open leaves the size and the time unchanged, so rule 2 on its own would call a half-written file complete and send it; with the descriptor still open, rule 1 refuses it. A file that is never found complete, because the body holds it open until the end or the call returns first, is not sent by the background path at all, and the final write-back below collects it as it always has.
1554
1554
 
1555
+ The worker walks an output with `os.walk`, which works the same whether or not the output already holds files placed for the call, because the listing the data patch answers is an iterator like the one the standard library returns. A poll that raises ends the background write-back for the rest of the call, so a walk that fails on an output holding placed files delivers nothing until the call returns. A file the background write-back has delivered stays on the client when the client process is stopped by SIGTERM or SIGINT before the call returns, because each file is renamed into place complete and nothing removes it on the way out.
1556
+
1555
1557
  Each file found complete is hashed and placed into the file blob cache exactly as the final write-back places one, except that it is copied rather than renamed, because the body may still write the next version of it at the output path.
1556
1558
 
1557
1559
  A path written more than once during a call, such as a checkpoint overwritten on every epoch, is one relative path with a new digest each time it is found complete. The background write-back answers this by keeping the digest it last sent for that path: a poll that reports a different digest for a path already sent starts a fresh transfer for the new digest, and does not wait for or cancel one already in flight for an older digest. The two transfers are not ordered against each other: neither waits for the other, and neither is cancelled when a newer one starts. The local file after both finish is whichever one's `os.replace` ran last, and because `os.replace` is atomic, a reader never sees a half-written file either way. This matches the rule Writing back already states for two calls writing back to the same local path: the last transfer to finish wins, and no transfer is required to finish before a newer one for the same path is allowed to start.
@@ -1654,6 +1656,8 @@ A handoff is what a volume cannot be: a value written on one provider and read o
1654
1656
 
1655
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.
1656
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
+
1657
1661
  The name `unstash` is not `fetch`, because `letify.fetch(tensor)` already reads a tensor back in `host=local`.
1658
1662
 
1659
1663
  Both run in two places with the same result:
@@ -70,7 +70,7 @@ distributed: Final = Host.distributed
70
70
  # The enum class stays importable from letify.declare.instance for letify's own use.
71
71
  del Host
72
72
 
73
- __version__ = "2.10.3"
73
+ __version__ = "2.10.5"
74
74
 
75
75
 
76
76
  def fetch(tensor): # type: ignore[no-untyped-def]
@@ -1567,11 +1567,16 @@ class _Scandir:
1567
1567
  """What the patched ``os.scandir`` answers: real entries, then the pending ones."""
1568
1568
 
1569
1569
  def __init__(self, entries, close):
1570
- self._entries = entries
1570
+ self._entries = iter(entries)
1571
1571
  self._close = close
1572
1572
 
1573
1573
  def __iter__(self):
1574
- return iter(self._entries)
1574
+ return self
1575
+
1576
+ def __next__(self):
1577
+ # ``os.walk`` calls ``next`` on what ``os.scandir`` answers, so an object that is
1578
+ # only iterable breaks every walk of a directory inside a running call.
1579
+ return next(self._entries)
1575
1580
 
1576
1581
  def __enter__(self):
1577
1582
  return self
@@ -2371,12 +2376,50 @@ def _op_get_file(request):
2371
2376
  }
2372
2377
 
2373
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
+
2374
2417
  def _op_pack_dir(request):
2375
2418
  """Pack a directory inside the runtime and return it as one payload."""
2376
2419
  buffer = io.BytesIO()
2377
2420
  root = request["path"]
2378
2421
  with tarfile.open(fileobj=buffer, mode="w:gz") as archive:
2379
- archive.add(root, arcname=os.path.basename(root.rstrip("/")), recursive=True)
2422
+ _pack_add(archive, root, os.path.basename(root.rstrip("/")))
2380
2423
  payload = buffer.getvalue()
2381
2424
  return {
2382
2425
  "ok": True,
@@ -2424,7 +2467,7 @@ def _op_pack_blob(request):
2424
2467
  hashed = _HashedFile(handle, hasher)
2425
2468
  mode = "w:gz" if request.get("gzip", True) else "w"
2426
2469
  with tarfile.open(fileobj=hashed, mode=mode) as archive:
2427
- archive.add(root, arcname=os.path.basename(root.rstrip("/")), recursive=True)
2470
+ _pack_add(archive, root, os.path.basename(root.rstrip("/")))
2428
2471
  digest = _data_finish(hasher)
2429
2472
  final = _data_file(directory, digest)
2430
2473
  os.makedirs(os.path.dirname(final), exist_ok=True)
@@ -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. This is plain
63
- standard library code that both this process and a worker can run, so a handoff made
64
- inside a shipped function uploads from the runtime and the bytes never cross the client.
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 != 308:
81
- detail = exc.read()[:300].decode(errors="replace")
82
- raise RuntimeFailure(f"Drive upload returned {exc.code}: {detail}") from exc
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
- raise RuntimeFailure(f"Drive upload failed: {exc}") from exc
85
- offset = end
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.3"
141
+ version = "2.10.5"
142
142
 
143
143
  [[package]]
144
144
  name = "letify-quic"
145
- version = "2.10.3"
145
+ version = "2.10.5"
146
146
  dependencies = [
147
147
  "quinn",
148
148
  "rcgen",
@@ -8,7 +8,7 @@ resolver = "3"
8
8
  members = ["letify", "letify-quic"]
9
9
 
10
10
  [workspace.package]
11
- version = "2.10.3"
11
+ version = "2.10.5"
12
12
  edition = "2024"
13
13
  license = "MIT"
14
14
  repository = "https://github.com/DarkPyonix/letify"
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "letify-status",
3
- "version": "2.10.3",
3
+ "version": "2.10.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "letify-status",
9
- "version": "2.10.3",
9
+ "version": "2.10.5",
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.3",
5
+ "version": "2.10.5",
6
6
  "publisher": "darkpyonix",
7
7
  "license": "SEE LICENSE IN LICENSE",
8
8
  "repository": {
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "letify"
3
- version = "2.10.3"
3
+ version = "2.10.5"
4
4
  description = "Declarations that become infrastructure."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -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"]) < session["size"]:
1236
- return answer(308, extra={"Range": f"bytes=0-{len(session['body']) - 1}"})
1237
- identifier = self._new_id()
1238
- self.files[identifier] = {
1239
- **session["meta"], "id": identifier, "content": session["body"],
1240
- "folder": False, "trashed": False,
1241
- }
1242
- return reply({"id": identifier, "name": session["meta"]["name"]})
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"}}')
@@ -1934,3 +1934,33 @@ def test_skipped_files_do_not_enter_the_progress_line(project, monkeypatch) -> N
1934
1934
  )
1935
1935
  pathdata.write_back(Runtime(), Collector(), "/rt/blobs")
1936
1936
  assert totals == [0], totals
1937
+
1938
+
1939
+ def test_a_file_written_during_a_local_call_reaches_the_client_before_the_call_returns(
1940
+ launcher_from, project
1941
+ ) -> None:
1942
+ """Spec "Writing back": the background write-back delivers each completed file of an
1943
+ output directory that already holds files, while the call still runs.
1944
+ """
1945
+ let = streaming(launcher_from)
1946
+ root = project / "selfplay"
1947
+ root.mkdir()
1948
+ (root / "selfplay-000000.pt").write_bytes(b"\x01" * 4096)
1949
+
1950
+ @let.function(device=let.providers.lab.CPU, host=letify.remote)
1951
+ def train(directory: Path, held: float) -> str:
1952
+ import time as clock
1953
+
1954
+ (directory / "selfplay-000001.pt").write_bytes(b"\x02" * 4096)
1955
+ clock.sleep(held)
1956
+ (directory / "selfplay-000002.pt").write_bytes(b"\x03" * 4096)
1957
+ clock.sleep(held)
1958
+ return "done"
1959
+
1960
+ thread, outcome = in_a_thread(lambda: train(root, HELD_S))
1961
+ try:
1962
+ wait_until(lambda: (root / "selfplay-000001.pt").is_file(), timeout=HELD_S - 2.0)
1963
+ assert thread.is_alive()
1964
+ finally:
1965
+ thread.join(timeout=120)
1966
+ assert outcome.get("value") == "done", outcome
@@ -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)
File without changes
File without changes
File without changes
File without changes
File without changes