fix(sandbox): reject non-finite ownership timings (#4960)

This commit is contained in:
Tsai Yuan 2026-08-24 15:27:33 +08:00 committed by GitHub
parent 1aa813ddb3
commit 336cd3acc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -29,6 +29,7 @@ class SandboxOwnershipConfig(BaseModel):
renewal_interval_seconds: float = Field(
default=30.0,
gt=0,
allow_inf_nan=False,
description=(
"How often an owning instance refreshes its leases. The lease TTL is derived from this (interval x ttl_multiplier), so ownership liveness is independent of sandbox.idle_timeout: "
"renewal keeps running even when idle cleanup is disabled (idle_timeout: 0)."
@ -37,6 +38,7 @@ class SandboxOwnershipConfig(BaseModel):
ttl_multiplier: float = Field(
default=4.0,
ge=2,
allow_inf_nan=False,
description="Lease TTL as a multiple of renewal_interval_seconds. At least 2, so a single missed renewal (slow host, brief Redis blip) cannot expire a live owner's lease. Default 4 tolerates three consecutive misses.",
)
key_prefix: str = Field(

View File

@ -356,6 +356,13 @@ def test_ttl_multiplier_below_two_is_rejected():
SandboxOwnershipConfig(ttl_multiplier=1.0)
@pytest.mark.parametrize("field", ["renewal_interval_seconds", "ttl_multiplier"])
@pytest.mark.parametrize("value", [float("inf"), float("-inf"), float("nan")])
def test_lease_timing_rejects_non_finite_values(field, value):
with pytest.raises(ValueError):
SandboxOwnershipConfig(**{field: value})
def test_owner_ids_are_unique_per_instance():
"""Two workers on one host must not share an owner id."""
assert generate_owner_id() != generate_owner_id()