Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
097f53d
Bound JSON encoder setup in Cell proof regression cases
zlareb1 Nov 20, 2026
4443caa
Compare Cell proof defaults in one canonical mapping
zlareb1 Nov 20, 2026
b74fc6e
Scope person-query observations to the decision task
zlareb1 Nov 20, 2026
9d57ebb
Cleanup tests measure their shared idle deadline
zlareb1 Nov 20, 2026
d48c7fd
Clear key-lock health after successful lease acquisition
zlareb1 Nov 19, 2026
c103988
Scope person-query observations to the decision task
zlareb1 Nov 20, 2026
24acbce
Bound JSON encoder setup in Cell proof regression cases
zlareb1 Nov 20, 2026
bc30cee
Compare Cell proof defaults in one canonical mapping
zlareb1 Nov 20, 2026
d66d60b
Cleanup tests measure their shared idle deadline
zlareb1 Nov 20, 2026
f78fe82
Keep first-content deadline fixture on an idle clock
zlareb1 Nov 21, 2026
85a3323
Keep trigger deadline fixtures on their private loop
zlareb1 Nov 21, 2026
aa2a0d2
Merge current main into key-lock health recovery
zlareb1 Nov 21, 2026
a96e4fa
Compose current documentation with the reviewed change
zlareb1 Nov 21, 2026
23cc087
Compose the reviewed scanner action pin with the change
zlareb1 Nov 21, 2026
f928507
Compose the reviewed test prerequisites with the change
zlareb1 Nov 21, 2026
d2b172e
Compose current test prerequisites with the change
zlareb1 Nov 21, 2026
12eb9ab
Retain proposal review provenance in the Cell proof
zlareb1 Nov 21, 2026
a191e0d
Cover the review provenance default in Cell proof refusals
zlareb1 Nov 21, 2026
023e10a
Merge current main into Clear key-lock health after successful lease …
zlareb1 Nov 21, 2026
4708f8f
Merge current main into PR #998 composition
zlareb1 Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions scripts/gates/testsupport/cell_trigger/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ def expected(self, row, audit, context, *, api, metadata, driver):
"workload semantic/active",
)
need(row["confidence"] == 1.0, "workload confidence")
for field, default in self.p["sparse_defaults"].items():
equal(row[field], default)
equal(
{field: row[field] for field in self.p["sparse_defaults"]},
self.p["sparse_defaults"],
)
need(
row["value"] == json.dumps(payload(key)) and row["content_sha256"] == content_hash(key),
"exact stored payload/hash",
Expand Down
3 changes: 2 additions & 1 deletion server/memory/store/key_write_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from server.core.errors import PreconditionFailedError
from server.core.leases import LeaseBusy, LeaseLost
from server.core.repo_base import _CHClient, _default_client
from server.observability import degradations
from server.observability import degradations, provider_health


def lock_name(
Expand Down Expand Up @@ -109,6 +109,7 @@ async def _take(self, name: str, until: float) -> leases.Lease:
) from e
if lease is None:
raise _busy()
provider_health.record_success("memory_key_lock")
return lease

@asynccontextmanager
Expand Down
72 changes: 71 additions & 1 deletion tests/unit/test_cell_attach_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest.mock import AsyncMock

import pytest
import pytest_asyncio

from server.cli import cell_attach, cell_control
from tests.unit.cell_control_owner import owner
Expand Down Expand Up @@ -96,7 +97,8 @@ async def work():
await asyncio.gather(*owned_tasks, return_exceptions=True)


@pytest.mark.asyncio
@pytest.mark.asyncio(loop_scope="function")
@pytest.mark.usefixtures("_cleanup_clock")
async def test_lock_owner_bounds_close_inside_the_same_cleanup_allowance():
closing = asyncio.Event()
conn = AsyncMock()
Expand Down Expand Up @@ -152,3 +154,71 @@ async def open(owned, what):
if failed:
assert caught.value is original
conn.close.assert_awaited_once()


@pytest.mark.parametrize("scheduler_s", [0.0, 0.16])
@pytest.mark.asyncio(loop_scope="function")
@pytest.mark.usefixtures("_cleanup_clock")
async def test_cleanup_allowance_ignores_independent_scheduler_time(monkeypatch, scheduler_s):
import time as wall_time

real_monotonic = wall_time.monotonic
elapsed = 0.0

def monotonic():
return real_monotonic() + elapsed

actual_close = cell_control.Owner.close

async def close(owned):
nonlocal elapsed
try:
return await actual_close(owned)
finally:
elapsed += scheduler_s

monkeypatch.setattr(wall_time, "monotonic", monotonic)
monkeypatch.setattr(cell_control.Owner, "close", close)
await test_lock_owner_bounds_close_inside_the_same_cleanup_allowance()


@pytest_asyncio.fixture(loop_scope="function")
async def _cleanup_clock(monkeypatch):
from server.core import pg
from tests.unit.clock_fake import ManualClock

before = set(asyncio.all_tasks())
loop = asyncio.get_running_loop()
clock = ManualClock(t=loop.time())
selector = loop._selector
real_select = selector.select

def select(timeout=None):
if timeout is not None:
clock.advance(max(0.0, timeout))
timeout = 0
return real_select(timeout)

# The cleanup protocol spends idle time, independently of CPU scheduling.
monkeypatch.setattr(loop, "time", clock.monotonic)
monkeypatch.setattr(selector, "select", select)
monkeypatch.setattr(cell_control, "time", clock)
monkeypatch.setattr(pg, "time", clock)
monkeypatch.setattr(f"{__name__}.time", clock)
yield clock
leaked = asyncio.all_tasks() - before - {asyncio.current_task()}
for task in leaked:
task.cancel()
await asyncio.gather(*leaked, return_exceptions=True)
assert not leaked, "cell cleanup leaves no task on its private loop"


@pytest.mark.asyncio(loop_scope="function")
async def test_cleanup_clock_preserves_the_close_deadline(_cleanup_clock):
from server.core import pg

loop = asyncio.get_running_loop()
assert loop.time == time.monotonic == cell_control.time.monotonic == pg.time.monotonic
began = _cleanup_clock.monotonic()
await test_lock_owner_bounds_close_inside_the_same_cleanup_allowance()
assert _cleanup_clock.monotonic() - began == pytest.approx(0.03)
66 changes: 66 additions & 0 deletions tests/unit/test_cell_trigger_default_comparison.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Default-field proof checks keep their refusals without per-field JSON setup."""

from copy import deepcopy

import pytest

from tests.unit.test_cell_trigger_ci_creator import keeper_config_case as keeper_config_case
from tests.unit.test_cell_trigger_ci_creator import protocol_reader as protocol_reader
from tests.unit.test_cell_trigger_provenance_reuse import _case


def _expected(native, specification, context, row, audit, api):
native.Codec(specification).expected(
row,
audit,
context,
api=api,
metadata={"summary": {"jti": "b" * 32}},
driver={"host": "proof-host", "pid": 701},
)


@pytest.mark.parametrize("api", [False, True], ids=["delivery", "api"])
def test_default_proof_bounds_json_encoder_setup(
keeper_config_case, protocol_reader, monkeypatch, api
):
native, *_ = keeper_config_case
specification, context, _, _, memories, audits, _ = _case(native, 1, api)
calls = 0
original = native.json.dumps

def counted(*args, **kwargs):
nonlocal calls
calls += 1
return original(*args, **kwargs)

monkeypatch.setattr(native.json, "dumps", counted)
_expected(native, specification, context, memories[0], audits[0], api)
# Encoder setup stays bounded as the protocol adds default fields.
assert calls <= 16


@pytest.mark.parametrize("index", range(44))
def test_default_proof_refuses_each_changed_field(keeper_config_case, protocol_reader, index):
native, *_ = keeper_config_case
specification, context, _, _, memories, audits, _ = _case(native, 1, False)
field, default = list(specification["sparse_defaults"].items())[index]
assert default != {"unexpected": True}
row = deepcopy(memories[0])
row[field] = {"unexpected": True}
with pytest.raises(native.Refused):
_expected(native, specification, context, row, audits[0], False)


@pytest.mark.parametrize("replacement", [False, 0.0])
def test_default_proof_keeps_json_numeric_type_refusals(
keeper_config_case, protocol_reader, replacement
):
native, *_ = keeper_config_case
specification, context, _, _, memories, audits, _ = _case(native, 1, False)
assert specification["sparse_defaults"]["pinned"] == 0
row = deepcopy(memories[0])
row["pinned"] = replacement
assert row["pinned"] == 0
with pytest.raises(native.Refused):
_expected(native, specification, context, row, audits[0], False)
42 changes: 42 additions & 0 deletions tests/unit/test_memory_key_write_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import asyncio
from contextlib import nullcontext
from types import SimpleNamespace
from typing import Any

Expand All @@ -13,6 +14,7 @@
from server.memory.app import update as update_mod
from server.memory.app import write as write_mod
from server.memory.store import key_write_lock as kl
from server.observability import provider_health
from tests.unit.claims_fake import FakeLockTable

_IDENT = ("org", "ns", "agent", "-", "-", "proc/deploy/steps")
Expand Down Expand Up @@ -92,6 +94,46 @@ async def test_keeper_failure_refuses_the_write(
assert notes == [("memory_key_lock", "keeper_unavailable")]


@pytest.mark.parametrize("body_fails", [False, True])
async def test_key_lock_health_recovers_when_the_lease_is_acquired(
monkeypatch: pytest.MonkeyPatch, body_fails: bool
) -> None:
monkeypatch.setattr(provider_health, "_state", {})
ch = FakeKeeper(fail=True)
locks = _locks(ch, monkeypatch)
with pytest.raises(BackendUnavailableError):
async with locks.hold(*_IDENT):
pytest.fail("entered without a lease")
assert provider_health.status()["providers"]["memory_key_lock"]["failing"] is True

provider_health.record_failure("other_provider", "still unavailable")
ch.down = False
with pytest.raises(ValueError, match="body failed") if body_fails else nullcontext():
async with locks.hold(*_IDENT):
assert provider_health.status()["providers"]["memory_key_lock"]["failing"] is False
if body_fails:
raise ValueError("body failed")
assert provider_health.status()["providers"]["other_provider"]["failing"] is True
assert ch.keys == {} and len(locks) == 0


async def test_a_busy_key_does_not_clear_the_last_acquisition_failure(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(provider_health, "_state", {})
ch = FakeKeeper(fail=True)
locks = _locks(ch, monkeypatch)
with pytest.raises(BackendUnavailableError):
async with locks.hold(*_IDENT):
pytest.fail("entered without a lease")
ch.down = False
ch.seed(kl.lock_name(*_IDENT), "other")
with pytest.raises(PreconditionFailedError):
async with locks.hold(*_IDENT):
pytest.fail("entered a held lock")
assert provider_health.status()["providers"]["memory_key_lock"]["failing"] is True


async def test_racing_conditional_sets_let_one_through(
monkeypatch: pytest.MonkeyPatch,
) -> None:
Expand Down
Loading