Skip to content

fix(oracle): restore PG query semantics and clean up migration chain#1312

Merged
nicoloboschi merged 1 commit intomainfrom
fix/oracle-pr-followup
Apr 29, 2026
Merged

fix(oracle): restore PG query semantics and clean up migration chain#1312
nicoloboschi merged 1 commit intomainfrom
fix/oracle-pr-followup

Conversation

@nicoloboschi
Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1307 (Oracle 23ai backend). Fixes three issues introduced during the abstraction refactor:

  • semantic_expanded CTE ordering: The DISTINCT ON rewrite lost the global ORDER BY score DESC before LIMIT. When results exceeded the budget, the LIMIT applied in mu.id order instead of keeping the highest-scored rows. Fixed by wrapping DISTINCT ON in a subquery that re-sorts by score before LIMIT (both PG build_semantic_causal_cte and observation expansion)
  • temporal neighbors ROW_NUMBER filter: The ROW_NUMBER() OVER (PARTITION BY ... ORDER BY time_diff_hours) filter was dropped, doubling returned rows per probe (K per direction × 2 instead of K closest overall). Restored for both PG and Oracle backends
  • migration chain cleanup: Removed two empty merge migrations (e6f7g8h9i0j1, j5k6l7m8n9o0) that were artifacts of the Oracle branch being developed in parallel. Linearized the chain: 8c6fa6f7230b → d5y6z7a8b9c0 → i4j5k6l7m8n9 → k6l7m8n9o0p1

Test plan

  • test_link_expansion_retrieval.py — 2/2 passed
  • test_db_abstraction.py — 80/80 passed
  • Full PG test suite — 141 passed, 1 pre-existing failure (test_memories_timeseries_empty_bank_returns_zero_filled_buckets — fails identically on main)
  • Lint + format pass

The Oracle PR (#1307) introduced subtle behavioral changes to two PG
query patterns during the abstraction refactor:

1. semantic_expanded CTE: the DISTINCT ON rewrite lost the global
   ORDER BY score DESC before LIMIT. When results exceeded the budget,
   the LIMIT applied in mu.id order instead of keeping the highest-
   scored rows. Fix: wrap DISTINCT ON in a subquery that re-sorts by
   score before applying LIMIT.

2. temporal neighbors: the ROW_NUMBER() OVER (PARTITION BY ... ORDER BY
   time_diff_hours) filter was dropped, doubling the returned rows per
   probe (K per direction × 2 instead of K closest overall). Fix:
   restore the ROW_NUMBER filter around the UNION ALL of both scan
   directions, for both PG and Oracle backends.

3. Migration chain: remove two empty merge migrations that were
   artifacts of the Oracle branch being developed in parallel
   (e6f7g8h9i0j1, j5k6l7m8n9o0) and linearize the chain:
   8c6fa6f7230b → d5y6z7a8b9c0 → i4j5k6l7m8n9 → k6l7m8n9o0p1
@nicoloboschi nicoloboschi merged commit 76bcd93 into main Apr 29, 2026
55 of 58 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.

1 participant