leanwarp 0.2.7__tar.gz → 0.2.8__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 (60) hide show
  1. {leanwarp-0.2.7 → leanwarp-0.2.8}/CHANGELOG.md +11 -0
  2. {leanwarp-0.2.7 → leanwarp-0.2.8}/PKG-INFO +1 -1
  3. {leanwarp-0.2.7 → leanwarp-0.2.8}/docs/http-api.md +62 -19
  4. {leanwarp-0.2.7 → leanwarp-0.2.8}/pyproject.toml +1 -1
  5. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/client.py +24 -0
  6. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/session.py +74 -14
  7. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/skills/leanwarp/references/usage.md +31 -10
  8. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_client.py +47 -0
  9. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_replay.py +90 -0
  10. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_session.py +72 -2
  11. {leanwarp-0.2.7 → leanwarp-0.2.8}/.gitignore +0 -0
  12. {leanwarp-0.2.7 → leanwarp-0.2.8}/LICENSE +0 -0
  13. {leanwarp-0.2.7 → leanwarp-0.2.8}/README.md +0 -0
  14. {leanwarp-0.2.7 → leanwarp-0.2.8}/docs/README.md +0 -0
  15. {leanwarp-0.2.7 → leanwarp-0.2.8}/docs/agents.md +0 -0
  16. {leanwarp-0.2.7 → leanwarp-0.2.8}/docs/assets/leanwarp-banner.svg +0 -0
  17. {leanwarp-0.2.7 → leanwarp-0.2.8}/docs/getting-started.md +0 -0
  18. {leanwarp-0.2.7 → leanwarp-0.2.8}/examples/lean-4.35/.gitignore +0 -0
  19. {leanwarp-0.2.7 → leanwarp-0.2.8}/examples/lean-4.35/LeanWarpExample.lean +0 -0
  20. {leanwarp-0.2.7 → leanwarp-0.2.8}/examples/lean-4.35/README.md +0 -0
  21. {leanwarp-0.2.7 → leanwarp-0.2.8}/examples/lean-4.35/lake-manifest.json +0 -0
  22. {leanwarp-0.2.7 → leanwarp-0.2.8}/examples/lean-4.35/lakefile.toml +0 -0
  23. {leanwarp-0.2.7 → leanwarp-0.2.8}/examples/lean-4.35/lean-toolchain +0 -0
  24. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/__init__.py +0 -0
  25. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/_toml.py +0 -0
  26. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/_version.py +0 -0
  27. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/agents.py +0 -0
  28. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/amounts.py +0 -0
  29. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/cli.py +0 -0
  30. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/compact.py +0 -0
  31. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/config.py +0 -0
  32. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/edits.py +0 -0
  33. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/endpoints.py +0 -0
  34. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/errors.py +0 -0
  35. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/mcp_server.py +0 -0
  36. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/outcome.py +0 -0
  37. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/project.py +0 -0
  38. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/py.typed +0 -0
  39. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/resources.py +0 -0
  40. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/skills/leanwarp/SKILL.md +0 -0
  41. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/transport.py +0 -0
  42. {leanwarp-0.2.7 → leanwarp-0.2.8}/src/leanwarp_cloud/updates.py +0 -0
  43. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/__init__.py +0 -0
  44. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/fixtures/lake-manifest-1.1.0.json +0 -0
  45. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/fixtures/lake-manifest-1.2.0.json +0 -0
  46. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_amounts.py +0 -0
  47. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_ci.py +0 -0
  48. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_config.py +0 -0
  49. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_deadline_transport.py +0 -0
  50. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_environment_compatibility.py +0 -0
  51. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_feedback.py +0 -0
  52. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_install.py +0 -0
  53. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_mcp.py +0 -0
  54. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_project.py +0 -0
  55. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_resources.py +0 -0
  56. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_retries.py +0 -0
  57. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_run_limits.py +0 -0
  58. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_setup.py +0 -0
  59. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_syntax_floor.py +0 -0
  60. {leanwarp-0.2.7 → leanwarp-0.2.8}/tests/test_tools.py +0 -0
@@ -2,6 +2,17 @@
2
2
 
3
3
  Update an installed SDK with `leanwarp update`.
4
4
 
5
+ ## 0.2.8
6
+
7
+ - `check`, `inspect` and `try_tactics` take `retention="short"`: a finished
8
+ result is then eligible for removal about 60 seconds after it finishes, so a
9
+ search loop need not delete each one. The default stays `"standard"`.
10
+ - If `apply` reports a `revision_conflict`, it keeps your local files. Check
11
+ whether the edit was written, then use `reconcile` to review what `sync`
12
+ would upload or delete.
13
+ - `apply` run again after an upload whose response was lost reports `applied`
14
+ when that upload landed, instead of asking to run the operation again.
15
+
5
16
  ## 0.2.7
6
17
 
7
18
  - Every result says whether there was a verdict. A check, batch entry or
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: leanwarp
3
- Version: 0.2.7
3
+ Version: 0.2.8
4
4
  Summary: Check and verify Lean proofs on LeanWarp from the command line, MCP or Python
5
5
  Project-URL: Repository, https://github.com/Isagoge-Labs/LeanWarp-SDK
6
6
  Project-URL: Homepage, https://isagoge.in/leanwarp
@@ -30,10 +30,12 @@ Authorization: Bearer lw_live_…
30
30
 
31
31
  Steps 3 to 5 can be one request: `POST /workspaces/{workspace_id}/run` takes the
32
32
  files to upload or delete (`files`, `delete_paths`) with the operation (`kind`,
33
- `payload`, and optionally `resource_profile` and `timeout_seconds`). It returns
34
- the new `revision` and the `operation`. Add `?wait_seconds=20` to hold it until
35
- the operation ends. One `Idempotency-Key` covers the upload and the operation;
36
- resending replays whichever already happened. Use a new key for each different
33
+ `payload`, and optionally `resource_profile`, `timeout_seconds` and
34
+ `retention`). `timeout_seconds` limits running the operation; starting a worker
35
+ does not count against it (see below). It returns the new `revision` and the
36
+ `operation`. Add `?wait_seconds=20` to hold it until the operation ends. One
37
+ `Idempotency-Key` covers the upload and the operation; resending replays
38
+ whichever already happened. Use a new key for each different
37
39
  request: the upload commits first, so files sent under a key already used for
