Skip to content

Enhance PostgreSQL integration with managed index capabilities and ob… - #71

Merged
eldonm merged 3 commits into
mainfrom
ab/dev
Nov 13, 2026
Merged

eldonm merged 3 commits into
mainfrom
ab/dev

Conversation

@abrouet

@abrouet abrouet commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

…servability improvements

  • Introduced JVSPATIAL_POSTGRES_INDEX_CREATION to control index creation modes, allowing for deferred performance index DDL while preserving unique constraints.
  • Added IndexSpec and ManagedSchemaError as public exports for managed PostgreSQL hosts.
  • Enhanced observability by emitting content-free spans for authentication and database operations, ensuring sensitive information is not logged.
  • Updated documentation to reflect new features and guidelines for managing PostgreSQL indexes and schema provisioning.

Type of Change

What type of change does this PR introduce? Mark all that apply:

  • 🐛 Bug Fix
  • 🚀 Feature Request
  • 🔄 Refactor
  • 📖 Documentation Update
  • 🔧 Other (Please specify):

Summary

What does this PR address?

Provide a concise summary of the changes introduced in this pull request. Specify if it resolves an issue, adds a feature, or refactors code.

For example:

  • Resolves #ISSUE_ID
  • Adds feature for X
  • Refactors Y to improve Z

Description

Bug Fixes:

If this PR fixes a bug, please provide:

  • A brief description of the bug.
  • The root cause of the issue.
  • How this PR resolves the issue.

Feature Request:

If this PR adds a new feature, please provide:

  • A brief description of the feature.
  • The motivation for introducing it.
  • Any relevant details about implementation.

Refactor Request:

If this PR refactors code, please provide:

  • The specific area of code refactored.
  • The problem with the current implementation.
  • The improvements made in the refactor.

Changes Made

High-Level Summary:

List the key changes made in this PR:

  1. Change 1
  2. Change 2
  3. Change 3

Checklist

Mark all that apply:

  • Code follows the project’s coding guidelines.
  • Tests have been added or updated for new functionality.
  • Documentation has been updated (if applicable).
  • Existing tests pass locally with these changes.
  • Any dependencies introduced are justified and documented.

Steps to Test

Provide a clear set of steps for testing the changes introduced in this PR:

  1. Step 1
  2. Step 2
  3. Step 3

Additional Context

If necessary, provide additional context, screenshots, or relevant references for the changes in this PR.


Questions or Concerns

Are there any open questions or areas of concern related to this PR? If so, mention them here.

…servability improvements

- Introduced `JVSPATIAL_POSTGRES_INDEX_CREATION` to control index creation modes, allowing for deferred performance index DDL while preserving unique constraints.
- Added `IndexSpec` and `ManagedSchemaError` as public exports for managed PostgreSQL hosts.
- Enhanced observability by emitting content-free spans for authentication and database operations, ensuring sensitive information is not logged.
- Updated documentation to reflect new features and guidelines for managing PostgreSQL indexes and schema provisioning.
@github-actions

Copy link
Copy Markdown

Benchmark comparison

Threshold: ±25% (informational, does not block merge)

