Repository navigation
fix(canary): read the configured SQL backend so the invariant harness is not blind on PostgreSQL (#1540) - #1690
Merged
Merged
Conversation
…1540) The canary snapshot collector opened a raw sqlite3 connection via db.connection.get_db_connection(), which deliberately ignores a non-SQLite DATABASE_URL. On a PostgreSQL deployment every SQL-tier collector read a stale/empty /data/trinity.db, so _collect_known_agents() returned zero rows -> snap.agents empty -> the whole per-agent loop (S-01/E-05/B-02/E-04/G-04 and B-01) plus the fleet-wide reads (E-02/E-03/G-03/E-06/L-03) went vacuously green. The canary was blind exactly where the pull/work-stealing migration (#1081) leans on it as the default-ON safety net. Repoint the six remaining collectors (_collect_known_agents, _collect_executions, _collect_terminal_executions, _collect_terminal_rows, _collect_enabled_schedules, _collect_orphan_refs) onto get_engine()/DATABASE_URL via SQLAlchemy Core, following the shipped _collect_queued_ids_via_engine template. SQLite-only PRAGMA table_info introspection is replaced with portable sqlalchemy.inspect(conn) reflection (fail-open on minimal/older DDLs, identical to before). Orphan-scan PK is derived from the STATIC db/tables.py Table (primary_key.columns), never reflection, so the composite-PK agent_tags table does not KeyError. No schema change (read-path repoint only) -> Invariant #3 dual-track migration not triggered. Imports stay lazy inside each collector to preserve the canary's low-dependency-leaf discipline. The sqlite.* labels in sources_unavailable are preserved verbatim (a load-bearing skip-contract prefix for L-03/E-02). db/connection.py is left untouched (sqlite-only maintenance seam). Co-Authored-By: Claude Fable 5 <[email protected]>
… seam (#1540) Three test updates required by the collector engine-seam port: - test_b01_backend_consistency_on_diverged_backend: the whole collector now reads the ENGINE file, so put the agent + queued rows there and assert the RAW file is ignored (strengthens the #1450 test into a #1540 un-blinding proof: a RAW-only ghost agent is invisible; queued_exec_ids reads the engine too). - test_column_absent_skips_collection: route the minimal DDL through DATABASE_URL instead of patching db.connection, so it exercises the inspect() column guard (fail-open identical to the old raw PRAGMA guard). - agent_tags test DDL: fix to the production composite PK (agent_name, tag) with no id column, so the composite->synthetic row_id orphan-scan branch is actually exercised on the SQLite rail (guards the KeyError('id') a reflected-PK port would have shipped). Co-Authored-By: Claude Fable 5 <[email protected]>
…PK, PG)
New TestIssue1540EngineSeam class:
- Un-blinding gate (split fixture): agents/rows written to the ENGINE file only
populate snap.known_agents/snap.agents (the core proof the vacuous-green
per-agent loop opened); RAW-only rows are ignored (reads moved off
db.connection). S-01 fires on a synthetic engine slot-row mismatch and stays
green on a clean bijection; L-03/E-05 un-blind on engine-only fleet-wide reads.
- Composite-PK agent_tags orphan scan yields synthetic 'agent_tags-row' row_id
(regression for the KeyError('id') a reflected-PK port would crash on).
- Minimal-DDL _collect_executions fail-open through the engine (inspect() column
guard: absent session/lease/queued-meta columns skip, not error).
- Engine-down preserves the sqlite.* sources_unavailable prefixes verbatim and
L-03/E-02 skip on them (pins the label->skip contract; guards a cosmetic
rename silently disabling the fail-open skip).
- Static import-guard: snapshot.py no longer imports db.connection.
- Env-gated real-Postgres test (TRINITY_TEST_PG_URL): drives collect_snapshot()
against postgres:16-alpine, asserts sources_unavailable == [] (no collector
errored on psycopg2) + S-01/L-03 fire. RUN and PASSING against a live
postgres:16-alpine container.
Co-Authored-By: Claude Fable 5 <[email protected]>
…n G3 (#1540) - architecture.md Canary section lead: reads state across Redis x the configured SQL backend (SQLite OR PostgreSQL via DATABASE_URL), not SQLite-only. - architecture.md B-01 catalog row: the collector-wide migration landed (#1540) — all six SQL-tier collectors honor DATABASE_URL, so the whole harness (not just B-01) is un-blinded on PG; the sqlite.* sources_unavailable labels are kept verbatim as an internal L-03/E-02 skip-contract prefix. - Pull-migration G3 caveat closed in PULL_MIGRATION_{TESTING,ROLLBACK,STATUS}: the canary is now a trustworthy PG signal (verified against postgres:16-alpine). Co-Authored-By: Claude Fable 5 <[email protected]>
Canary lives inline in architecture.md (no dedicated flow doc), matching the #1450/#1077/#1446 convention of a Recent Updates row pointing at architecture.md. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Resolve by running |
vybe
approved these changes
Jul 19, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Validated via /validate-pr: engine-seam repoint un-blinds the canary on PG, named #1540 regression coverage incl. real-PG dialect gate, composite-PK handling for agent_tags. TRINITY_TEST_PG_URL is test-only (no compose wiring needed). All checks green. Approving.
#1484 feature-flows rows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1540
Summary
The CANARY-001 invariant harness opened a SQLite connection unconditionally (
db.connection.get_db_connectionhardcodessqlite3and ignores a non-SQLiteDATABASE_URL), so on a PostgreSQL-backed deployment its SQL-tier collectors inspected a stale/empty/data/trinity.dbinstead of the live PG database._collect_known_agentsreturned zero rows →snap.agentsempty → the whole per-agent loop (S-01/E-05/B-02/E-04/G-04/B-01) plus the fleet-wide reads (E-02/E-03/G-03/E-06/L-03) went vacuously green. The harness was effectively blind to the live database at that tier.This finishes the #1450 collector-wide migration:
get_engine()/DATABASE_URLseam —_collect_known_agents,_collect_executions,_collect_terminal_executions,_collect_terminal_rows,_collect_enabled_schedules,_collect_orphan_refsnow read through the same engine seam B-01 already used, so the whole harness is backend-consistent on PostgreSQL.PRAGMA table_info→sqlalchemy.inspect()— the column-existence probes (older-image skips) are now portable across SQLite and PG instead of SQLite-only DDL introspection.agent_tagshandling — the orphan-scan primary key is taken from the staticdb/tables.pyTabledefinition, not runtime reflection;agent_tagshas a composite PK, so it maps to a syntheticrow_idrather than assuming a single-column PK.Verification
tests/test_canary_invariants.py→ 139 passed, 1 skipped (the 1 skip is the real-Postgres dialect gate,TRINITY_TEST_PG_URL). Re-run at ship stage, still green.postgres:16-alpineat both implement and review stages (via theTRINITY_TEST_PG_URL-gated test).--skip-agent: PASS — build + import-smoke, boot + health, and the integration suite all green.Notes
sqlite.*sources_unavailablelabels are kept verbatim as an internal skip-contract prefix for L-03/E-02, not a backend claim — they are a stable contract string, not a description of the DB in use.Follow-ups (for Andrii to file)
.claudesubmodule test-runner catalog entry for the new canary coverage is prepared locally but left uncommitted — the core team lands.claudechanges via the privatetrinity-devsubmodule, not through this public-repo PR.🤖 Generated with Claude Code