38
40
  another operation are committed before that conflict is reported. After a
39
41
  rejected request, `GET /workspaces/{workspace_id}/files` shows whether the upload
@@ -103,10 +105,10 @@ start at 1, and columns count characters (Unicode code points).
103
105
  | --- | --- |
104
106
  | `check` | `file`, `strict` (default `true`; `false` is a draft check, in which `sorry` is only a warning). |
105
107
  | `inspect` | `file`, `line`, `column`. |
106
- | `try_tactics` | `file`, `line`, `column`, `tactics` (1 to 32), `timeout_ms` per tactic (default 30000). |
108
+ | `try_tactics` | `file`, `line`, `column`, `tactics` (1 to 32), `timeout_ms` per tactic (default 30000). Near the operation's limit, tactics tried together share the time left, and those with no time left are listed in `skipped`. |
107
109
  | `verify_target` | `file`, `candidate_declaration`, `target_statement`, `target_context` (it may import only the environment's packages, never the workspace's modules), `execution_mode` (`reusable` or `fresh`), `timeout` seconds. |
108
110
  | `holes` | `file`, `goals` (default `true`: bounded goals for the first 16 unfinished or unknown placeholders). |
109
- | `suggest` | `file`, `line`, `column`. Optional `tactics` (1 to 32) to use instead of LeanWarp's portfolio, and `timeout_ms` per tactic (learned budgets by default). |
111
+ | `suggest` | `file`, `line`, `column`. Optional `tactics` (1 to 32) to use instead of LeanWarp's portfolio, and `timeout_ms` per tactic (learned budgets by default). Near the operation's limit, tactics tried together share the time left. |
110
112
  | `extract_decls` | `file`. |
111
113
  | `sorry2lemma` | `file`, `max_extractions` (1 to 256, default 64), optional `name_prefix`, `strict_final_check` (default `false`). |
112
114
  | `check_files` | `files` (1 to 64 distinct paths), `strict` (default `true`), optional `timeout` seconds per file (default 60), which starts once the file's imports have loaded, except in a file using `native_decide`. It must fit the operation's budget for its entries (see below). |
@@ -116,6 +118,24 @@ Any `payload` may also carry `lean_options`, an object of Lean options applied a
116
118
  a lakefile's `leanOptions` would be, such as `{"maxSynthPendingDepth": 3}`. Options
117
119
  that could weaken checking are refused.
118
120
 
121
+ An operation's `timeout_seconds` limits execution to 1–600 seconds. The default
122
+ depends on the operation. For example, `check` and `inspect` default to 120 seconds.
123
+ Every stage shares that one limit: preparing the file's local imports,
124
+ capturing its proof state, checking it and running tactic trials. A check or
125
+ verification whose Lean run reaches it returns a `timeout` non-verdict, retryable
126
+ with more time. A batch keeps the entries it finished (see below). Otherwise,
127
+ including a check that reaches it while its imports are still being prepared,
128
+ the operation fails with `operation_timeout`.
129
+
130
+ Starting a worker does not count against `timeout_seconds`, so a file gets the
131
+ same limit on a warm worker as on a cold one. A start has its own limits. It
132
+ fails with `capacity_unavailable` if it is still waiting for capacity 10 minutes
133
+ after the operation's submission, queueing included (whenever the service
134
+ reclaims an operation and must start a worker for it, the wait starts afresh).
135
+ It then has up to 15 minutes to create the worker and 5 more for it to become
136
+ ready (`worker_start_timeout`). Both failures are retryable, and nothing ran.
137
+ Uploading files counts against neither limit.
138
+
119
139
  `suggest`, `check_files` and `verify_batch` stop starting new work after four
120
140
  minutes. Their default `timeout_seconds` is 600, enough for the work still in
121
141
  flight to finish. A lower `timeout_seconds` stops starting new work ten seconds
@@ -173,6 +193,16 @@ with `operation_active`; cancel it or wait. Reading an operation never deletes i
173
193
  Resubmitting a deleted request with the same `Idempotency-Key` answers
174
194
  `operation_expired` and does not run it again.
175
195
 
196
+ A `check`, `inspect` or `try_tactics` can instead ask for short retention: send
197
+ `"retention": "short"` with the operation. Its result is then eligible for
198
+ removal about 60 seconds after it finishes, instead of an hour, so a search loop
199
+ stays within its limits without a `DELETE` for each result. This is not an
200
+ erasure time: history removes results only when it needs room, so a quiet
201
+ workspace may keep one longer, and each workspace's newest operation is always
202
+ kept. Until it is removed, resending the request returns the original result;
203
+ afterwards it answers `operation_expired`, as a deleted one does. Other kinds
204
+ refuse `"short"` with `invalid_request`. The default is `"standard"`.
205
+
176
206
  ### Waiting on many operations
177
207
 
178
208
  `GET /operations?ids=A,B,…&wait_seconds=N` names up to 100 operations and holds the
@@ -280,9 +310,13 @@ twice. Use a new key for each new request.
280
310
 
