Repository navigation
feat(temporal): expose canonical bounds in the query space (D107 WP-T.0b) - #375
Conversation
Codex review (gpt-5.6-sol, xhigh) — round 1Verdict: request changes. Triage
EOF Findings
Verified
No PostgreSQL-backed tests or PostgreSQL process were run. I made no file changes; static validation, manifest regeneration comparison, and Merge verdictRequest changes. The core clock calculation, timezone handling, view membership, and privilege boundary are correct, but the shipped catalog still publishes obsolete inclusive-overlap guidance, the binding acceptance criteria are not exercised through the actual example/query-role path, the declared canonical index cannot serve predicates through the opaque security-definer SRF, and the sharded benchmark defaults to a protocol key that no longer exists. |
Antigravity review — round 1Verdict: request changes. Triage
EOF Findings1. Sharding default protocol key breaks on LoCoMo run
2.
|
|
Round-1 findings applied on Fixed: sharded Left: query-role EXPLAIN proving an index path (C3 remainder — the catalog is now honest that the view uses the parent claim indexes); tombstoned-lineage A/B (A3 — documented as a designed divergence, not equality). Dataset error strings still name the frozen v22 dataset pin (A6 wontfix). |
03f9ba5 to
67ada2c
Compare
PR 375 Round-Two Review: Canonical Bounds in Query Space (
|
| ID | Location | Severity | Category | Summary |
|---|---|---|---|---|
| D-1 | src/tests/surfaces/test_open_query_batch_f.py:964 |
High | Correctness / Test Failure | Stale hardcoded manifest hash 2fff3177... causes test failure against new hash 7d8ee75d... |
| D-2 | src/tests/surfaces/test_retrieval_batch_b.py:632 |
Low | Code Style | Scoped import json inside test body instead of top-level imports |
Root-Cause Analysis: Function Permissions in Owner-Rights Views
The Round-One Defect
In round 1 (commit 67ada2c6), memory_v1.claims_canonical was defined as:
SELECT h.*,
claim_canonical_start(h.claim_valid_from, h.claim_valid_precision::claim_valid_precision) AS canon_start,
claim_canonical_end(h.claim_valid_from, h.claim_valid_until, h.claim_valid_precision::claim_valid_precision) AS canon_end
FROM memory_v1.claims_visible_history AS h;The previous review assumed that because the view is owned by rememberstack_view_owner, callers querying the view would inherit the owner's privileges for function execution.
Why that fails in PostgreSQL:
In PostgreSQL, owner-rights views operate with the view owner's privileges only for underlying table access. Any function called within the view's query expression is checked against the calling role's privileges (unless the function itself is declared SECURITY DEFINER). Because migration p9_02_0023_query_space_roles.py revoked EXECUTE ON ALL FUNCTIONS IN SCHEMA public FROM PUBLIC and does not grant EXECUTE on the private twins to rememberstack_query_*, any query run as the query role against claims_canonical failed with:
psycopg.errors.InsufficientPrivilege: permission denied for function claim_canonical_start
The round 1 test in test_retrieval_batch_b.py had masked this bug because it executed queries over corpus.engine.connect() as the database superuser rather than authenticating as the restricted rememberstack_query_* role.
The Round-Two Resolution in Commit 9b378306
The uncommitted fixes (now commit 9b378306) solved this by:
- Inlining the canonical expressions directly in
claims_canonical:
The view now joinspublic.claims AS cand embeds the rawCASEexpressions ofclaim_canonical_startandclaim_canonical_end. Because no user-defined function is called, the query role requires noEXECUTEprivileges. - Preserving private function ACLs:
claim_canonical_startandclaim_canonical_endremain inaccessible torememberstack_query_*. Direct calls topublic.claimsor the twin functions fail withInsufficientPrivilege. - Query-Role acceptance testing:
test_retrieval_batch_b.py:567-583now provisions an authentic TCP/socket connection asrememberstack_query_{database}, executesEXAMPLE_QUERIES["claims_as_of"]viaQuerySandboxExecutor, and explicitly verifies that direct calls topublic.claims,public.claim_canonical_start, andpublic.claim_canonical_endraisepsycopg.errors.InsufficientPrivilege.
Detailed Audit Against Review Requirements
1. Frozen Migration-0023 Grants
- Status: PASS
- Verification: In
p9_02_0023_query_space_roles.py:49-74,_INITIAL_PUBLIC_VIEWSfreezes the 24 views authored up to revision0022. Replacing the dynamic importfrom catalog import VIEW_CONTRACTS_BY_NAMEprevents fresh migrations from attempting to alter or grantclaims_canonical(which is not created until0048) and preserves reverse-order downgrade behavior.
2. Migration 0048 Inline Canonical View Projections & Partial Index Eligibility
- Status: PASS
- Analysis:
claims_canonicalinlines the exact UTC-truncatingCASEexpressions matchingcore/temporal.py:canonical_boundsand the0047SQL twins.- In
p9_27_0048_query_space_canonical_bounds.py:158-164,ix_claims_canonical_windowwas altered to:CREATE INDEX ix_claims_canonical_window ON claims ( deployment_id, claim_canonical_start(claim_valid_from, claim_valid_precision), claim_canonical_end(claim_valid_from, claim_valid_until, claim_valid_precision) ) WHERE claim_canonical_start(claim_valid_from, claim_valid_precision) IS NOT NULL;
- When open SQL queries
canon_start < ($2::timestamptz + '1 microsecond'::interval), PostgreSQL's planner inlinesclaim_canonical_startinto the index expression and proves via strict operator deduction (<) thatcanon_start IS NOT NULL. Thus, the partial index predicate is satisfied and the index is used directly as anIndex Cond.
3. Private Function ACL Preservation
- Status: PASS
- Verification:
public.claim_canonical_startandclaim_canonical_endhaveEXECUTEgranted only torememberstack_view_owner(somemory_v1.canonical_bounds, aSECURITY DEFINERfunction, can evaluate them). The query role is denied direct execution, which is pinned by tests intest_retrieval_batch_b.py:612-620.
4. Query-Role Execution of Saved Examples & Meaningful Acceptance Tests
- Status: PASS
- Verification:
- Shipped example query
CLAIMS_AS_OF_SQLusesclaims_canonicaland countsunknownprecision viaWHERE u.claim_valid_precision = 'unknown'(fixing audit 4.21). - The acceptance test in
test_retrieval_batch_b.py:564-637tests window overlap, non-zero excluded unstamped claims, point queries (parameters=(point, point)), ACL denials, and verifies thatix_claims_canonical_windowappears underIndex CondinEXPLAIN (FORMAT JSON).
- Shipped example query
5. Downgrade Metadata
- Status: PASS
- Verification: In
p9_27_0048_query_space_canonical_bounds.py:205-238,downgrade()extracts and executes the original view comments forclaims_visible_historyandclaims_livefromMEMORY_V1_AUTHORED_DDL, dropsclaims_canonicalandcanonical_bounds, restores the0047partial index definition (WHERE claim_valid_precision <> 'unknown'), and revokesEXECUTEon the twin functions fromrememberstack_view_owner.
6. Manifest & LoCoMo Protocol Consistency
- Status: FAIL (see Defect D-1)
- Analysis:
- Query space manifest
memory_v1_manifest.json:40130andbenchmarks/locomo/protocol.py:46were rolled toFull-v23with hash7d8ee75d2a102485df10d96511f306e0f4e5c8d1d387b1cc9f271497480b84f9. - All protocol tests in
test_locomo_protocol.pyandtest_locomo_runner.pypass. - However,
test_open_query_batch_f.py:964still expects the round-1 hash2fff3177fd6adb35c8f6a248db1d9c698cc716dc8461c818865bb3c36c752870, causing a test failure.
- Query space manifest
Detailed Defects & Concrete Remediations
Defect D-1: Stale Surface Manifest Hash Assertion
- File & Line:
src/tests/surfaces/test_open_query_batch_f.py:962-965 - Severity: High (breaks CI / test suite)
- Reproduction:
Output:
uv run pytest src/tests/surfaces/test_open_query_batch_f.py -k test_core_prose_is_authority_for_live_graph_and_claims_verbatim
AssertionError: assert '7d8ee75d2a10...71497480b84f9' == '2fff3177fd6a...bb3c36c752870' - 2fff3177fd6adb35c8f6a248db1d9c698cc716dc8461c818865bb3c36c752870 + 7d8ee75d2a102485df10d96511f306e0f4e5c8d1d387b1cc9f271497480b84f9 - Concrete Fix:
Update the expected hash insrc/tests/surfaces/test_open_query_batch_f.py:assert ( load_manifest()["surface_manifest_hash"] == "7d8ee75d2a102485df10d96511f306e0f4e5c8d1d387b1cc9f271497480b84f9" )
Defect D-2: Inline import json Inside Test Body
- File & Line:
src/tests/surfaces/test_retrieval_batch_b.py:632 - Severity: Low (Code cleanliness)
- Description:
import jsonis placed insidetest_claims_canonical_unknown_count_and_overlap_match_engine_as_ofright before serializing the execution plan. - Concrete Fix:
Addimport jsonto the top-level standard library imports insrc/tests/surfaces/test_retrieval_batch_b.pyand remove line 632.
Database Validation & Reproduction Record
In accordance with review instructions ("Test or reproduce where practical; do not claim database validation without running it"):
- Full Migration Chain Caveat:
Runningalembic upgrade headfrombaseagainst local PostgreSQL 15 fails at revisionp0_02_0001becausepg_textsearchis a specialized/PostgreSQL 19 extension available in the CI/container environment, not present on the host's standard PostgreSQL 15 instance. Therefore, full database lifecycle verification (test_migrations.py) could not be run against the host database. - Executed Local SQL Verification (PostgreSQL 15):
The following isolated database proofs were executed againstlocalhost:5432:- Bug Reproduction: Tested commit
67ada2c6view definition withrememberstack_query_*role. Replicated exact error:permission denied for function claim_canonical_start. - ACL Isolation: Tested commit
9b378306inlined view withrememberstack_query_*role. ProvedSELECTonmemory_v1.claims_canonicalsucceeds while direct access topublic.claimsandpublic.claim_canonical_startraisesInsufficientPrivilege. - Index Matching: Tested
EXPLAINquery withcanon_start < now(). ConfirmedBitmap Index Scan on ix_claims_canonical_windowwithIndex Condproving partial index eligibility. - Migration Lifecycle: Tested 0047 upgrade -> 0048 upgrade -> 0048 downgrade lifecycle. Confirmed
ix_claims_canonical_windowcleanly drops and restores toWHERE claim_valid_precision <> 'unknown'.
- Bug Reproduction: Tested commit
- Executed Unit Tests:
test_query_space_manifest.py: 15 passed in 3.52s.test_locomo_protocol.py&test_locomo_runner.py: passed.test_saved_queries_batch_e.py: passed.test_query_sandbox_batch_b.py: 92 passed, 29 skipped in 14.93s.test_open_query_batch_f.py: failed on line 964 (Defect D-1).
Merge Verdict
CHANGES REQUESTED
The underlying architecture, inlined SQL projections, security isolation, and query-role execution in 9b378306 are sound and resolve the round-1 security flaw. Once Defect D-1 in src/tests/surfaces/test_open_query_batch_f.py:964 is updated to match the rolled manifest hash, PR 375 is approved to merge.
….0b) Publish memory_v1.canonical_bounds and claims_canonical so open SQL uses the same half-open D41 windows as the engine. Rewrite examples.claims_as_of over the view, counting unknown precision by precision alone, and roll the query space, surface manifest, and LoCoMo protocol to Full-v23.
Default sharded prepare to full-v23. Project public twins in claims_canonical instead of a lateral SECURITY DEFINER SRF, mark the SRF ROWS 1, stop claiming the expression index, and point claims_visible_history/claims_live comments at the canonical overlap. Remove the dead FUNCTION_ALLOWLIST entry, run the shipped examples.claims_as_of SQL in the acceptance proof, and regenerate the surface hash / Full-v23 fingerprint.
8e56286 to
470f992
Compare
|
Round-three Antigravity found a real second-layer ACL issue: migration0023's per-schema default privilege revocation cannot remove PostgreSQL's global default PUBLIC function EXECUTE. Applied atddd2ea8f:0048 explicitly revokes PUBLIC EXECUTE on both private canonical twins; tests independently inspect both schema USAGE and function EXECUTE permissions. Downgrade retains the restriction rather than restoring an unintended grant. Application function owners and the explicit view-owner grants remain intact. The review's direct-call failure claim did not reproduce on the actual migrated schema:0023 revokes public schema USAGE, and all PostgreSQL19 CI jobs at470f9921 passed, including direct-call denial. Its reduced fixture omitted that independent schema boundary. The new ACL assertions ensure denial is no longer masked by schema restrictions. The official PostgreSQL ALTER DEFAULT PRIVILEGES documentation explicitly confirms the per-schema limitation. Round-three otherwise approved canonical arithmetic across timezones, row membership/tombstone filters, index use with one claims scan, and downgrade object/index restoration. Its isolated test reader twice held an idle transaction blocking its own DROP VIEW; only that completed temporary reader was released, with no repository source or test assertion changed. Full CI was independent of that probe. Focused final Antigravity follow-up and CI onddd2ea8f are running. No merge until both complete. |
|
Final Antigravity follow-up reviewedddd2ea8f: APPROVED / READY TO MERGE, no remaining findings. It independently confirmed the explicit private-function ACL fix, application-owner execution, published SECURITY DEFINER wrapper, schema and function denial, index use, retained restriction on downgrade and clean re-upgrade in a private PostgreSQL15 fixture. The reviewer withdrew round-three's direct-call exploitability claim after reproducing the actual schema USAGE restriction. Its final validation was scoped to the role/canonical migration lifecycle and fixture, not a claim to run the entire Alembic chain locally. Full PostgreSQL19 CI remains the final integration gate. No repository changes were made by the reviewer. |
Problem and result
Open SQL could not use the canonical half-open claim windows already shipped by the engine-internal T.0a path. The saved
examples.claims_as_ofstill compared inclusive raw fields and its unknown-precision count could never be nonzero.This PR publishes
memory_v1.canonical_boundsfor explicit top-level FROM calls andclaims_canonicalfor claim filtering, fixes the saved example, and rolls the query-space manifest and both LoCoMo variants to Full-v23. Claim storage and the Python QueryEngine path are unchanged.Implementation and important decisions
claims_visible_history. PostgreSQL view ownership supplies table permissions, not private function EXECUTE. Direct joins avoid a second claims scan.Sources inspected
D107
plan/designs/temporal_clocks_design.md§5;plan/plans/temporal_clocks.mdT.0b; query-space role/grammar contracts; migrations 0022/0023/0025/0047; PostgreSQL CREATE VIEW permission rules and actual PostgreSQL behavior. Round-one Codex and Antigravity findings and round-two Antigravity findings were triaged.Validation and review
Local lint, formatting and type checking pass. The latest targeted local run passed 136 tests, with 19 database-dependent tests skipped. An isolated 10,000-row PostgreSQL 15 probe confirmed query-role use of the direct-expression canonical index; PostgreSQL 19 CI remains the integration authority.
Database tests execute the exact shipped example through QuerySandboxExecutor authenticated as the restricted query login; compare unknown counts and point/window claim sets with the library; assert private accesses fail; check the canonical index path; and compare all seven precisions and row membership under a non-UTC session. Fresh migration, downgrade/reupgrade and catalog/deletion gates run in CI.
Antigravity rounds two through four are resolved; final review APPROVED at ddd2ea8. In addition to the manifest/index fixes, the private canonical twins now explicitly revoke PUBLIC EXECUTE (per-schema default ACLs cannot remove PostgreSQL global defaults). Tests inspect schema USAGE and function EXECUTE independently. Downgrade retains that restriction. The final reviewer independently checked role/wrapper/index/downgrade/re-upgrade behavior in an isolated PostgreSQL15 fixture. All full integration jobs must pass before merge, even if the fast PR gate completes earlier.
Limitations and follow-up
T.0b publishes source testimony, not adjudicated truth. Engine and query-space lineage/version filters have an existing documented difference for tombstoned versions; the clean live-corpus equality test does not claim universal equality. T.4 and the four design spikes before T.1 remain separate work under #364.
Contributor agreement