envloop-cli 2.0.0__tar.gz → 2.2.0__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.
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/PKG-INFO +38 -28
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/README.pypi.md +34 -26
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/cli.py +3 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/cli_errors.py +5 -2
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/http.py +10 -8
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/assets.py +15 -6
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/cli_output.py +2 -2
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/client.py +24 -20
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/direct_checkpoint.py +41 -3
- envloop_cli-2.2.0/packages/asset/envloop_asset/direct_publication.py +84 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/direct_storage.py +6 -2
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/recipe_packages.py +2 -2
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/resource_cli.py +7 -17
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/runner_packages.py +27 -4
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/tags.py +20 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/transfer.py +148 -21
- envloop_cli-2.2.0/packages/chat/envloop_chat/__init__.py +1 -0
- envloop_cli-2.2.0/packages/chat/envloop_chat/cli.py +116 -0
- envloop_cli-2.2.0/packages/chat/envloop_chat/client.py +146 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/cli.py +14 -5
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/client.py +23 -10
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/http.py +1 -2
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/job_spec_cli.py +6 -3
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/named_profile.py +5 -1
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/pyproject.toml +9 -8
- envloop_cli-2.0.0/packages/asset/envloop_asset/direct_publication.py +0 -46
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/.gitignore +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/__init__.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/_optional.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/auth_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/auth_login.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/auth_workspace.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/cli_output.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/client.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/config.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/downloads.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/lifecycle_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/navigation_resources.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/profile_secrets.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/resource_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/resources.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/terminal.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/utils/__init__.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/envloop/utils/logging.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/__init__.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/checkpoint_download.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/checkpoint_upload.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/dataset_upload.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/direct_artifact.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/direct_worker_artifact.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/execution_content.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/http.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/navigation_resources.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/profile_updates.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/publication_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/publications.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/r2_upload.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/recipes.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/asset/envloop_asset/upload_strategy.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/__init__.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/cli_output.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/decision.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/inference.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/job_cost.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/job_logs.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/navigation_resources.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/resource_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/resources.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/runtime_params.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/sandbox.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/train.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/train_log_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/train_metrics_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/train_progress.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/train_runner_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/experiment/envloop_experiment/training/__init__.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/rsi-loop/envloop_rsi_loop/__init__.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/rsi-loop/envloop_rsi_loop/cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/rsi-loop/envloop_rsi_loop/cli_output.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/rsi-loop/envloop_rsi_loop/loop_cli.py +0 -0
- {envloop_cli-2.0.0 → envloop_cli-2.2.0}/packages/rsi-loop/envloop_rsi_loop/loops.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: envloop-cli
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: EnvLoop CLI and Python SDK for jobs, training, checkpoints and inference
|
|
5
5
|
Project-URL: Homepage, https://envloop.ai
|
|
6
6
|
Project-URL: Documentation, https://docs.envloop.ai
|
|
@@ -10,7 +10,9 @@ Project-URL: Agent instructions, https://docs.envloop.ai/skill.md
|
|
|
10
10
|
Requires-Python: >=3.12
|
|
11
11
|
Provides-Extra: asset
|
|
12
12
|
Requires-Dist: boto3==1.44.3; extra == 'asset'
|
|
13
|
-
Requires-Dist: envloop-envhub==
|
|
13
|
+
Requires-Dist: envloop-envhub==2.2.0; extra == 'asset'
|
|
14
|
+
Provides-Extra: chat
|
|
15
|
+
Requires-Dist: openai==3.55.1; extra == 'chat'
|
|
14
16
|
Provides-Extra: default
|
|
15
17
|
Provides-Extra: experiment
|
|
16
18
|
Provides-Extra: rsi-loop
|
|
@@ -24,29 +26,16 @@ commands are equivalent. The Python import package is `envloop`.
|
|
|
24
26
|
|
|
25
27
|
## Release compatibility
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
release. Check your installed `el --version` and `el COMMAND --help` before
|
|
31
|
-
following an example; the source package version alone does not identify
|
|
32
|
-
unreleased features.
|
|
33
|
-
|
|
34
|
-
| Unreleased source enhancement | Published 1.33.0 |
|
|
35
|
-
| --- | --- |
|
|
36
|
-
| Explicit `--json` for `el runner get\|create\|update\|delete` | These commands already output JSON; omit `--json` |
|
|
37
|
-
| `el dataset create --format harbor --update-digests` | not available; set `[[tasks]] digest` values by hand |
|
|
38
|
-
| `el trial artifact download TRIAL_ID --output DIRECTORY` | positional `DIRECTORY` only |
|
|
39
|
-
|
|
40
|
-
Execution also requires a matching platform, project permissions and published
|
|
41
|
-
Runners; package installation alone does not establish those prerequisites. See the
|
|
29
|
+
Check your installed `el --version` and `el COMMAND --help` when following an
|
|
30
|
+
example. Upgrade an older installation with `uv tool upgrade envloop-cli`, or
|
|
31
|
+
`python -m pip install --upgrade envloop-cli` in your SDK environment. See the
|
|
42
32
|
[PyPI release history](https://pypi.org/project/envloop-cli/#history) for published versions.
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
available while waiting for a compatible platform release.
|
|
34
|
+
Job execution needs project permissions, readable published Runners and a
|
|
35
|
+
platform that supports the selected Profile and Runner formats. If the platform
|
|
36
|
+
rejects a format, ask your project administrator which published versions it
|
|
37
|
+
supports. Use `envloop-cli[chat]` for the Job chat examples below and
|
|
38
|
+
`envloop-cli[asset]` for ANS parsing and verified content transfers.
|
|
50
39
|
|
|
51
40
|
## Install
|
|
52
41
|
|
|
@@ -104,6 +93,21 @@ python -m pip install "envloop-cli[asset]"
|
|
|
104
93
|
|
|
105
94
|
## Connect
|
|
106
95
|
|
|
96
|
+
For Job-bound chat, install the optional dependency in the same environment:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
python -m pip install "envloop-cli[chat]"
|
|
100
|
+
el job chat JOB_ID "Introduce yourself."
|
|
101
|
+
el job chat JOB_ID
|
|
102
|
+
el job chat JOB_ID "Hello" --json
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Text answers stream by default. `--json` returns one complete response.
|
|
106
|
+
The command uses the configured EnvLoop connection and automatically reads the
|
|
107
|
+
Job's model. The `chat` extra uses the official OpenAI Python SDK against EnvLoop;
|
|
108
|
+
it does not use an OpenAI account. `/clear` resets terminal history, `/exit` leaves,
|
|
109
|
+
and Ctrl+C exits without stopping the Job.
|
|
110
|
+
|
|
107
111
|
Use an authorized EnvLoop account and project. Browser authorization:
|
|
108
112
|
|
|
109
113
|
```bash
|
|
@@ -215,19 +219,24 @@ Sandbox Job without a Dataset:
|
|
|
215
219
|
```bash
|
|
216
220
|
el job submit --type sandbox --runner base --command 'python --version'
|
|
217
221
|
el job submit --type sandbox --runner base --image python:3.11 --wait
|
|
222
|
+
el job submit --type sandbox --provider e2b --spec REQUEST.json
|
|
218
223
|
el job list --type sandbox
|
|
219
224
|
el job log JOB_ID --follow
|
|
220
225
|
```
|
|
221
226
|
|
|
222
227
|
The platform resolves `base` to the registered `envloop/base@main` source ref and
|
|
223
228
|
freezes its immutable Revision. The Sandbox image defaults to the registered Runner image;
|
|
224
|
-
`--image` accepts an image name, tag or digest.
|
|
225
|
-
by
|
|
229
|
+
`--image` accepts an image name, tag or digest. Bench and Sandbox submissions can request a
|
|
230
|
+
platform-enabled provider by name. In a request file, `provider` is a
|
|
231
|
+
top-level field alongside `spec` and optional `overrides` in an `envloop.job/v2`
|
|
232
|
+
envelope. The `--provider` flag overrides that field and also works with the
|
|
233
|
+
named `--profile` shortcut. Omit the selection to use the platform default.
|
|
234
|
+
Job logs retain the actual captured output and collection metadata.
|
|
226
235
|
Failures include a code, readable explanation, HTTP status when available, and
|
|
227
236
|
recovery guidance without echoing arbitrary response bodies or credentials.
|
|
228
237
|
|
|
229
238
|
Bench/Sandbox Harbor Recipes accept `--harbor_env docker|process` with a canonical
|
|
230
|
-
JobSpec (`spec.schema = "envloop.job/
|
|
239
|
+
JobSpec (`spec.schema = "envloop.job/v2"`) or a named `--profile`:
|
|
231
240
|
|
|
232
241
|
```bash
|
|
233
242
|
el job submit --type sandbox --spec REQUEST.json --harbor_env process
|
|
@@ -388,8 +397,9 @@ ID is never substituted for a real asset ID. Use `RESOURCE upload get OPERATION_
|
|
|
388
397
|
only publication commit; there is no separate upload create command. Failed or timed-out operations
|
|
389
398
|
exit nonzero while preserving their safe receipt. Storage credentials are not printed.
|
|
390
399
|
|
|
391
|
-
Dataset downloads require an explicit split and accept
|
|
392
|
-
digest selectors.
|
|
400
|
+
Dataset downloads require an explicit split and accept content digest and paired task ID/tree
|
|
401
|
+
digest selectors. Directory downloads with an explicit config selector are currently unsupported
|
|
402
|
+
by the pinned ANS dependency. Downloads verify manifests, sizes, SHA-256, safe paths and executable bits. Use
|
|
393
403
|
`download REF --file-id FILE_ID --output FILE --resume` for a resumable single file. File selection
|
|
394
404
|
is separate from `get`; Profile uses a redacted `export` instead of a content download.
|
|
395
405
|
|
|
@@ -6,29 +6,16 @@ commands are equivalent. The Python import package is `envloop`.
|
|
|
6
6
|
|
|
7
7
|
## Release compatibility
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
release. Check your installed `el --version` and `el COMMAND --help` before
|
|
13
|
-
following an example; the source package version alone does not identify
|
|
14
|
-
unreleased features.
|
|
15
|
-
|
|
16
|
-
| Unreleased source enhancement | Published 1.33.0 |
|
|
17
|
-
| --- | --- |
|
|
18
|
-
| Explicit `--json` for `el runner get\|create\|update\|delete` | These commands already output JSON; omit `--json` |
|
|
19
|
-
| `el dataset create --format harbor --update-digests` | not available; set `[[tasks]] digest` values by hand |
|
|
20
|
-
| `el trial artifact download TRIAL_ID --output DIRECTORY` | positional `DIRECTORY` only |
|
|
21
|
-
|
|
22
|
-
Execution also requires a matching platform, project permissions and published
|
|
23
|
-
Runners; package installation alone does not establish those prerequisites. See the
|
|
9
|
+
Check your installed `el --version` and `el COMMAND --help` when following an
|
|
10
|
+
example. Upgrade an older installation with `uv tool upgrade envloop-cli`, or
|
|
11
|
+
`python -m pip install --upgrade envloop-cli` in your SDK environment. See the
|
|
24
12
|
[PyPI release history](https://pypi.org/project/envloop-cli/#history) for published versions.
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
available while waiting for a compatible platform release.
|
|
14
|
+
Job execution needs project permissions, readable published Runners and a
|
|
15
|
+
platform that supports the selected Profile and Runner formats. If the platform
|
|
16
|
+
rejects a format, ask your project administrator which published versions it
|
|
17
|
+
supports. Use `envloop-cli[chat]` for the Job chat examples below and
|
|
18
|
+
`envloop-cli[asset]` for ANS parsing and verified content transfers.
|
|
32
19
|
|
|
33
20
|
## Install
|
|
34
21
|
|
|
@@ -86,6 +73,21 @@ python -m pip install "envloop-cli[asset]"
|
|
|
86
73
|
|
|
87
74
|
## Connect
|
|
88
75
|
|
|
76
|
+
For Job-bound chat, install the optional dependency in the same environment:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
python -m pip install "envloop-cli[chat]"
|
|
80
|
+
el job chat JOB_ID "Introduce yourself."
|
|
81
|
+
el job chat JOB_ID
|
|
82
|
+
el job chat JOB_ID "Hello" --json
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Text answers stream by default. `--json` returns one complete response.
|
|
86
|
+
The command uses the configured EnvLoop connection and automatically reads the
|
|
87
|
+
Job's model. The `chat` extra uses the official OpenAI Python SDK against EnvLoop;
|
|
88
|
+
it does not use an OpenAI account. `/clear` resets terminal history, `/exit` leaves,
|
|
89
|
+
and Ctrl+C exits without stopping the Job.
|
|
90
|
+
|
|
89
91
|
Use an authorized EnvLoop account and project. Browser authorization:
|
|
90
92
|
|
|
91
93
|
```bash
|
|
@@ -197,19 +199,24 @@ Sandbox Job without a Dataset:
|
|
|
197
199
|
```bash
|
|
198
200
|
el job submit --type sandbox --runner base --command 'python --version'
|
|
199
201
|
el job submit --type sandbox --runner base --image python:3.11 --wait
|
|
202
|
+
el job submit --type sandbox --provider e2b --spec REQUEST.json
|
|
200
203
|
el job list --type sandbox
|
|
201
204
|
el job log JOB_ID --follow
|
|
202
205
|
```
|
|
203
206
|
|
|
204
207
|
The platform resolves `base` to the registered `envloop/base@main` source ref and
|
|
205
208
|
freezes its immutable Revision. The Sandbox image defaults to the registered Runner image;
|
|
206
|
-
`--image` accepts an image name, tag or digest.
|
|
207
|
-
by
|
|
209
|
+
`--image` accepts an image name, tag or digest. Bench and Sandbox submissions can request a
|
|
210
|
+
platform-enabled provider by name. In a request file, `provider` is a
|
|
211
|
+
top-level field alongside `spec` and optional `overrides` in an `envloop.job/v2`
|
|
212
|
+
envelope. The `--provider` flag overrides that field and also works with the
|
|
213
|
+
named `--profile` shortcut. Omit the selection to use the platform default.
|
|
214
|
+
Job logs retain the actual captured output and collection metadata.
|
|
208
215
|
Failures include a code, readable explanation, HTTP status when available, and
|
|
209
216
|
recovery guidance without echoing arbitrary response bodies or credentials.
|
|
210
217
|
|
|
211
218
|
Bench/Sandbox Harbor Recipes accept `--harbor_env docker|process` with a canonical
|
|
212
|
-
JobSpec (`spec.schema = "envloop.job/
|
|
219
|
+
JobSpec (`spec.schema = "envloop.job/v2"`) or a named `--profile`:
|
|
213
220
|
|
|
214
221
|
```bash
|
|
215
222
|
el job submit --type sandbox --spec REQUEST.json --harbor_env process
|
|
@@ -370,8 +377,9 @@ ID is never substituted for a real asset ID. Use `RESOURCE upload get OPERATION_
|
|
|
370
377
|
only publication commit; there is no separate upload create command. Failed or timed-out operations
|
|
371
378
|
exit nonzero while preserving their safe receipt. Storage credentials are not printed.
|
|
372
379
|
|
|
373
|
-
Dataset downloads require an explicit split and accept
|
|
374
|
-
digest selectors.
|
|
380
|
+
Dataset downloads require an explicit split and accept content digest and paired task ID/tree
|
|
381
|
+
digest selectors. Directory downloads with an explicit config selector are currently unsupported
|
|
382
|
+
by the pinned ANS dependency. Downloads verify manifests, sizes, SHA-256, safe paths and executable bits. Use
|
|
375
383
|
`download REF --file-id FILE_ID --output FILE --resume` for a resumable single file. File selection
|
|
376
384
|
is separate from `get`; Profile uses a redacted `export` instead of a content download.
|
|
377
385
|
|
|
@@ -278,6 +278,9 @@ def _main(argv: list[str] | None = None):
|
|
|
278
278
|
if args.group == 'setting' and args.action == 'update' and not any(getattr(args, key) is not None for key in ('name', 'slug', 'region')):
|
|
279
279
|
cli.error('provide at least one of --name, --slug or --region')
|
|
280
280
|
try:
|
|
281
|
+
if args.group == 'job' and args.action == 'chat':
|
|
282
|
+
from envloop_chat.client import require_dependencies
|
|
283
|
+
require_dependencies()
|
|
281
284
|
if args.group == 'loop':
|
|
282
285
|
from ._optional import feature_module
|
|
283
286
|
feature_module('rsi-loop', 'loop_cli').validate(args)
|
|
@@ -56,7 +56,7 @@ _register("RUNNER_PACKAGE_INVALID", "The Runner package directory is invalid. It
|
|
|
56
56
|
_register("RUNNER_REVISION_INVALID", "Use the full lowercase 40- or 64-character source commit, or a local branch or tag name, as --revision and a NAMESPACE/NAME Runner name.")
|
|
57
57
|
_register("RUNNER_REVISION_UNRESOLVED", "--revision names no local branch or tag in the Git checkout that holds DIRECTORY, or Git is unavailable. Fetch or create the branch, or pass the full source commit.")
|
|
58
58
|
_register("RUNNER_PACKAGE_UNCOMMITTED", "DIRECTORY differs from the --revision commit: it has uncommitted changes, untracked files or ignored files, all of which would be published. Commit or remove them, or pass a full commit you vouch for.")
|
|
59
|
-
_register("
|
|
59
|
+
_register("RUNNER_COMMIT_METADATA_INVALID", "Git author and message must be single-line text of at most 256 and 4096 characters, respectively.")
|
|
60
60
|
_register("RUNNER_REVISION_CONFLICT", "The platform catalog holds different package or index hashes for this Runner revision. Publish a new revision instead of changing an existing one.")
|
|
61
61
|
_register("RECIPE_PACKAGE_INVALID RECIPE_DECLARATION_INVALID RECIPE_INVALID", "--directory must hold recipe.toml with schema_version = \"envloop.recipe/v3\" and the tables [recipe] name, types; [runner] name, abi; [source] paths, optional exclude and optional repository (a https://github.com/OWNER/REPO URL if given; omit it for a local-only repository); optional [inputs], [params], [outputs] and [dependencies]. No other top-level tables or keys are allowed.")
|
|
62
62
|
_register("RECIPE_PACKAGE_SCHEMA_RETIRED", "recipe.toml uses the retired envloop.recipe-publication/v3 format. Rewrite it as schema_version = \"envloop.recipe/v3\" with [recipe], [runner] and [source] tables and add entrypoint.sh next to it; published Recipes stay readable.")
|
|
@@ -162,6 +162,8 @@ _register("RESOURCE_IN_USE", "Remove or release the listed references first. A r
|
|
|
162
162
|
_register("PUBLIC_DEPENDENCY_UNAVAILABLE", "A shared resource needs dependencies at least as readable as itself: a public Recipe needs public dependencies, and an internal Recipe needs dependencies readable in this workspace (internal or public). Change the dependencies' visibility first (the owning resource set-visibility ASSET_ID), then retry; private dependencies are never shared automatically.")
|
|
163
163
|
_register("PUBLIC_CONTENT_UNSAFE PUBLICATION_REVIEW_REQUIRED", "Content review failed for one of this name's current revisions, so it cannot be shared. Fix or retire the flagged revision, then retry.")
|
|
164
164
|
_register("CHECKPOINT_AMBIGUOUS", "More than one checkpoint matches this selection.")
|
|
165
|
+
_register("CHECKPOINT_METADATA_PENDING", "Checkpoint files are committed, but their metadata is not complete. Retry checkpoint upload complete with the same OPERATION_ID; keep the original tags and do not upload the files again.")
|
|
166
|
+
_register("ASSET_PIN_CONFLICT", "This immutable asset already has different content or tags. Keep the existing publication unchanged and use a new immutable asset identity for a different publication.")
|
|
165
167
|
_register("CHECKPOINT_UPLOAD_UNAVAILABLE", "The platform checkpoint upload service is unavailable. Ask a platform operator to check the upload service and temporary-credential configuration, then let the worker retry.")
|
|
166
168
|
_register("CHECKPOINT_UPLOAD_FORBIDDEN", "Checkpoint publication requires the current Train worker's platform-issued credential in its own workspace and project. Check the worker connection and checkpoints.write permission.")
|
|
167
169
|
_register("CHECKPOINT_UPLOAD_CLOSED", "The checkpoint upload session or its producing Trial is no longer open for publication. Check the Trial state and worker credential expiry; a stopped Trial cannot publish.")
|
|
@@ -174,6 +176,7 @@ _register("CHECKPOINT_FILES_UNAVAILABLE ARTIFACT_NOT_READY", "The requested down
|
|
|
174
176
|
_register("CHECKPOINT_FILES_INVALID ARTIFACT_LISTING_INVALID ARTIFACT_NAME_UNSAFE UNSAFE_ARTIFACT_REDIRECT ARTIFACT_SIZE_MISMATCH ARTIFACT_HASH_MISMATCH", "The download failed a safety or integrity check.")
|
|
175
177
|
_register("ARTIFACT_DOWNLOAD_FAILED", "The artifact download service rejected the request.")
|
|
176
178
|
_register("ENDPOINT_NOT_READY", "The inference endpoint is not ready.")
|
|
179
|
+
_register("CHAT_TEXT_UNAVAILABLE", "The model did not return a text answer. Use --json to inspect the complete response.")
|
|
177
180
|
_register("WAIT_TIMEOUT", "The resource did not reach the requested state before the wait timeout.")
|
|
178
181
|
_register("CLEANUP_INCOMPLETE", "The persisted cleanup operation did not complete successfully.")
|
|
179
182
|
_register("CLI_ERROR", "The command could not be completed.")
|
|
@@ -294,7 +297,7 @@ def _http_message(status: int | None) -> str:
|
|
|
294
297
|
return _MESSAGES["HTTP_ERROR"]
|
|
295
298
|
|
|
296
299
|
|
|
297
|
-
_OWN_PACKAGES = frozenset({"envloop", "envloop_asset", "envloop_experiment", "envloop_rsi_loop"})
|
|
300
|
+
_OWN_PACKAGES = frozenset({"envloop", "envloop_asset", "envloop_experiment", "envloop_rsi_loop", "envloop_chat"})
|
|
298
301
|
|
|
299
302
|
|
|
300
303
|
def validation_message(error: BaseException) -> str | None:
|
|
@@ -21,23 +21,25 @@ REDIRECT_STATUSES = {301, 302, 303, 307, 308}
|
|
|
21
21
|
RESOLVED_OWNER_FIELDS = ("dataset_owners", "checkpoint_owners", "checkpoint_owner", "runner_owner", "runner_storage_prefix")
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def validate_public_execution(value: Any, *,
|
|
25
|
-
"""
|
|
24
|
+
def validate_public_execution(value: Any, *, allow_sandbox_provider: bool = True) -> None:
|
|
25
|
+
"""Allow provider selection only on the outer Bench/Sandbox submit request."""
|
|
26
26
|
if not isinstance(value, dict):
|
|
27
27
|
return
|
|
28
|
-
|
|
29
|
-
if any(key in value for key in RESOLVED_OWNER_FIELDS) or isinstance(spec, dict) and any(key in spec for key in RESOLVED_OWNER_FIELDS):
|
|
28
|
+
if any(key in value for key in RESOLVED_OWNER_FIELDS):
|
|
30
29
|
raise ValueError("the owning project of each input is resolved by the platform; select a Dataset copy by its "
|
|
31
30
|
"asset_id and remove dataset_owners, checkpoint_owners, checkpoint_owner and runner_owner")
|
|
32
31
|
if any(key in value for key in ("executor", "backend")):
|
|
33
32
|
raise ValueError("execution backend is configured by the server")
|
|
34
|
-
if "provider" in value
|
|
35
|
-
|
|
33
|
+
if "provider" in value:
|
|
34
|
+
spec = value.get("spec")
|
|
35
|
+
kind = spec.get("type") if isinstance(spec, dict) and spec.get("schema") == "envloop.job/v2" else value.get("type")
|
|
36
|
+
if not (allow_sandbox_provider and kind in {"bench", "sandbox"} and value.get("type", kind) == kind):
|
|
37
|
+
raise ValueError("provider is only accepted as a top-level Bench/Sandbox Job submission field")
|
|
36
38
|
execution = value.get("execution")
|
|
37
39
|
if isinstance(execution, dict) and any(key in execution for key in ("executor", "provider", "backend")):
|
|
38
40
|
raise ValueError("execution backend is configured by the server")
|
|
39
|
-
for key in ("profile", "profile_overrides", "params"):
|
|
40
|
-
validate_public_execution(value.get(key),
|
|
41
|
+
for key in ("spec", "overrides", "profile", "profile_overrides", "params"):
|
|
42
|
+
validate_public_execution(value.get(key), allow_sandbox_provider=False)
|
|
41
43
|
|
|
42
44
|
|
|
43
45
|
class WaitTimeoutError(TimeoutError):
|
|
@@ -167,6 +167,9 @@ class ContentResource:
|
|
|
167
167
|
from .publications import INLINE_BYTES, hf_source, prepare, publication_ref
|
|
168
168
|
if type(wait) is not bool or not 0 <= timeout < float('inf'):
|
|
169
169
|
raise ValueError('wait must be boolean and timeout must be nonnegative')
|
|
170
|
+
if self.kind == 'checkpoint' and source.get('tags') is not None:
|
|
171
|
+
from .tags import validate_checkpoint_tags
|
|
172
|
+
source['tags'] = validate_checkpoint_tags(source['tags'])
|
|
170
173
|
if self.kind == 'recipe' and version is not None:
|
|
171
174
|
raise ValueError('Recipe versions are derived from content; omit --version')
|
|
172
175
|
source_format = source.pop('format', None)
|
|
@@ -179,22 +182,24 @@ class ContentResource:
|
|
|
179
182
|
if update_digests:
|
|
180
183
|
raise ValueError('--update-digests requires --format harbor')
|
|
181
184
|
if self.kind == 'checkpoint' and source.get('result') is not None:
|
|
182
|
-
if name is not None or version is not None or any(value is not None for key,value in source.items() if key not in {'result','directory','checkpoint_name'}):
|
|
183
|
-
raise ValueError('Worker Checkpoints accept only saved result, directory and
|
|
185
|
+
if name is not None or version is not None or any(value is not None for key,value in source.items() if key not in {'result','directory','checkpoint_name','tags'}):
|
|
186
|
+
raise ValueError('Worker Checkpoints accept only saved result, directory, checkpoint_name and tags')
|
|
184
187
|
if parent is not None:
|
|
185
188
|
raise ValueError('A worker publishes each new save with create, never update')
|
|
186
|
-
from .direct_checkpoint import publish
|
|
189
|
+
from .direct_checkpoint import check_metadata, publish
|
|
187
190
|
from .direct_storage import _DomainTransport
|
|
188
191
|
adapter = _DomainTransport(self.transport,'checkpoints')
|
|
192
|
+
tags = source.pop('tags', None)
|
|
189
193
|
try:
|
|
190
194
|
receipt = publish(adapter, source.pop('directory'), result=source.pop('result'),
|
|
191
|
-
checkpoint_name=source.pop('checkpoint_name', None), single=True,
|
|
195
|
+
checkpoint_name=source.pop('checkpoint_name', None), tags=tags, single=True,
|
|
192
196
|
upload_path=scope(self.transport) + '/checkpoints/uploads')
|
|
197
|
+
value = self.get(receipt.get('asset_id') or receipt['uri'])
|
|
198
|
+
check_metadata(value, tags=tags)
|
|
193
199
|
except BaseException as error:
|
|
194
200
|
if adapter.last is not None:
|
|
195
201
|
cast(Any,error).last = adapter.last
|
|
196
202
|
raise
|
|
197
|
-
value = self.get(receipt.get('asset_id') or receipt['uri'])
|
|
198
203
|
asset = value['asset']
|
|
199
204
|
asset['details'] = {**receipt, 'durable':True, 'upload_actor':'worker', **asset.get('details',{})}
|
|
200
205
|
return value
|
|
@@ -408,7 +413,11 @@ class ContentResource:
|
|
|
408
413
|
return envelope(self.transport.request('GET', self._operation_path(operation_id)))
|
|
409
414
|
|
|
410
415
|
def upload_complete(self, operation_id: str) -> dict[str, Any]:
|
|
411
|
-
|
|
416
|
+
value = envelope(self.transport.request('POST', self._operation_path(operation_id) + '/complete'))
|
|
417
|
+
if self.kind == 'checkpoint':
|
|
418
|
+
from .direct_checkpoint import check_metadata
|
|
419
|
+
check_metadata(value)
|
|
420
|
+
return value
|
|
412
421
|
|
|
413
422
|
def upload_abort(self, operation_id: str) -> dict[str, Any]:
|
|
414
423
|
return envelope(self.transport.request('POST', self._operation_path(operation_id) + '/abort'))
|
|
@@ -46,8 +46,8 @@ def list_layout(items: list[dict[str, Any]], args: argparse.Namespace) -> tuple[
|
|
|
46
46
|
# Like el dataset list: STATUS / UNAVAILABLE REASON appear when the page reports them, so a
|
|
47
47
|
# Revision that differs between shared copies (RUNNER_REVISION_AMBIGUOUS) is visible in the table.
|
|
48
48
|
states = tuple(field for field in ('status', 'unavailable_reason') if any(field in item for item in items))
|
|
49
|
-
headers = ('NAME', 'REVISION', '
|
|
50
|
-
render = lambda item: (item.get('name'), item.get('revision'), item.get('
|
|
49
|
+
headers = ('NAME', 'REVISION', 'AUTHOR', 'MESSAGE', 'VISIBILITY', *(field.replace('_', ' ').upper() for field in states), *LIFECYCLE)
|
|
50
|
+
render = lambda item: (item.get('name'), item.get('revision'), item.get('author'), item.get('message'),
|
|
51
51
|
item.get('visibility'), *(item.get(field) for field in states), *lifecycle(item))
|
|
52
52
|
empty = 'No runners found.'
|
|
53
53
|
elif args.group == 'dataset' and args.action == 'list':
|
|
@@ -281,32 +281,29 @@ class Runners:
|
|
|
281
281
|
from .execution_content import ExecutionContent
|
|
282
282
|
return download_content(ExecutionContent(self._server,'runner'),ref,output,file_id=file_id,**selection)
|
|
283
283
|
|
|
284
|
-
def create(self, directory: str | Path, *, revision: str, name: str | None = None,
|
|
285
|
-
executables: Sequence[str] | None = None,
|
|
286
|
-
source_ref_kind: str = 'branch', dry_run: bool = False):
|
|
284
|
+
def create(self, directory: str | Path, *, revision: str = 'main', name: str | None = None,
|
|
285
|
+
executables: Sequence[str] | None = None, dry_run: bool = False):
|
|
287
286
|
"""Create an immutable Runner revision from a local package directory."""
|
|
288
287
|
return self._publish(directory, revision=revision, name=name, executables=executables,
|
|
289
|
-
|
|
288
|
+
dry_run=dry_run)
|
|
290
289
|
|
|
291
|
-
def update(self, asset_id: str, directory: str | Path, *, revision: str, name: str | None = None,
|
|
292
|
-
executables: Sequence[str] | None = None,
|
|
293
|
-
source_ref_kind: str = 'branch', dry_run: bool = False):
|
|
290
|
+
def update(self, asset_id: str, directory: str | Path, *, revision: str = 'main', name: str | None = None,
|
|
291
|
+
executables: Sequence[str] | None = None, dry_run: bool = False):
|
|
294
292
|
"""Publish a new immutable revision of the same Runner, preserving historical bytes."""
|
|
295
293
|
return self._publish(directory, revision=revision, name=name, executables=executables,
|
|
296
|
-
|
|
294
|
+
dry_run=dry_run, asset_id=asset_id)
|
|
297
295
|
|
|
298
296
|
def _publish(self, directory: str | Path, *, revision: str, name: str | None = None,
|
|
299
|
-
executables: Sequence[str] | None = None,
|
|
300
|
-
source_ref_kind: str = 'branch', dry_run: bool = False, asset_id: str | None = None):
|
|
297
|
+
executables: Sequence[str] | None = None, dry_run: bool = False, asset_id: str | None = None):
|
|
301
298
|
"""Publish a Runner package directory as the immutable revision NAME@REVISION.
|
|
302
299
|
|
|
303
300
|
This is the Runner domain publication API with the native manifest built
|
|
304
301
|
from `directory` (runner.toml plus its main.py or main.sh entrypoint): the
|
|
305
302
|
platform stores the bytes, derives the package and index SHA-256, creates the
|
|
306
303
|
Runner asset on first use and registers the revision. `revision` is the full
|
|
307
|
-
source commit
|
|
308
|
-
|
|
309
|
-
|
|
304
|
+
source commit or a local branch/tag, resolved once to its full commit. Branch
|
|
305
|
+
and tag names remain selectable after registration. Author and message
|
|
306
|
+
come from this commit; a detached package leaves unknown metadata empty. Returns `{'asset': publication, 'runner': catalog revision}`; a dry run
|
|
310
307
|
returns the server's validation result without publishing.
|
|
311
308
|
"""
|
|
312
309
|
from envloop.http import RemoteError
|
|
@@ -314,15 +311,22 @@ class Runners:
|
|
|
314
311
|
from envloop_asset.runner_packages import (
|
|
315
312
|
REFERENCE_KEYS,
|
|
316
313
|
REVISION,
|
|
317
|
-
|
|
314
|
+
commit_metadata,
|
|
315
|
+
resolve_source_revision,
|
|
318
316
|
runner_package,
|
|
319
|
-
source_ref_valid,
|
|
320
317
|
)
|
|
321
318
|
|
|
322
|
-
if not isinstance(revision, str) or
|
|
319
|
+
if not isinstance(revision, str) or name is not None and not isinstance(name, str):
|
|
323
320
|
raise RemoteError('RUNNER_REVISION_INVALID')
|
|
324
|
-
|
|
325
|
-
|
|
321
|
+
requested_revision = None
|
|
322
|
+
if not REVISION.fullmatch(revision):
|
|
323
|
+
if len(revision) >= 40 and all(character in '0123456789abcdefABCDEF' for character in revision):
|
|
324
|
+
raise RemoteError('RUNNER_REVISION_INVALID')
|
|
325
|
+
selected = revision
|
|
326
|
+
revision, kind = resolve_source_revision(directory, selected)
|
|
327
|
+
prefix = 'refs/heads/' if kind == 'branch' else 'refs/tags/'
|
|
328
|
+
requested_revision = selected if selected.startswith(prefix) else prefix + selected
|
|
329
|
+
metadata = commit_metadata(directory, revision)
|
|
326
330
|
name, manifest, files, executables = runner_package(directory, name=name, executables=executables)
|
|
327
331
|
ref = f'envloop://runners/{name}@{revision}'
|
|
328
332
|
data = ExecutionContent(self._server, 'runner')
|
|
@@ -339,11 +343,11 @@ class Runners:
|
|
|
339
343
|
or any(not isinstance(pinned.get(key), str) for key in REFERENCE_KEYS)):
|
|
340
344
|
raise RemoteError('INVALID_RESPONSE')
|
|
341
345
|
reference = {key: pinned[key] for key in REFERENCE_KEYS}
|
|
342
|
-
if
|
|
346
|
+
if requested_revision is None and not metadata:
|
|
343
347
|
runner = self._server.get_runner_revision(name, revision)
|
|
344
348
|
else:
|
|
345
349
|
runner = self._server.register_runner_revision(
|
|
346
|
-
name, {**reference,
|
|
350
|
+
name, {**reference, **metadata, **({'requested_revision': requested_revision} if requested_revision else {})})
|
|
347
351
|
# Both catalog views must name the same stored bytes.
|
|
348
352
|
if not isinstance(runner, dict) or any(runner.get(key) != value for key, value in reference.items()):
|
|
349
353
|
raise RemoteError('RUNNER_REVISION_CONFLICT')
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import json
|
|
3
3
|
import re
|
|
4
4
|
import stat
|
|
5
|
+
from collections.abc import Mapping
|
|
5
6
|
from pathlib import Path
|
|
6
|
-
from typing import Any
|
|
7
|
+
from typing import Any, cast
|
|
7
8
|
|
|
8
9
|
from envloop.http import RemoteError
|
|
9
10
|
|
|
@@ -17,6 +18,7 @@ from .direct_storage import (
|
|
|
17
18
|
_Storage,
|
|
18
19
|
)
|
|
19
20
|
from .publications import open_file
|
|
21
|
+
from .tags import validate_checkpoint_tags, validate_tags
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
def _inventory(saved: Path) -> list[dict[str, Any]]:
|
|
@@ -99,7 +101,40 @@ def _receipt(value: Any, *, step: int, uri: str | None = None) -> dict[str, Any]
|
|
|
99
101
|
return receipt
|
|
100
102
|
|
|
101
103
|
|
|
102
|
-
def
|
|
104
|
+
def check_metadata(value: dict[str, Any], *, tags: Mapping[str, str] | None = None) -> dict[str, Any]:
|
|
105
|
+
"""A byte receipt alone does not finish a labelled publication."""
|
|
106
|
+
operation = value.get('operation')
|
|
107
|
+
operation = operation if isinstance(operation, dict) else {}
|
|
108
|
+
upload = operation.get('upload')
|
|
109
|
+
upload = upload if isinstance(upload, dict) else {}
|
|
110
|
+
state = upload.get('state')
|
|
111
|
+
failure = operation.get('error')
|
|
112
|
+
code = failure.get('code') if isinstance(failure, dict) else None
|
|
113
|
+
if state == 'metadata_conflict' or code == 'ASSET_PIN_CONFLICT':
|
|
114
|
+
error = RemoteError('ASSET_PIN_CONFLICT', 409)
|
|
115
|
+
elif (state == 'metadata_pending' or code == 'CHECKPOINT_METADATA_PENDING'
|
|
116
|
+
or state == 'committed' and operation.get('status') != 'succeeded'):
|
|
117
|
+
error = RemoteError('CHECKPOINT_METADATA_PENDING', 503)
|
|
118
|
+
else:
|
|
119
|
+
labels = tags if tags is not None else upload.get('tags') if state == 'committed' else None
|
|
120
|
+
try:
|
|
121
|
+
labels = validate_tags(labels) if labels is not None else {}
|
|
122
|
+
except ValueError:
|
|
123
|
+
error = RemoteError('INVALID_RESPONSE')
|
|
124
|
+
else:
|
|
125
|
+
asset = value.get('asset')
|
|
126
|
+
details = asset.get('details') if isinstance(asset, dict) else None
|
|
127
|
+
actual = (details.get('tags') if isinstance(details, dict) and 'tags' in details
|
|
128
|
+
else asset.get('tags') if isinstance(asset, dict) else None)
|
|
129
|
+
if not labels or isinstance(actual, dict) and all(actual.get(key) == item for key, item in labels.items()):
|
|
130
|
+
return value
|
|
131
|
+
error = RemoteError('CHECKPOINT_METADATA_PENDING', 503)
|
|
132
|
+
cast(Any, error).last = value
|
|
133
|
+
raise error
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def publish(transport: Any, directory: str | Path, *, result: str | Path | dict[str, Any], upload_path: str, checkpoint_name: str | None = None, tags: Mapping[str, str] | None = None, single: bool = False) -> dict[str, Any]:
|
|
137
|
+
labels = validate_checkpoint_tags(tags) if tags is not None else None
|
|
103
138
|
prepared = _prepare(directory, result)
|
|
104
139
|
if single:
|
|
105
140
|
if checkpoint_name is None and len(prepared) != 1:
|
|
@@ -112,7 +147,10 @@ def publish(transport: Any, directory: str | Path, *, result: str | Path | dict[
|
|
|
112
147
|
for item, saved, entries in prepared:
|
|
113
148
|
descriptor = {key: item[key] for key in ('step', 'kind', 'model', 'model_revision', 'directory', 'format') if key in item}
|
|
114
149
|
descriptor['name'] = f"checkpoint-{item['step']}"
|
|
115
|
-
|
|
150
|
+
body = dict(type='checkpoint', checkpoint=descriptor, files=entries)
|
|
151
|
+
if labels is not None:
|
|
152
|
+
body['tags'] = labels
|
|
153
|
+
session = _request(transport, upload_path, body,
|
|
116
154
|
phase='checkpoint_upload_init')
|
|
117
155
|
if isinstance(session, dict) and session.get('state') == 'committed':
|
|
118
156
|
receipt = _receipt(session, step=item['step'])
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Coordinate Checkpoint upload plans, provider strategies and metadata-only completion."""
|
|
2
|
+
import hashlib
|
|
3
|
+
import re
|
|
4
|
+
import socket
|
|
5
|
+
import ssl
|
|
6
|
+
from typing import Any
|
|
7
|
+
from urllib.error import HTTPError, URLError
|
|
8
|
+
from urllib.parse import urlencode
|
|
9
|
+
|
|
10
|
+
from envloop.http import RemoteError
|
|
11
|
+
from envloop_asset.upload_strategy import strategy_for
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def storage_failure(error: Exception) -> RemoteError:
|
|
15
|
+
reason = error.reason if isinstance(error, URLError) else error
|
|
16
|
+
response = getattr(error, 'response', None)
|
|
17
|
+
response = response if isinstance(response, dict) else {}
|
|
18
|
+
storage_error = response.get('Error')
|
|
19
|
+
storage_error = storage_error if isinstance(storage_error, dict) else {}
|
|
20
|
+
metadata = response.get('ResponseMetadata')
|
|
21
|
+
metadata = metadata if isinstance(metadata, dict) else {}
|
|
22
|
+
transport_kind = {'ConnectTimeoutError': 'timeout', 'ReadTimeoutError': 'timeout',
|
|
23
|
+
'SSLError': 'tls_error', 'EndpointConnectionError': 'connection_error',
|
|
24
|
+
'ConnectionClosedError': 'connection_error', 'ProxyConnectionError': 'connection_error'}
|
|
25
|
+
kind = ('http_error' if isinstance(error, HTTPError) or storage_error else
|
|
26
|
+
transport_kind[type(error).__name__] if type(error).__name__ in transport_kind else
|
|
27
|
+
'timeout' if isinstance(reason, TimeoutError) else
|
|
28
|
+
'tls_error' if isinstance(reason, ssl.SSLError) else
|
|
29
|
+
'dns_error' if isinstance(reason, socket.gaierror) else
|
|
30
|
+
'connection_error' if isinstance(reason, ConnectionError) else 'transport_error')
|
|
31
|
+
details = ['Storage failure: ' + kind]
|
|
32
|
+
allowed = {'SignatureDoesNotMatch', 'AccessDenied', 'ExpiredToken', 'RequestTimeTooSkewed',
|
|
33
|
+
'RequestExpired', 'SlowDown', 'ServiceUnavailable', 'InternalError',
|
|
34
|
+
'XAmzContentSHA256Mismatch', 'InvalidRequest', 'EntityTooLarge',
|
|
35
|
+
'AuthorizationQueryParametersError', 'RequestTimeout'}
|
|
36
|
+
status = error.code if isinstance(error, HTTPError) else metadata.get('HTTPStatusCode')
|
|
37
|
+
if type(status) is int and 400 <= status <= 599:
|
|
38
|
+
details.append('Storage HTTP status: ' + str(status))
|
|
39
|
+
code = storage_error.get('Code')
|
|
40
|
+
if isinstance(error, HTTPError):
|
|
41
|
+
try:
|
|
42
|
+
body = error.read(4096)
|
|
43
|
+
except Exception:
|
|
44
|
+
body = b''
|
|
45
|
+
match = re.search(rb'<Code>([A-Za-z][A-Za-z0-9]{0,63})</Code>', body)
|
|
46
|
+
code = match.group(1).decode('ascii') if match is not None else None
|
|
47
|
+
if isinstance(code, str) and code in allowed:
|
|
48
|
+
details.append('Storage error code: ' + code)
|
|
49
|
+
return RemoteError('CHECKPOINT_STORAGE_UPLOAD_FAILED', details=details)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def upload_part(transport: Any, upload_path: str, number: int, content: bytes) -> dict[str, Any]:
|
|
53
|
+
digest = hashlib.sha256(content).hexdigest()
|
|
54
|
+
path = upload_path + f'/parts/{number}'
|
|
55
|
+
query = {'sha256': digest}
|
|
56
|
+
plan = transport.request('POST', path + '/url?' + urlencode(query))
|
|
57
|
+
expected = {'number': number, 'size': len(content), 'sha256': digest}
|
|
58
|
+
if not isinstance(plan, dict) or plan.get('transport') != 'direct' or plan.get('part') != expected:
|
|
59
|
+
raise RemoteError('INVALID_RESPONSE')
|
|
60
|
+
if plan.get('stored') is True:
|
|
61
|
+
strategy_for(plan.get('provider'))
|
|
62
|
+
return expected
|
|
63
|
+
lease = plan.get('lease')
|
|
64
|
+
if not isinstance(lease, str) or not re.fullmatch(r'[a-f0-9]{32}', lease):
|
|
65
|
+
raise RemoteError('INVALID_RESPONSE')
|
|
66
|
+
|
|
67
|
+
def report(outcome: str) -> Any:
|
|
68
|
+
return transport.request('POST', path + '/staged?' + urlencode({**query, 'lease': lease, 'outcome': outcome}))
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
strategy_for(plan.get('provider')).upload(plan, content, api_base=transport.base)
|
|
72
|
+
except Exception as error:
|
|
73
|
+
failure = error if isinstance(error, RemoteError) else storage_failure(error)
|
|
74
|
+
if isinstance(error, HTTPError):
|
|
75
|
+
error.close()
|
|
76
|
+
try:
|
|
77
|
+
report('failed')
|
|
78
|
+
except Exception:
|
|
79
|
+
pass
|
|
80
|
+
raise failure from None
|
|
81
|
+
result = report('stored')
|
|
82
|
+
if result != expected:
|
|
83
|
+
raise RemoteError('INVALID_RESPONSE')
|
|
84
|
+
return expected
|