benchmark baseline (s) current (s) delta status
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_deferred_save_batched_100 0.016449 0.011512 -30.0% IMPROVED (-30.0%)
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_immediate_save_100 0.015955 0.012681 -20.5% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[hierarchy] 0.002773 0.002101 -24.2% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[ontology] 0.002752 0.002082 -24.4% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[relationships] 0.002553 0.002153 -15.7% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[hierarchy] 0.002441 0.001791 -26.6% IMPROVED (-26.6%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[ontology] 0.002520 0.001788 -29.0% IMPROVED (-29.0%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[relationships] 0.002421 0.001737 -28.2% IMPROVED (-28.2%)
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_batched_saves_500 0.425320 0.403223 -5.2% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_empty_query 0.001559 0.001304 -16.3% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_filtered 0.074688 0.056246 -24.7% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_find_filtered 0.073231 0.056790 -22.5% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_save_throughput 0.001349 0.001841 +36.4% REGRESSION (+36.4%)
tests/benchmarks/test_postgres_benchmarks.py::test_bench_postgres_find_many_bulk 0.000742 0.000572 -22.9% OK
tests/benchmarks/test_postgres_benchmarks.py::test_bench_postgres_traverse_depth 0.000409 0.000290 -29.0% IMPROVED (-29.0%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_empty 0.000167 0.000123 -26.6% IMPROVED (-26.6%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_fallback_via_regex 0.022157 0.015732 -29.0% IMPROVED (-29.0%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_pushdown 0.001042 0.000713 -31.6% IMPROVED (-31.6%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_fallback_via_regex 0.023122 0.015783 -31.7% IMPROVED (-31.7%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_pushdown 0.000287 0.000203 -29.4% IMPROVED (-29.4%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_sort_limit_pushdown 0.001839 0.001327 -27.8% IMPROVED (-27.8%)

…fications

- Removed redundant import in `auth_middleware.py` for cleaner code.
- Added detailed docstrings to `identifier` and `IndexSpec` methods in `indexes.py` for improved documentation and clarity.
- Simplified return statement in `PostgresDB` index creation method for better readability.
- Added a blank line in the test file for consistency and style adherence.
@github-actions

Copy link
Copy Markdown

Benchmark comparison

Threshold: ±25% (informational, does not block merge)

benchmark baseline (s) current (s) delta status
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_deferred_save_batched_100 0.016449 0.011064 -32.7% IMPROVED (-32.7%)
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_immediate_save_100 0.015955 0.011572 -27.5% IMPROVED (-27.5%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[hierarchy] 0.002773 0.001987 -28.4% IMPROVED (-28.4%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[ontology] 0.002752 0.002041 -25.9% IMPROVED (-25.9%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[relationships] 0.002553 0.001927 -24.5% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[hierarchy] 0.002441 0.001745 -28.5% IMPROVED (-28.5%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[ontology] 0.002520 0.001703 -32.4% IMPROVED (-32.4%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[relationships] 0.002421 0.001709 -29.4% IMPROVED (-29.4%)
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_batched_saves_500 0.425320 0.425882 +0.1% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_empty_query 0.001559 0.001083 -30.5% IMPROVED (-30.5%)
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_filtered 0.074688 0.053602 -28.2% IMPROVED (-28.2%)
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_find_filtered 0.073231 0.053406 -27.1% IMPROVED (-27.1%)
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_save_throughput 0.001349 0.001252 -7.2% OK
tests/benchmarks/test_postgres_benchmarks.py::test_bench_postgres_find_many_bulk 0.000742 0.000581 -21.7% OK
tests/benchmarks/test_postgres_benchmarks.py::test_bench_postgres_traverse_depth 0.000409 0.000296 -27.5% IMPROVED (-27.5%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_empty 0.000167 0.000113 -32.3% IMPROVED (-32.3%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_fallback_via_regex 0.022157 0.015120 -31.8% IMPROVED (-31.8%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_pushdown 0.001042 0.000701 -32.8% IMPROVED (-32.8%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_fallback_via_regex 0.023122 0.015221 -34.2% IMPROVED (-34.2%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_pushdown 0.000287 0.000206 -28.3% IMPROVED (-28.3%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_sort_limit_pushdown 0.001839 0.001312 -28.7% IMPROVED (-28.7%)

@abrouet
abrouet requested a review from eldonm November 13, 2026 11:26

@eldonm eldonm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CI is green, and I also ran the new live-Postgres tests against a real database (CI's test workflow has no Postgres service, so they're skipped there). Those passed, as did the observability and API suites. Two items conflict with the repo's AGENTS.md boundaries, though, so requesting changes before merge.

Blocking

  1. Downstream consumer name in library code. PostgresDB.verify_index_spec hardcodes the catalog table integral_index_catalog. AGENTS.md forbids naming specific downstream consumers in the library. Please make the catalog relation configurable (constructor arg / env var with a neutral default such as jvspatial_index_catalog) and document its required columns (fingerprint, index_name, definition_hash) in docs/md/postgres-guide.md and SPEC. Without that, no other host can actually use managed mode.
  2. AGENTS.md link outside the repo. The new "Optional local workspace reference" section points to ../docs/JVSPATIAL_FOUNDATION.md, which describes one developer's downstream integrations and doesn't exist for other clones. Please drop it (keep it in a local, untracked note instead).

Should fix

  • index_creation docstring in PostgresDB.__init__ lists only auto / constraints; managed is accepted but undocumented there.
  • CHANGELOG: the "Governed storage capability (unreleased)" entry is appended under [0.0.5] - Previous; move it into ## [Unreleased].
  • SPEC: "Managed PostgreSQL index boundary" is appended after the change-process section at the end of the file; move it next to the new index-policy text in the database section.
  • verify_index_spec interpolates self.schema_name into SQL directly; other paths go through _safe_collection. Validate it the same way.
  • tests/observability/test_database_spans.py::test_unconfigured_tracing_keeps_metrics_without_proxy_spans imports opentelemetry without pytest.importorskip, so it fails in environments without the optional OTel extra (its sibling tests guard correctly).
  • auth.authenticate span sets error.type on exception but never sets ERROR status, unlike the db/walker/http helpers.
  • constraints mode still creates the binary-text keyset indexes (_binary_text_keyset.create_indexes only skips managed), which contradicts the "skips performance indexes" description. Either skip there too or document that explicit helper calls are exempt.

The rest looks good: content-free spans, query-logger removal on cancellation (with a test), unique enforcement preserved in constraints mode, and the env allowlist entry.

- Introduced `index_catalog_table` for configurable index catalog management in PostgreSQL, allowing hosts to specify their own catalog tables.
- Added support for `managed` index creation mode, which verifies pre-provisioned storage without persistent schema/index DDL.
- Improved observability by ensuring authentication failures set ERROR status without exposing sensitive details.
- Updated documentation to reflect new index management capabilities and guidelines for PostgreSQL integration.
- Enhanced tests to validate new features and ensure compliance with expected behaviors.
@github-actions

Copy link
Copy Markdown

Benchmark comparison

Threshold: ±25% (informational, does not block merge)

benchmark baseline (s) current (s) delta status
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_deferred_save_batched_100 0.016449 0.012141 -26.2% IMPROVED (-26.2%)
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_immediate_save_100 0.015955 0.011557 -27.6% IMPROVED (-27.6%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[hierarchy] 0.002773 0.002099 -24.3% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[ontology] 0.002752 0.002309 -16.1% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_projection_capture[relationships] 0.002553 0.002149 -15.8% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[hierarchy] 0.002441 0.001915 -21.5% OK
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[ontology] 0.002520 0.001834 -27.2% IMPROVED (-27.2%)
tests/benchmarks/test_graph_projection_benchmarks.py::test_warm_rich_projection_capture[relationships] 0.002421 0.001795 -25.9% IMPROVED (-25.9%)
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_batched_saves_500 0.425320 0.483751 +13.7% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_empty_query 0.001559 0.001239 -20.5% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_filtered 0.074688 0.058642 -21.5% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_find_filtered 0.073231 0.056918 -22.3% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_save_throughput 0.001349 0.001820 +34.9% REGRESSION (+34.9%)
tests/benchmarks/test_postgres_benchmarks.py::test_bench_postgres_find_many_bulk 0.000742 0.000650 -12.4% OK
tests/benchmarks/test_postgres_benchmarks.py::test_bench_postgres_traverse_depth 0.000409 0.000307 -24.7% OK
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_empty 0.000167 0.000119 -28.7% IMPROVED (-28.7%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_fallback_via_regex 0.022157 0.016263 -26.6% IMPROVED (-26.6%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_pushdown 0.001042 0.000736 -29.4% IMPROVED (-29.4%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_fallback_via_regex 0.023122 0.016620 -28.1% IMPROVED (-28.1%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_pushdown 0.000287 0.000237 -17.6% OK
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_sort_limit_pushdown 0.001839 0.001417 -22.9% OK

@abrouet
abrouet requested a review from eldonm November 13, 2026 17:26

@eldonm eldonm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All requested changes addressed: configurable neutral catalog table with documented schema, AGENTS.md external link removed, docs/CHANGELOG/SPEC placement fixed, schema validation, OTel test guard, auth span ERROR status, and constraints-mode keyset skip. Verified locally against live PostgreSQL (tests/db, tests/observability, tests/api: 1379 passed). Minor follow-up: note in postgres-guide that index_catalog_table is quoted and therefore case-sensitive.

@eldonm
eldonm merged commit b2b82e2 into main Nov 13, 2026
6 checks passed
@eldonm eldonm mentioned this pull request Nov 13, 2026
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.

2 participants