281
311
  LeanWarp keeps a window of finished history, not all of it (see
282
312
  [limits](../src/leanwarp_cloud/skills/leanwarp/references/usage.md#credentials-credit-and-limits)).
283
- A replay within an hour of the original always returns its result. Later, a
284
- submission whose operation was removed returns `operation_expired` for at least
285
- 7 days, and is not run again. Reading that operation returns `not_found`.
313
+ A replay returns the original result while it is stored. Unless you explicitly
314
+ delete it, history keeps a finished result for at least an hour, or a minute
315
+ with [short retention](#releasing-results). After deletion or removal by history,
316
+ replaying the submission returns `operation_expired` for at least 7 days.
317
+ Reading the removed operation returns `not_found`. `retention` is part of the
318
+ request: leaving it out is the same as `"standard"`, and resending a key with a
319
+ different `retention` is an `idempotency_conflict`.
286
320
 
287
321
  Creating a workspace replays this way until 7 days after the workspace is
288
322
  deleted; after that, the same key creates a new workspace.
@@ -319,17 +353,18 @@ do next. It may change. Common codes:
319
353
  | `idempotency_conflict` | 409 | The `Idempotency-Key` was used for a different request. |
320
354
  | `operation_expired` | 409 | The request already ran and its result is no longer stored. It was not run again. |
321
355
  | `operation_active` | 409 | The operation has not finished, so its result cannot be deleted yet. |
322
- | `operation_limit_exceeded` | 429 | The workspace holds the account's limit of operations from the last hour (1,000 by default). |
356
+ | `operation_limit_exceeded` | 429 | The workspace stores the account's limit of operations (1,000 by default). |
323
357
  | `operation_storage_limit_exceeded` | 429 | Stored results, and the space held for queued and running operations, reached the account's limit (512 MiB by default). |
324
358
  | `source_history_limit_exceeded` | 429 | The workspace reached the account's sync limit (1,000 by default) within the last hour, or stored source reached the account's limit (64 MiB by default). |
325
359
  | `workspace_creation_limit_exceeded` | 429 | The account created its limit of workspaces within the last hour (300 by default). |
326
360
 
327
361
  The four limits above free with time, so they answer `429` with `Retry-After`:
328
- the seconds until the oldest record that counts leaves the hour-long window (or
329
- the whole window when nothing is waiting to leave it; for storage held only by
330
- running operations, 30 seconds). Deleting results you have read frees operation
331
- history and storage at once. Stored source frees only when you delete files or
332
- workspaces, so waiting does not help that case. An account's limits can be
362
+ the seconds until enough records that count can be removed, an hour after each
363
+ finished or a minute for short retention (or the whole hour-long window when
364
+ nothing is waiting to leave it; for storage held only by running operations, 30
365
+ seconds). Deleting results you have read frees operation history and storage at
366
+ once. Stored source frees only when you delete files or workspaces, so waiting
367
+ does not help that case. An account's limits can be
333
368
  raised; email contact@isagoge.in.
334
369
 
335
370
  ## Results and failed operations
@@ -398,10 +433,18 @@ until it stops. The operation's own fields are under `result.result`, and the
398
433
  [reference](../src/leanwarp_cloud/skills/leanwarp/references/usage.md#results)
399
434
  lists them. Completed operations also have `execution`, which says which worker
400
435
  ran them and what was reused, and `timing`, with `queued_ms`, `worker_ms`,
401
- `upload_ms` and `run_ms`. Parts of `run_ms` appear when Lean timed them:
402
- `elaboration_ms` (checks: importing and checking the file), `proof_state_ms` and
403
- `tactics_ms` (tactic trials: capturing the proof state, then running the
404
- tactics). After dispatch recovery, `queued_ms` is absent rather than an estimate
436
+ `upload_ms` and `run_ms`. When a worker was started for the operation,
437
+ `worker_ms` has parts, and may also include other work: `start_wait_ms`
438
+ (waiting for capacity to start one, after the wait in `queued_ms`), `create_ms`
439
+ (creating it) and `ready_ms` (waiting for it to answer). The worker also reports
440
+ its own measures of its start: `isolation_ms` (setting up resource limits and
441
+ metering), `project_ms` (preparing the project) and `engine_start_ms` (starting
442
+ the Lean engine). It times these itself, so they can overlap `create_ms` and
443
+ need not add up to `ready_ms`. Parts of `run_ms` appear when Lean timed them:
444
+ `elaboration_ms` (checks: importing and checking the file), with `imports_ms`
445
+ (loading the imports, such as Mathlib) inside it for strict checks,
446
+ `proof_state_ms` and `tactics_ms` (tactic trials: capturing the proof state,
447
+ then running the tactics). After dispatch recovery, `queued_ms` is absent rather than an estimate
405
448
  of earlier attempts. Clients should tolerate absent timing.
406
449
 
407
450
  A service update can interrupt an operation that is running. Most finish during
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "leanwarp"
3
- version = "0.2.7"
3
+ version = "0.2.8"
4
4
  description = "Check and verify Lean proofs on LeanWarp from the command line, MCP or Python"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -52,6 +52,11 @@ OperationKind = Literal[
52
52
  "verify_batch",
53
53
  ]
54
54
  OPERATION_KINDS: frozenset[str] = frozenset(get_args(OperationKind))
55
+ #: How long a finished operation is kept before history may remove it to admit new
56
+ #: work: about an hour, or about a minute with ``"short"``, which only check,
57
+ #: inspect and try_tactics accept.
58
+ Retention = Literal["standard", "short"]
59
+ RETENTIONS: frozenset[str] = frozenset(get_args(Retention))
55
60
  #: The most files one check_files operation checks.
56
61
  MAX_BATCH_FILES = 64
57
62
  #: The most proofs one verify_batch operation checks.
@@ -303,6 +308,7 @@ class LeanWarpCloud:
303
308
  payload: Mapping[str, Any],
304
309
  resource_profile: str | None = None,
305
310
  timeout_seconds: int | None = None,
311
+ retention: Retention | None = None,
306
312
  idempotency_key: str | None = None,
307
313
  deadline: float | None = None,
308
314
  ) -> dict[str, Any]:
@@ -317,6 +323,7 @@ class LeanWarpCloud:
317
323
  if type(timeout_seconds) is not int or not 1 <= timeout_seconds <= 600:
318
324
  raise UsageError("timeout_seconds must be an integer between 1 and 600")
319
325
  body["timeout_seconds"] = timeout_seconds
326
+ _set_retention(body, retention)
320
327
  return self._request(
321
328
  "POST",
322
329
  f"workspaces/{_segment(workspace_id)}/operations",
@@ -336,6 +343,7 @@ class LeanWarpCloud:
336
343
  delete_paths: tuple[str, ...] | list[str] = (),
337
344
  resource_profile: str | None = None,
338
345
  timeout_seconds: int | None = None,
346
+ retention: Retention | None = None,
339
347
  idempotency_key: str | None = None,
340
348
  deadline: float | None = None,
341
349
  wait_seconds: float = 0,
@@ -361,6 +369,7 @@ class LeanWarpCloud:
361
369
  if type(timeout_seconds) is not int or not 1 <= timeout_seconds <= 600:
362
370
  raise UsageError("timeout_seconds must be an integer between 1 and 600")
363
371
  body["timeout_seconds"] = timeout_seconds
372
+ _set_retention(body, retention)
364
373
  path = f"workspaces/{_segment(workspace_id)}/run"
365
374
  if wait_seconds > 0:
366
375
  path += f"?wait_seconds={wait_seconds:.3f}"
@@ -440,6 +449,7 @@ class LeanWarpCloud:
440
449
  *,
441
450
  expected_revision: int,
442
451
  strict: bool = True,
452
+ retention: Retention | None = None,
443
453
  idempotency_key: str | None = None,
444
454
  ) -> dict[str, Any]:
445
455
  return self.submit(
@@ -447,6 +457,7 @@ class LeanWarpCloud:
447
457
  "check",
448
458
  expected_revision=expected_revision,
449
459
  payload={"file": file, "strict": strict},
460
+ retention=retention,
450
461
  idempotency_key=idempotency_key,
451
462
  )
452
463
 
@@ -458,6 +469,7 @@ class LeanWarpCloud:
458
469
  expected_revision: int,
459
470
  line: int,
460
471
  column: int,
472
+ retention: Retention | None = None,
461
473
  idempotency_key: str | None = None,
462
474
  ) -> dict[str, Any]:
463
475
  return self.submit(
@@ -465,6 +477,7 @@ class LeanWarpCloud:
465
477
  "inspect",
466
478
  expected_revision=expected_revision,
467
479
  payload={"file": file, "line": line, "column": column},
480
+ retention=retention,
468
481
  idempotency_key=idempotency_key,
469
482
  )
470
483
 
@@ -478,6 +491,7 @@ class LeanWarpCloud:
478
491
  column: int,
479
492
  tactics: list[str],
480
493
  timeout_ms: int = 30_000,
494
+ retention: Retention | None = None,
481
495
  idempotency_key: str | None = None,
482
496
  ) -> dict[str, Any]:
483
497
  return self.submit(
@@ -491,6 +505,7 @@ class LeanWarpCloud:
491
505
  "tactics": tactics,
492
506
  "timeout_ms": timeout_ms,
493
507
  },
508
+ retention=retention,
494
509
  idempotency_key=idempotency_key,
495
510
  )
