-
Notifications
You must be signed in to change notification settings - Fork 7
fix(guard): page cloud command request snapshots #1292
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
+600
−298
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a20ae2e
fix(guard): page cloud command request snapshots
kantorcodes d552275
test(guard): cover paged command snapshots
kantorcodes f47c41d
test(guard): cover paged command snapshots
kantorcodes b112fb4
refactor(guard): extract local request snapshots
kantorcodes 0ad2445
refactor(guard): extract local request snapshots
kantorcodes fa1abd4
fix(guard): keep small local request snapshots complete
kantorcodes 07153ec
fix(guard): advance local request snapshot cursor
kantorcodes ea990cc
test(guard): cover snapshot cursor wraparound
kantorcodes 3d2de80
Merge main into cloud command snapshot paging
kantorcodes d829103
fix(guard): cap local request snapshot payloads
kantorcodes 170c03c
test(guard): cover bounded local request snapshots
kantorcodes 4bf813e
Merge branch 'main' into fix/cloud-command-snapshot-paging
kantorcodes 3c26a97
fix(guard): cap command request snapshots
kantorcodes 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Regression coverage for Cloud command local request snapshot paging.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import base64 | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from codex_plugin_scanner.guard.runtime import command_executors | ||
|
|
||
|
|
||
| class PagingStore: | ||
| def __init__(self, guard_home: Path) -> None: | ||
| self.guard_home = guard_home | ||
| self.payloads: dict[str, object] = {} | ||
|
|
||
| def get_sync_payload(self, key: str) -> object | None: | ||
| return self.payloads.get(key) | ||
|
|
||
| def set_sync_payload(self, key: str, payload: object, now: str) -> None: | ||
| del now | ||
| self.payloads[key] = payload | ||
|
|
||
| def get_oauth_local_credentials(self, *, allow_primary: bool = False) -> object | None: | ||
| del allow_primary | ||
| return None | ||
|
|
||
| def list_approval_requests( | ||
| self, | ||
| *, | ||
| status: str | None = "pending", | ||
| harness: str | None = None, | ||
| limit: int | None = 50, | ||
| cursor: str | None = None, | ||
| search: str | None = None, | ||
| ) -> list[dict[str, object]]: | ||
| del harness, search | ||
| if status != "pending": | ||
| return [] | ||
| rows = [_approval_request_row(index) for index in range(130)] | ||
| if cursor: | ||
| padded = cursor + ("=" * (-len(cursor) % 4)) | ||
| decoded = json.loads(base64.urlsafe_b64decode(padded.encode("ascii")).decode("utf-8")) | ||
| marker_last_seen = decoded["last_seen_at"] | ||
| marker_request_id = decoded["request_id"] | ||
| rows = [ | ||
| row | ||
| for row in rows | ||
| if ( | ||
| str(row["last_seen_at"]) < marker_last_seen | ||
| or (str(row["last_seen_at"]) == marker_last_seen and str(row["request_id"]) < marker_request_id) | ||
| ) | ||
| ] | ||
| return rows if limit is None else rows[:limit] | ||
|
|
||
|
|
||
| def _approval_request_row(index: int) -> dict[str, object]: | ||
| return { | ||
| "request_id": f"req-pending-{index:03d}", | ||
| "status": "pending", | ||
| "harness": "codex", | ||
| "artifact_id": f"artifact-{index:03d}", | ||
| "artifact_hash": "b" * 64, | ||
| "policy_action": "require-reapproval", | ||
| "recommended_scope": "artifact", | ||
| "created_at": "2026-05-14T11:58:00.000Z", | ||
| "last_seen_at": f"2026-05-14T11:{59 - (index // 10):02d}:{59 - (index % 10):02d}.000Z", | ||
| "queue_group_id": "queue-group-1", | ||
| "action_envelope_json": { | ||
| "action_type": "shell_command", | ||
| "command": "npm install minimist@1.2.8", | ||
| "tool_name": "Bash", | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def test_local_request_snapshot_pages_large_pending_backlog(tmp_path: Path) -> None: | ||
| store = PagingStore(tmp_path / "guard-home") | ||
|
|
||
| first_payload = command_executors._local_request_snapshot_payload(store) | ||
| second_payload = command_executors._local_request_snapshot_payload(store) | ||
|
|
||
| assert first_payload["pendingComplete"] is False | ||
| assert first_payload["pendingCount"] == command_executors.LOCAL_REQUEST_PENDING_SNAPSHOT_LIMIT | ||
| assert first_payload["requests"][0]["localRequestId"] == "req-pending-000" | ||
| assert first_payload["requests"][-1]["localRequestId"] == "req-pending-124" | ||
| assert second_payload["pendingComplete"] is False | ||
| assert second_payload["pendingCount"] == 5 | ||
| assert second_payload["requests"][0]["localRequestId"] == "req-pending-125" | ||
| assert second_payload["requests"][-1]["localRequestId"] == "req-pending-129" |
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.