Repository navigation
Backend: join reviewed runtime fixes (#251, #252, #266) onto the capture stack with join-verification journeys #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d518905
fix(backend): address Greptile review findings on the orchestrator
ObviousApp a5a07e6
fix(backend): retryable finalize handoff and lease-guarded file-index…
SamGu-NRX 2ce3533
fix(backend): serialize MemoryState event seq assignment
SamGu-NRX 9935ec1
test(backend): add runtime-join journeys over the capture front door
ObviousApp 020d729
test(backend): read the fake start_run failure as a local contract
ObviousApp 607697f
fix(backend): close amendment, confirmation, and retry defects on the…
ObviousApp 57ee07a
merge(backend): bring the moved burst7 base into the runtime-join branch
ObviousApp 201a175
test(backend): pin finalize failure-publication ordering, not the pub…
ObviousApp 5f77c45
Merge origin/alpha into obv/burst9-bs-runtime-join
SamGu-NRX 86ad280
test(backend): failing regressions for the #278 review findings
SamGu-NRX d392105
fix(backend): publish an escaped finalize failure once, under the slot
SamGu-NRX 5920a2c
fix(backend): a late correction re-runs on a fresh deadline
SamGu-NRX eb14571
fix(backend): a corrected result publishes its new final event
SamGu-NRX 6f57242
fix(backend): a busy index lease no longer strands committed files
SamGu-NRX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| """A busy file-index lease must not strand committed files unannounced. | ||
|
|
||
| ModalDictState merges the per-capture file index under a strict lease; a lease | ||
| that stays busy raises LeaseBusy and the commit route answers a retryable 503. | ||
| Whatever the failed request already committed must still reach | ||
| ``files_committed`` and ``on_files_committed``, and whatever it did not commit | ||
| must stay pending so the retry commits and announces it. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import time | ||
| from urllib.parse import urlparse | ||
|
|
||
| import pytest | ||
|
|
||
| from server.api.tests.conftest import sha256_hex | ||
| from server.api.tests.test_ingest import _create, _file | ||
| from server.common.backends import state_modal_dict | ||
| from server.common.backends.state_modal_dict import ModalDictState | ||
| from server.common.lease import LeaseBusy | ||
|
|
||
| _BLOBS = {"stills/s1.jpg": b"jpeg-one", "stills/s2.jpg": b"jpeg-two"} | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def shared(client, monkeypatch): | ||
| deps = client.app_state | ||
| deps.state = ModalDictState() | ||
| monkeypatch.setattr(state_modal_dict, "_INDEX_LEASE_WAIT_S", 0.05) | ||
| announced: list[list[str]] = [] | ||
| monkeypatch.setattr( | ||
| deps.hooks, "on_files_committed", lambda _capture_id, files: announced.append([f.path for f in files]) | ||
| ) | ||
| return deps, announced | ||
|
|
||
|
|
||
| def _upload_all(client, capture_id: str) -> None: | ||
| files = [_file(path, data, meta={"still": f"s{index + 1}"}) for index, (path, data) in enumerate(_BLOBS.items())] | ||
| registered = client.post(f"/v1/captures/{capture_id}/files", json={"files": files}) | ||
| assert registered.status_code == 200, registered.text | ||
| for item, data in zip(registered.json()["files"], _BLOBS.values(), strict=True): | ||
| target = item["upload"] | ||
| put = client.put(urlparse(target["url"]).path, content=data, headers=target["headers"]) | ||
| assert put.status_code == 200, put.text | ||
|
|
||
|
|
||
| def _commit(client, capture_id: str): | ||
| return client.post( | ||
| f"/v1/captures/{capture_id}/files:commit", | ||
| json={"files": [{"path": path, "sha256": sha256_hex(data)} for path, data in _BLOBS.items()]}, | ||
| ) | ||
|
|
||
|
|
||
| def _committed_events(client, capture_id: str) -> list[str]: | ||
| events = client.get(f"/v1/captures/{capture_id}/events").json()["events"] | ||
| return sorted(path for e in events if e["type"] == "files_committed" for path in e["data"]["paths"]) | ||
|
|
||
|
|
||
| def test_a_busy_lease_saves_nothing_and_the_retry_announces(client, shared): | ||
| deps, announced = shared | ||
| capture_id = _create(client, "packet-lease-busy") | ||
| _upload_all(client, capture_id) | ||
| # Another container holds a fresh lease on this capture's file index. | ||
| deps.state.put_if_absent(f"lease:files:{capture_id}", {"id": "other", "at": time.time()}) | ||
|
|
||
| busy = _commit(client, capture_id) | ||
| assert busy.status_code == 503, busy.text | ||
| assert busy.json()["errors"][0]["code"] == "lease_busy" | ||
| for path in _BLOBS: | ||
| assert deps.state.get_file(capture_id, path).state == "pending", "nothing may commit without the lease" | ||
|
|
||
| deps.state.delete_kv(f"lease:files:{capture_id}") | ||
| retried = _commit(client, capture_id) | ||
| assert retried.status_code == 200, retried.text | ||
| assert _committed_events(client, capture_id) == sorted(_BLOBS) | ||
| assert sorted(path for batch in announced for path in batch) == sorted(_BLOBS) | ||
| assert sorted(rec.path for rec in deps.state.files(capture_id)) == sorted(_BLOBS) | ||
|
|
||
|
|
||
| def test_files_committed_before_a_busy_lease_are_still_announced(client, shared, monkeypatch): | ||
| deps, announced = shared | ||
| capture_id = _create(client, "packet-lease-partial") | ||
| _upload_all(client, capture_id) | ||
|
|
||
| real_with_lease = state_modal_dict.with_lease | ||
| calls = {"n": 0} | ||
|
|
||
| def second_commit_busy(state, name, fn, **kwargs): | ||
| calls["n"] += 1 | ||
| if calls["n"] == 2: | ||
| raise LeaseBusy(f"lease {name!r} stayed busy") | ||
| return real_with_lease(state, name, fn, **kwargs) | ||
|
|
||
| monkeypatch.setattr(state_modal_dict, "with_lease", second_commit_busy) | ||
| busy = _commit(client, capture_id) | ||
| assert busy.status_code == 503, busy.text | ||
| # The first file committed before the lease went busy: it is announced now, | ||
| # because the retry will read it as already committed. | ||
| assert _committed_events(client, capture_id) == ["stills/s1.jpg"] | ||
| assert deps.state.get_file(capture_id, "stills/s2.jpg").state == "pending" | ||
|
|
||
| monkeypatch.setattr(state_modal_dict, "with_lease", real_with_lease) | ||
| retried = _commit(client, capture_id) | ||
| assert retried.status_code == 200, retried.text | ||
| assert _committed_events(client, capture_id) == sorted(_BLOBS) | ||
| assert sorted(path for batch in announced for path in batch) == sorted(_BLOBS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.