496
511
 
@@ -1054,6 +1069,15 @@ def _decoded(response: httpx.Response, idempotency_key: str | None) -> dict[str,
1054
1069
  return result
1055
1070
 
1056
1071
 
1072
+ def _set_retention(body: dict[str, Any], retention: Retention | None) -> None:
1073
+ """Send a retention only when asked for one: the service's default is standard."""
1074
+ if retention is None:
1075
+ return
1076
+ if retention not in RETENTIONS:
1077
+ raise UsageError('retention must be "standard" or "short"')
1078
+ body["retention"] = retention
1079
+
1080
+
1057
1081
  def _segment(value: str) -> str:
1058
1082
  if not value or value in {".", ".."} or "/" in value or "\\" in value:
1059
1083
  raise UsageError("identifier must be a nonempty path segment")
@@ -23,9 +23,11 @@ from .client import (
23
23
  MAX_FEEDBACK_SUMMARY,
24
24
  MIN_FEEDBACK_SUMMARY,
25
25
  OPERATION_KINDS,
26
+ RETENTIONS,
26
27
  FeedbackKind,
27
28
  FeedbackSeverity,
28
29
  LeanWarpCloud,
30
+ Retention,
29
31
  )
30
32
  from .compact import summary
31
33
  from .edits import EDITING_KINDS, edited_sha256, edited_source
@@ -705,10 +707,13 @@ class ProjectSession:
705
707
  *,
706
708
  resource_profile: str | None = None,
707
709
  timeout_seconds: int | None = None,
710
+ retention: Retention | None = None,
708
711
  ) -> dict[str, Any]:
709
712
  """Sync acknowledged source, then submit without hiding a second paid operation."""
710
713
  if kind not in OPERATION_KINDS:
711
714
  raise UsageError(f"{kind!r} is not a LeanWarp operation")
715
+ if retention is not None and retention not in RETENTIONS:
716
+ raise UsageError('retention must be "standard" or "short"')
712
717
  if timeout_seconds is not None and (
713
718
  type(timeout_seconds) is not int or not 1 <= timeout_seconds <= 600
714
719
  ):
@@ -736,6 +741,10 @@ class ProjectSession:
736
741
  body["resource_profile"] = resource_profile
737
742
  if timeout_seconds is not None:
738
743
  body["timeout_seconds"] = timeout_seconds
744
+ # Standard is the default: sending it changes nothing, so it is never
745
+ # sent, and a resend compares the same request however it was asked for.
746
+ if retention == "short":
747
+ body["retention"] = retention
739
748
  # Running the same command again after a lost response asks for the work
740
749
  # the resent request just started; submitting it too would pay twice.
741
750
  if update is None and settled is not None and _same_submission(settled[0], body):
@@ -764,6 +773,7 @@ class ProjectSession:
764
773
  wait_seconds: float,
765
774
  resource_profile: str | None = None,
766
775
  timeout_seconds: int | None = None,
776
+ retention: Retention | None = None,
767
777
  ) -> dict[str, Any]:
768
778
  """Submit, then poll briefly for the result in the same call.
769
779
 
@@ -781,7 +791,11 @@ class ProjectSession:
781
791
  "poll longer with wait"
782
792
  )
783
793
  operation = self.submit(
784
- kind, payload, resource_profile=resource_profile, timeout_seconds=timeout_seconds
794
+ kind,
795
+ payload,
796
+ resource_profile=resource_profile,
797
+ timeout_seconds=timeout_seconds,
798
+ retention=retention,
785
799
  )
786
800
  if wait_seconds == 0 or operation.get("state") in _TERMINAL_STATES:
787
801
  self._note_finished(operation)
@@ -1158,7 +1172,20 @@ class ProjectSession:
1158
1172
  after a revision conflict, run reconcile and then sync instead.
1159
1173
  """
