Skip to content

Commit 2e5bb46

Browse files
Pigbibicodex
andcommitted
cap offline e3 receipt freshness
Co-Authored-By: Codex <noreply@openai.com>
1 parent 15ba8c3 commit 2e5bb46

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

runtime_preflight.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
E3_RECEIPT_SCHEMA_VERSION = "qmt.e3.receipt.v1"
1616
E3_RECEIPT_REQUIRED_SUMMARY_COUNTS = ("accounts", "positions", "orders", "fills", "cash", "ledger")
17+
E3_RECEIPT_MAX_FRESHNESS_SECONDS = 300
1718
_E3_RECEIPT_FIELDS = frozenset(
1819
{
1920
"schema_version",
@@ -133,8 +134,12 @@ def _validate_e3_freshness(
133134
issues: list[PreflightIssue],
134135
) -> None:
135136
freshness_seconds = receipt.get("freshness_seconds")
136-
if not isinstance(freshness_seconds, int) or isinstance(freshness_seconds, bool) or freshness_seconds < 0:
137-
issues.append(PreflightIssue("invalid_freshness", "Receipt freshness must be a non-negative integer."))
137+
if (
138+
not isinstance(freshness_seconds, int)
139+
or isinstance(freshness_seconds, bool)
140+
or not 0 <= freshness_seconds <= E3_RECEIPT_MAX_FRESHNESS_SECONDS
141+
):
142+
issues.append(PreflightIssue("invalid_freshness", "Receipt freshness is outside the accepted window."))
138143
return
139144

140145
as_of = receipt.get("as_of")

tests/test_runtime_preflight.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
import pytest
99

10-
from runtime_preflight import E3_RECEIPT_SCHEMA_VERSION, run_preflight, validate_e3_receipt
10+
from runtime_preflight import (
11+
E3_RECEIPT_MAX_FRESHNESS_SECONDS,
12+
E3_RECEIPT_SCHEMA_VERSION,
13+
run_preflight,
14+
validate_e3_receipt,
15+
)
1116
from scripts.preflight_qmt_runtime import main
1217

1318

@@ -181,6 +186,7 @@ def test_e3_receipt_validator_accepts_complete_sanitized_receipt():
181186
("summary_counts", {"accounts": 1}, "invalid_summary_counts"),
182187
("as_of", "not-a-timestamp", "invalid_as_of"),
183188
("freshness_seconds", -1, "invalid_freshness"),
189+
("freshness_seconds", E3_RECEIPT_MAX_FRESHNESS_SECONDS + 1, "invalid_freshness"),
184190
("no_order", False, "no_order_required"),
185191
("verify_only", False, "verify_only_required"),
186192
],

0 commit comments

Comments
 (0)