Skip to content

fix(test): bind the hermetic agent-tools memory case to its fake datastore - #10450

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/10423-hermetic-memory-clock-and-binding
Jul 24, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/10423-hermetic-memory-clock-and-binding

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

Fixes the order dependency in TestSurfaceDefaultAccessMatrix::test_surface_excludes_archive_and_respects_grants[agent_tools], the case failing the Backend Hermetic E2E job (and therefore the Backend Hermetic Merge Gate) across several open PRs.

Fixes #10423.

Root cause

The agent-tools case reads through utils.retrieval.tool_services.memories.get_memories_text, which resolves the Firestore client that module captured at import time (from database._client import db as firestore_db). The case never bound that name, so it only passed when an earlier test's fixture happened to rebind it.

Run on its own it reaches for real Firestore:

pytest 'testing/e2e/test_canonical_memory_pipeline.py::TestSurfaceDefaultAccessMatrix::test_surface_excludes_archive_and_respects_grants'
→ 1 failed, 5 passed
   PermissionDenied: Cloud Firestore API has not been used in project test-e2e-project

That's both an order dependency and a hermeticity hole — a "hermetic" case escaping to a real service.

Fix

Bind the module's client to the case's fake_firestore explicitly. Six added lines, test-only.

On the clock half of #10423

The issue also suspected the reader evaluated short-term expiry against the wall clock. That part is already resolved on current main — the clock is injected end to end:

get_memories_text(now=) → MemoryService.read(now=) → read_canonical_memories(now=) → filter_canonical_default_visible_items(now=)

I verified it rather than assuming: re-ran the matrix with the fixture clock moved 18 months into the past (NOW = 2025-01-15) — 6 passed. If the wall clock still leaked, the fresh-short fixture would have been filtered. So after this change the case is both date- and order-independent.

Verification

  • Case standalone (the failing repro): 6 passed (was 1 failed, 5 passed)
  • Whole file, CI-like ordering: 8 passed
  • Date-independence probe (NOW −18 months): 6 passed

Product invariants affected

none

Failure-Class: none

Review in cubic

…store

The agent-tools case of TestSurfaceDefaultAccessMatrix reads through
utils.retrieval.tool_services.memories.get_memories_text, which resolves the
Firestore client this module captured at import time. The case never bound it,
so it only passed when an earlier test's fixture happened to rebind that name;
run on its own it reaches for real Firestore and fails with PermissionDenied
against test-e2e-project — an order dependency and a hermeticity hole (BasedHardware#10423).

Bind the module's client to the case's fake_firestore explicitly, so the case is
order-independent and never leaves the hermetic stack.

The reader clock is already injected end to end (get_memories_text(now=) →
MemoryService.read → read_canonical_memories → filter_canonical_default_visible_items),
verified by re-running the matrix with the fixture clock moved 18 months into the
past: still 6 passed. So this case is now both date- and order-independent.

Refs BasedHardware#10423.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level

Copy link
Copy Markdown
Member

Nice find and clean fix — thanks @aryanorastar.

I verified the root cause statically: utils/retrieval/tool_services/memories.py captures the Firestore client at import time (from database._client import db as firestore_db, line 12) and get_memories_text reads through that module-level name rather than a passed-in client. The agent_tools branch in surface_default_reader calls get_memories_text(uid, limit, now) without forwarding the case's db, so the explicit monkeypatch.setattr(tool_memories_service, "firestore_db", db) is exactly the right binding to close the hermeticity hole — it matches how every other surface in this matrix receives its datastore. The 18-months-past clock re-run is a good way to confirm the date-independence half is already covered on main.

The Backend Hermetic Merge Gate and Hermetic Backend E2E are green on this head, so the order dependency is resolved. The remaining check entries appear as skipped/cancelled only because this is a test-only path with no source formatting/hygiene surface.

Leaving formal approval to a human maintainer; from a correctness standpoint this looks good.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only hermetic fix (fixes #10423): binds agent_tools case to fake_firestore, removes order dependency + real-Firestore escape. Backend suite green.

@kodjima33
kodjima33 merged commit 58ec416 into BasedHardware:main Jul 24, 2026
32 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hermetic canonical-memory agent-tools case expires its fixed “fresh” fixture

3 participants