1160
1174
  with self._locked() as state:
1161
- self._settle(state)
1175
+ pending = state.get("pending")
1176
+ try:
1177
+ self._settle(state)
1178
+ except LeanWarpCloudError as error:
1179
+ # An earlier apply's upload, resent: it meets the same conflict.
1180
+ if (
1181
+ error.code != "revision_conflict"
1182
+ or not isinstance(pending, dict)
1183
+ or pending.get("method") != "sync_files"
1184
+ ):
1185
+ raise
1186
+ raise _kept_for_reconcile(
1187
+ error, "Your local files are kept, any edit apply wrote included, but"
1188
+ ) from None
1162
1189
  _check_apply_recovery(self.directory)
1163
1190
  if not isinstance(state.get("operation_id"), str):
1164
1191
  raise SessionError("this project has not submitted an operation")
@@ -1170,10 +1197,6 @@ class ProjectSession:
1170
1197
  raise SessionError("only a suggest or sorry2lemma result can be applied")
1171
1198
  if operation.get("state") != "completed":
1172
1199
  raise SessionError("the latest operation has not completed; run `leanwarp wait`")
1173
- if operation.get("revision") != state["revision"]:
1174
- raise SessionError(
1175
- "files were uploaded after this result was computed; run it again"
1176
- )
1177
1200
  result = OperationOutcome(operation).result
1178
1201
  file = result.get("file") if result is not None else None
1179
1202
  if result is None or not isinstance(file, str) or file not in state["files"]:
@@ -1187,11 +1210,20 @@ class ProjectSession:
1187
1210
  )
1188
1211
  if not OperationOutcome(operation).successful:
1189
1212
  raise SessionError("the latest result is not a verified edit")
1190
- # Fail on a changed toolchain before the file is written, not after.
1191
- self._environment(state)
1213
+ promised = edited_sha256(str(kind), result)
1192
1214
  current = collect_lean_sources(self.root).get(file)
1193
1215
  digest = hashlib.sha256(current.encode()).hexdigest() if current is not None else None
1194
- if digest == edited_sha256(str(kind), result):
1216
+ # An earlier apply whose response was lost can have uploaded the edit;
1217
+ # settling recorded that upload, so only other changed files remain.
1218
+ if operation.get("revision") != state["revision"] and not (
1219
+ digest == promised and state["files"][file] == promised
1220
+ ):
1221
+ raise SessionError(
1222
+ "files were uploaded after this result was computed; run it again"
1223
+ )
1224
+ # Fail on a changed toolchain before the file is written, not after.
1225
+ self._environment(state)
1226
+ if digest == promised:
1195
1227
  pass # Written by an earlier apply whose upload did not finish.
1196
1228
  elif digest == state["files"][file] and current is not None:
1197
1229
  try:
@@ -1203,7 +1235,13 @@ class ProjectSession:
1203
1235
  raise SessionError(
1204
1236
  f"{file} changed locally after the result was computed; run it again"
1205
1237
  )
1206
- uploaded = self._sync(state)
1238
+ try:
1239
+ uploaded = self._sync(state)
1240
+ except LeanWarpCloudError as error:
1241
+ if error.code != "revision_conflict":
1242
+ raise
1243
+ # Applying again would meet the same conflict; say the edit is kept.
1244
+ raise _kept_for_reconcile(error, f"{file} now holds the edit, but") from None
1207
1245
  return {
1208
1246
  "status": "applied",
1209
1247
  "backup_directory": str(self.directory / "apply-backups"),
@@ -1612,9 +1650,15 @@ def block_seconds(timeout_seconds: int | None) -> float:
1612
1650
 
1613
1651
  def _same_submission(pending: Mapping[str, Any], body: Mapping[str, Any]) -> bool:
1614
1652
  """Whether a resent request submitted exactly the operation now being asked for."""
1615
- return pending["method"] in {"submit", "run"} and all(
1616
- pending["arguments"].get(field) == body.get(field)
1617
- for field in ("kind", "payload", "resource_profile", "timeout_seconds")
1653
+ arguments = pending["arguments"]
1654
+ return (
1655
+ pending["method"] in {"submit", "run"}
1656
+ and all(
1657
+ arguments.get(field) == body.get(field)
1658
+ for field in ("kind", "payload", "resource_profile", "timeout_seconds")
1659
+ )
1660
+ # Leaving retention out asks for the standard one.
1661
+ and arguments.get("retention", "standard") == body.get("retention", "standard")
1618
1662
  )
1619
1663
 
1620
1664
 
@@ -1703,7 +1747,7 @@ def _validate_journal(state: dict[str, Any]) -> None:
1703
1747
  and revision(args.get("expected_revision"))
1704
1748
  )
1705
1749
  update = {"files", "delete_paths"}
1706
- submission = {"kind", "payload", "resource_profile", "timeout_seconds"}
1750
+ submission = {"kind", "payload", "resource_profile", "timeout_seconds", "retention"}
1707
1751
  if method in {"sync_files", "run"}:
1708
1752
  valid = (
1709
1753
  valid
@@ -1742,11 +1786,27 @@ def _validate_journal(state: dict[str, Any]) -> None:
1742
1786
  and 1 <= args["timeout_seconds"] <= 600
1743
1787
  )
1744
1788
  )
1789
+ and (
1790
+ "retention" not in args
1791
+ or (isinstance(args["retention"], str) and args["retention"] in RETENTIONS)
1792
+ )
1745
1793
  )
1746
1794
  if not valid:
1747
1795
  raise SessionError(_JOURNAL_DAMAGED)
1748
1796
 
1749
1797
 
1798
+ def _kept_for_reconcile(error: LeanWarpCloudError, kept: str) -> LeanWarpCloudError:
1799
+ """Apply's upload met a revision conflict: what is kept, and what to do next."""
1800
+ return LeanWarpCloudError(
1801
+ error.status_code,
1802
+ error.code,
1803
+ f"{kept} another client changed the workspace since this project's last sync, so "
1804
+ "nothing was uploaded. Decide with the other writer which files to keep, then run "
1805
+ "reconcile and sync.",
1806
+ idempotency_key=error.idempotency_key,
1807
+ )
1808
+
1809
+
1750
1810
  def _check_apply_recovery(directory: Path) -> None:
1751
1811
  marker = directory / "apply-recovery.txt"
1752
1812
  if marker.exists() or marker.is_symlink():
@@ -108,7 +108,8 @@ LeanWarp checks the search tactic itself instead.
108
108
  Preparing imports, the portfolio and its rechecks share one four-minute budget.
109
109
 
110
110
  `apply` writes a result only onto the exact bytes it was computed from. Run it
111
- straight after `suggest` or `sorry2lemma`. The result must:
111
+ straight after `suggest` or `sorry2lemma`. To write the edit for the first time,
112
+ the result must:
112
113
 
113
114
  - be this project's latest operation, and successful;
114
115
  - have completed at the revision the project last uploaded;
@@ -116,8 +117,14 @@ straight after `suggest` or `sorry2lemma`. The result must:
116
117
 
117
118
  Each result names the SHA-256 of the source it read and of the source it
118
119
  produces. `apply` also uploads other changed files, as `sync` would. It prints
119
- `status: applied` with the new `revision`. If the upload fails after the file is
120
- written, run `apply` again. It sees the edit is already in place and uploads it.
120
+ `status: applied` with the new `revision`. If the file was written and the
121
+ upload response was lost, run `apply` again. It confirms the edit if the upload
122
+ landed, or finishes uploading it.
123
+
124
+ If `apply` reports a `revision_conflict`, your local files are preserved.
125
+ Check the file first. A conflict on an earlier pending upload can stop `apply`
126
+ before it writes the edit. Run `reconcile`, review what the next `sync` would
127
+ upload or delete, then run `sync` once you agree with those changes.
121
128
 
122
129
  `apply` refuses a read-only or hard-linked file. It also refuses a result for a
123
130
  file the operation was not asked about. The project records the files it
@@ -470,7 +477,9 @@ For many workspaces at once, `LeanWarpCloud.wait_operations(ids, wait_seconds=20
470
477
  waits on up to 100 operations in one request and returns as soon as any ends:
471
478
  `{"operations": [...], "unread": [...]}`, where `unread` names finished operations
472
479
  to read with `operation(id)`. Free storage as you go with
473
- `delete_operation(id)` once you have read a result.
480
+ `delete_operation(id)` once you have read a result, or pass `retention="short"`
481
+ to `check`, `inspect`, `try_tactics`, `submit` or `run` so history may remove the
482
+ result a minute after it finishes, with no delete.
474
483
 
475
484
  The client resends reads, `stop`, `cancel`, `delete` and writes with an
476
485
  idempotency key after `429`, `502`, `503`, `504` or a lost connection. It waits
@@ -620,16 +629,19 @@ higher. Email contact@isagoge.in to raise them. `status` reports the account's
620
629
  history limits.
621
630
 
622
631
  History is a window, not a lifetime allowance. When a new operation or sync
623
- would pass a history limit, LeanWarp removes the oldest finished operations and
624
- sync records that finished more than an hour ago, but only if that makes enough
625
- room. Otherwise nothing is removed, and the request reports the limit with HTTP
632
+ would pass a history limit, LeanWarp removes finished operations and sync
633
+ records that finished more than an hour ago (a minute for an operation with
634
+ short retention), soonest removable first, but only if that makes enough room.
635
+ Otherwise nothing is removed, and the request reports the limit with HTTP
626
636
  `429` and `Retry-After`, the seconds until room frees; the client resends after
627
637
  it, within the call's deadline. LeanWarp never removes queued or running work, each workspace's newest
628
638
  operation and sync, or your uploaded files.
629
639
 
630
- Retrying a request with the same idempotency key within the hour returns the
631
- original result. Later, a removed operation reads as `not_found`. For at least 7
632
- days, resubmitting it returns `operation_expired` without running it again.
640
+ Until history removes an operation, at least an hour after it finished (a minute
641
+ for short retention), retrying its request with the same idempotency key returns
642
+ the original result. Later, a removed operation reads as `not_found`. For at
643
+ least 7 days, resubmitting it returns `operation_expired` without running it
644
+ again.
633
645
  Keep results you need with `export`. `status` reports `history_usage`: each
634
646
  limit's `used` and `limit`.
635
647
 
@@ -638,6 +650,15 @@ it (`DELETE /operations/{id}`). Resubmitting that request returns
638
650
  `operation_expired`; see the [HTTP
639
651
  API](https://github.com/Isagoge-Labs/LeanWarp-SDK/blob/main/docs/http-api.md#releasing-results).
640
652
 
653
+ A search loop that submits many `check`, `inspect` or `try_tactics` operations
654
+ can skip the delete: submit them with `retention="short"` (`"retention": "short"`
655
+ over HTTP). Each result is then eligible for removal about 60 seconds after it
656
+ finishes. That is not an erasure time: history removes results only when it
657
+ needs room, so a quiet workspace may keep one longer, and each workspace's newest
658
+ operation is kept. Until the result is removed, a resent request returns the
659
+ original; once it has been removed, `operation_expired`. Other kinds refuse
660
+ short retention.
661
+
641
662
  Hidden directories, `.lake`, `lakefile.lean` and symlinks are never uploaded,
642
663
  and symlinked Lean files are rejected. Lake scripts and dependency builds never
643
664
  run.
@@ -445,6 +445,53 @@ def test_verify_batch_submits_inline_proofs_and_bounds_their_count() -> None:
445
445
  assert bodies[1]["payload"] == {"codes": codes, "strict": True}
446
446
 
447
447
 
448
+ def test_short_retention_is_sent_only_when_asked_for() -> None:
449
+ requests: list[httpx.Request] = []
450
+
451
+ def handle(request: httpx.Request) -> httpx.Response:
452
+ requests.append(request)
453
+ return httpx.Response(202, json={"operation_id": "op"})
454
+
455
+ with LeanWarpCloud(
456
+ "secret", base_url="https://cloud.example", transport=httpx.MockTransport(handle)
457
+ ) as api:
458
+ api.check("workspace", "Main.lean", expected_revision=1)
459
+ api.check("workspace", "Main.lean", expected_revision=1, retention="short")
460
+ api.inspect(
461
+ "workspace", "Main.lean", expected_revision=1, line=1, column=0, retention="short"
462
+ )
463
+ api.try_tactics(
464
+ "workspace",
465
+ "Main.lean",
466
+ expected_revision=1,
467
+ line=1,
468
+ column=0,
469
+ tactics=["simp"],
470
+ retention="short",
471
+ )
472
+ api.submit(
473
+ "workspace",
474
+ "check",
475
+ expected_revision=1,
476
+ payload={"file": "Main.lean"},
477
+ retention="standard",
478
+ )
479
+ api.run("workspace", "check", expected_revision=1, payload={}, retention="short")
480
+ with pytest.raises(ValueError, match="retention"):
481
+ api.check("workspace", "Main.lean", expected_revision=1, retention="brief") # type: ignore[arg-type]
482
+ bodies = [json.loads(request.content) for request in requests]
483
+ assert [body.get("retention") for body in bodies] == [
484
+ None,
485
+ "short",
486
+ "short",
487
+ "short",
488
+ "standard",
489
+ "short",
490
+ ]
491
+ assert "retention" not in bodies[0]
492
+ assert requests[-1].url.path.endswith("/run")
493
+
494
+
448
495
  @pytest.mark.parametrize("deadline", [0, 601, True, 1.5])
449
496
  def test_invalid_execution_deadline_is_rejected_before_submission(deadline: object) -> None:
450
497
  def unexpected(_request: httpx.Request) -> httpx.Response:
@@ -96,6 +96,96 @@ def test_repeating_the_same_command_after_a_lost_response_pays_once(project):
96
96
  assert journal(root)["operation_id"] == first
97
97
 
98
98
 
99
+ @pytest.mark.parametrize("lost", ["/operations", "/run"])
100
+ def test_a_resend_keeps_the_retention_it_was_submitted_with(project, lost):
101
+ root, service, session = project
102
+ session.connect()
103
+ if lost == "/operations":
104
+ session.sync()
105
+ service.lose = lost
106
+ with pytest.raises(LeanWarpTransportError):
107
+ session.submit("check", {"file": "Main.lean"}, retention="short")
108
+ assert journal(root)["pending"]["arguments"]["retention"] == "short"
109
+ first = service.operation["operation_id"]
110
+ # The same command with the same retention is the resent work, paid once.
111
+ again = session.submit("check", {"file": "Main.lean"}, retention="short")
112
+ assert again["operation_id"] == first
113
+ (one, two) = posts(service, lost)
114
+ assert one.headers["Idempotency-Key"] == two.headers["Idempotency-Key"]
115
+ assert one.content == two.content
116
+ assert json.loads(two.content)["retention"] == "short"
117
+
118
+
119
+ def test_another_retention_is_not_taken_for_the_resent_work(project):
120
+ _, service, session = project
121
+ session.connect()
122
+ session.sync()
123
+ service.lose = "/operations"
124
+ with pytest.raises(LeanWarpTransportError):
125
+ session.submit("check", {"file": "Main.lean"}, retention="short")
126
+ first = service.operation["operation_id"]
127
+ other = session.submit("check", {"file": "Main.lean"})
128
+ assert other["operation_id"] != first
129
+ (_, resent, fresh) = posts(service, "/operations")
130
+ assert json.loads(resent.content)["retention"] == "short"
131
+ assert "retention" not in json.loads(fresh.content)
132
+
133
+
134
+ @pytest.mark.parametrize(("first", "second"), [(None, "standard"), ("standard", None)])
135
+ @pytest.mark.parametrize("lost", ["/operations", "/run"])
136
+ def test_standard_retention_resends_like_an_omitted_one(project, lost, first, second):
137
+ _, service, session = project
138
+ session.connect()
139
+ if lost == "/operations":
140
+ session.sync()
141
+ service.lose = lost
142
+ with pytest.raises(LeanWarpTransportError):
143
+ session.submit("check", {"file": "Main.lean"}, retention=first)
144
+ original = service.operation["operation_id"]
145
+ again = session.submit("check", {"file": "Main.lean"}, retention=second)
146
+ # Either spelling of the default is the same request: resent once, paid once.
147
+ assert again["operation_id"] == original
148
+ (one, two) = posts(service, lost)
149
+ assert one.content == two.content and "retention" not in json.loads(two.content)
150
+
151
+
152
+ @pytest.mark.parametrize("lost", ["/operations", "/run"])
153
+ def test_a_saved_standard_retention_resends_like_an_omitted_one(project, lost):
154
+ root, service, session = project
155
+ session.connect()
156
+ if lost == "/operations":
157
+ session.sync()
158
+ service.lose = lost
159
+ with pytest.raises(LeanWarpTransportError):
160
+ session.submit("check", {"file": "Main.lean"})
161
+ original = service.operation["operation_id"]
162
+ # A journal (and its sent request) that spelled out the default still names
163
+ # the same request.
164
+ saved = journal(root)
165
+ saved["pending"]["arguments"]["retention"] = "standard"
166
+ (root / ".leanwarp/session.json").write_text(json.dumps(saved))
167
+ for key, (body, result) in list(service.receipts.items()):
168
+ if "kind" in body:
169
+ service.receipts[key] = ({**body, "retention": "standard"}, result)
170
+ again = ProjectSession(session.cloud, root).submit("check", {"file": "Main.lean"})
171
+ assert again["operation_id"] == original
172
+ assert len(posts(service, lost)) == 2
173
+
174
+
175
+ def test_a_journal_with_an_unknown_retention_is_refused(project):
176
+ root, service, session = project
177
+ session.connect()
178
+ session.sync()
179
+ service.lose = "/operations"
180
+ with pytest.raises(LeanWarpTransportError):
181
+ session.submit("check", {"file": "Main.lean"}, retention="short")
182
+ damaged = journal(root)
183
+ damaged["pending"]["arguments"]["retention"] = "forever"
184
+ (root / ".leanwarp/session.json").write_text(json.dumps(damaged))
185
+ with pytest.raises(SessionError):
186
+ ProjectSession(session.cloud, root).recover()
187
+
188
+
99
189
  def test_a_different_command_after_a_resend_runs_once_the_first_has_finished(project):
100
190
  _, service, session = project
101
191
  session.connect()
@@ -961,9 +961,15 @@ class SharedWorkspace(Service):
961
961
  def __init__(self) -> None:
962
962
  super().__init__()
963
963
  self.denied_submissions = 0
964
+ # Drop the next upload's connection before the service receives it.
965
+ self.drop_upload = False
964
966
 
965
967
  def handle(self, request: httpx.Request) -> httpx.Response:
966
968
  path = request.url.path
969
+ if request.method == "PUT" and path.endswith("/files") and self.drop_upload:
970
+ self.drop_upload = False
971
+ self.requests.append(request)
972
+ raise httpx.ConnectError("connection reset", request=request)
967
973
  if request.method == "GET" and path.endswith("/files"):
968
974
  self.requests.append(request)
969
975
  return httpx.Response(
@@ -1562,10 +1568,10 @@ def test_apply_refuses_a_result_the_client_does_not_count_as_successful(project)
1562
1568
  assert (root / "Main.lean").read_text() == SORRY
1563
1569
 
1564
1570
 
1565
- def test_apply_after_a_failed_upload_uploads_the_edit_it_already_wrote(project):
1571
+ def test_apply_after_a_refused_upload_uploads_the_edit_it_already_wrote(project):
1566
1572
  root, service, session, edited = _suggestion_for_apply(project)
1567
1573
  revision = service.revision
1568
- service.reject = True # Another device advanced the workspace first.
1574
+ service.reject = True # The service refuses the upload once.
1569
1575
  with pytest.raises(LeanWarpCloudError):
1570
1576
  session.apply()
1571
1577
  assert (root / "Main.lean").read_text() == edited
@@ -1574,6 +1580,70 @@ def test_apply_after_a_failed_upload_uploads_the_edit_it_already_wrote(project):
1574
1580
  assert applied["revision"] == service.revision == revision + 1
1575
1581
 
1576
1582
 
1583
+ def test_apply_after_a_lost_upload_response_reports_the_edit_applied(project):
1584
+ root, service, session, edited = _suggestion_for_apply(project)
1585
+ revision = service.revision
1586
+ service.lose = "/files" # The upload lands; its response does not.
1587
+ with pytest.raises(LeanWarpTransportError):
1588
+ session.apply()
1589
+ (root / "Helper.lean").write_text("def helper := 2")
1590
+ applied = session.apply()
1591
+ assert applied["status"] == "applied" and applied["file"] == "Main.lean"
1592
+ assert (root / "Main.lean").read_text() == service.sources["Main.lean"] == edited
1593
+ # Other changed files are still uploaded, as by sync.
1594
+ assert service.sources["Helper.lean"] == "def helper := 2"
1595
+ assert applied["revision"] == service.revision == revision + 2
1596
+
1597
+
1598
+ def test_apply_after_another_client_changed_the_workspace_keeps_the_edit_for_reconcile(
1599
+ shared,
1600
+ ):
1601
+ root, service, session = shared
1602
+ (root / "Main.lean").write_text(SORRY)
1603
+ service.result_for, edited = _suggested(SORRY)
1604
+ session.connect()
1605
+ session.submit_and_wait(
1606
+ "suggest", {"file": "Main.lean", "line": 2, "column": 3}, wait_seconds=0
1607
+ )
1608
+ service.sources["Other.lean"] = "def other := 1"
1609
+ service.revision += 1
1610
+ for _ in range(2): # Applying again meets the same conflict.
1611
+ with pytest.raises(LeanWarpCloudError, match="now holds the edit") as conflict:
1612
+ session.apply()
1613
+ assert conflict.value.code == "revision_conflict" and conflict.value.status == 409
1614
+ assert (root / "Main.lean").read_text() == edited
1615
+ session.reconcile()
1616
+ session.sync()
1617
+ assert service.sources["Main.lean"] == edited and "Other.lean" in service.sources
1618
+ assert session.apply()["revision"] == service.revision
1619
+
1620
+
1621
+ def test_apply_after_a_dropped_upload_and_another_clients_change_keeps_the_edit(shared):
1622
+ root, service, session = shared
1623
+ (root / "Main.lean").write_text(SORRY)
1624
+ service.result_for, edited = _suggested(SORRY)
1625
+ session.connect()
1626
+ session.submit_and_wait(
1627
+ "suggest", {"file": "Main.lean", "line": 2, "column": 3}, wait_seconds=0
1628
+ )
1629
+ service.drop_upload = True
1630
+ with pytest.raises(LeanWarpTransportError):
1631
+ session.apply()
1632
+ assert (root / "Main.lean").read_text() == edited
1633
+ # Another client advances the workspace before the upload is resent.
1634
+ service.sources["Other.lean"] = "def other := 1"
1635
+ service.revision += 1
1636
+ for _ in range(2): # The resent upload, then applying again, meet the conflict.
1637
+ with pytest.raises(LeanWarpCloudError, match="nothing was uploaded") as conflict:
1638
+ session.apply()
1639
+ assert conflict.value.code == "revision_conflict" and conflict.value.status == 409
1640
+ assert "reconcile and sync" in str(conflict.value)
1641
+ assert (root / "Main.lean").read_text() == edited
1642
+ session.reconcile()
1643
+ session.sync()
1644
+ assert service.sources["Main.lean"] == edited and "Other.lean" in service.sources
1645
+
1646
+
1577
1647
  def test_apply_writes_nothing_when_the_environment_changed(project):
1578
1648
  root, _, session, _ = _suggestion_for_apply(project)
1579
1649
  (root / "lean-toolchain").write_text("leanprover/lean4:v4.27.0\n")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes