Skip to content

Qualify Sites evidence API against pinned SQL and fix JSONB journey capture - #1266

Merged
sidneyswift merged 3 commits into
mainfrom
codex/sites-evidence-sql-bridge
Nov 18, 2026
Merged

sidneyswift merged 3 commits into
mainfrom
codex/sites-evidence-sql-bridge

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Review capture rejected unchanged reports after PostgreSQL JSONB reordered journey keys. Capture now uses the existing journey schema for artifact comparison, matching assessment, while preserving the original report and digests.

The offline bridge executes actual capture, stored assessment, selected publication and typed RPC wrappers against unchanged Database #136 at afd214aa73dfd70b0f2b860fce90c12ceb23f28b. It verifies/freeze-loads 31 API modules and verifies 16 Database/bootstrap sources. External authority/provider reads are explicit synthetic seams; no PostgREST exposure, hosted authentication, provider acceptance or publication activation is claimed.

The parent owns disposable directory leases, quiesces its dedicated worker group, independently identifies/stops PostgreSQL by the exact registered data directory, and verifies process/socket absence before deleting files. Uncertain cleanup preserves evidence. Lifecycle responsibilities and source verifiers are separate modules.

Validation at ddd614c998ffdbc837f8bfde58333350c36d648c:

  • All ten reported checks pass. Full unit CI: 9,978 passed / 67 skipped; downstream offline workflow, production TypeScript and contract-type steps pass.
  • PostgreSQL 15/17 CI: 14 business-contract cases, six lifecycle faults and old-output stale-marker rejection pass on each version. Source loader: 31 loaded / zero missing; this is load attribution, not every-branch coverage.
  • Local focused API tests: 148 passed; dedicated fixture cases correctly skip without the runner. Focused actual-import types, lint and formatting pass. Broad test-inclusive repository TypeScript remains separately non-green.
  • Exact-head independent spec/standards reviews clear. Seventeen review threads resolved; final Cubic review reports zero issues in the latest eight-file delta. CodeRabbit was skipped/manual-review-required.

The stale-marker negative covers old output reuse, not foreign root/worker marker injection at the current-root read path. Those identity comparisons are source-reviewed guards. Database #136 remains draft and unapplied; no SQL proposal, route/factory wiring or activation changes. Root retains merge/release approval.

@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Nov 18, 2026 12:26am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Solid & Clean Code Warning Summary: The check fails. The PR adds new bridge tooling under scripts/sites-evidence-sql-bridge/ (all files new in commits 54beb4e, 4dcdc4f, ddd614c). That code breaks the explicit file-func… 1. Fix the file-function name rule: - Rename quoteFixtureLiteral.ts to literal.ts, or rename the export to quoteFixtureLiteral. - Move _worker and main out of run.py. Keep run.py as a thin entry point, or name the module after…
Full details: Solid & Clean Code

Explanation

Summary: The check fails. The PR adds new bridge tooling under scripts/sites-evidence-sql-bridge/ (all files new in commits 54beb4e, 4dcdc4f, ddd614c). That code breaks the explicit file-function name rule, the 20-line function rule, and the constants rule. The production change is small, but it sits inside an already long function. Scope of the change (verified): - Production: lib/sites/production/captureSavedSiteReview.ts already existed before this PR. Commit 54beb4e adds 7 lines. It adds an inline experienceContractSchema.safeParse journey check and error branch. The function body is still about 65 lines. - Bridge tooling: all bridge files are new in this PR. The directory is test and verification tooling, but the check text does not exclude tooling. Violations still present at HEAD ddd614c9: 1. File-function name rule (explicit). - quoteFixtureLiteral.ts (added in 4dcdc4f, untouched in ddd614c) exports literal. The file name does not match. - run.py defines two top-level functions, _worker and main. Neither matches the file name run. 2. Functions over 20 lines (explicit). Measured with Python ast for the Python files and by reading the TypeScript file: - run.py main(): 92 lines. It mixes argument parsing, self-test, fault dispatch, source pinning, lifecycle, reporting, and cleanup. It nests try/finally blocks several levels deep. - run.py _worker(): 33 lines. - install_lifecycle.py install_lifecycle(): 52 lines. - stop_owned_cluster.py stop_owned_cluster(): 48 lines. - fixtureSql.ts fixtureSql(): about 50 lines. It validates the socket and marker and runs psql. 3. Repeated values (explicit "use constants"). - Port 55473 appears in fixtureSql.ts line 25. - .s.PGSQL.55473 appears in stop_owned_cluster.py line 82 and install_lifecycle.py line 46. - The two interrupted signal handlers are near duplicates. They sit in run.py lines 98-99 and install_lifecycle.py lines 73-74. Prior failure disposition: The prior FAIL remains valid for the current state. Some items are resolved: - verify_sources.py was split into verify_api.py and verify_database.py. - lifecycle.py was split into install_lifecycle.py, quiesce_worker.py, and stop_owned_cluster.py. These items remain open: - quoteFixtureLiteral.ts name mismatch. - run.py main() length and its two top-level functions. - The fixtureSql() length. - The duplicated port and socket literals. - The duplicated signal handlers. - The journey-check helper in captureSavedSiteReview.ts. Positive evidence: The production diff is minimal and reuses experienceContractSchema. The original report is preserved. The lifecycle split reduced the responsibility count of the largest file.

Resolution

  1. Fix the file-function name rule: - Rename quoteFixtureLiteral.ts to literal.ts, or rename the export to quoteFixtureLiteral. - Move _worker and main out of run.py. Keep run.py as a thin entry point, or name the module after its single primary function. 2. Reduce long functions to 20 lines or fewer: - Split run.py main() into named steps: pin verification, source load, worker launch, cleanup, and fault assertion. - Split fixtureSql() into a socket and marker validator and a psql runner. - Split install_lifecycle() into one helper per fault mode. - Split stop_owned_cluster() into smaller steps. 3. Remove duplication: - Define the port 55473 and the socket file name .s.PGSQL.55473 once. Source them from sources.json or a shared constants module, and import them in TypeScript and Python. - Share one signal-handler factory for both interrupted handlers, or keep one handler at the process entry point. 4. In lib/sites/production/captureSavedSiteReview.ts, extract the journey-artifact check (the safeParse plus the prepareSiteRenderArtifacts comparison) into a named helper. This keeps the function on one responsibility.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T00:06:36.692700Z 54beb4e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 12 files

Confidence score: 4/5

  • network-deny.ts leaves outbound connections available through WebSocket and node:http2, so the offline guarantee is incomplete. Add denials for those entry points.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/sites-evidence-sql-bridge/network-deny.ts">

<violation number="1" location="scripts/sites-evidence-sql-bridge/network-deny.ts:25">
P3: The deny shim leaves outbound paths open: global `WebSocket` (present on Node 22) and `node:http2` `connect`/`request` are not replaced. Add denials for them so the offline guarantee holds for every network entry point.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant CI as CI Workflow
    participant Runner as run.py
    participant Worker as Isolated Worker
    participant PG as PostgreSQL (15/17)
    participant Test as Vitest Bridge Suite
    participant API as Real API Modules
    participant DB as Database Repo

    Note over CI,DB: NEW: Offline cross-layer qualification bridge

    CI->>Runner: Execute with pinned DB commit
    Runner->>Runner: Verify API source SHA-256 hashes
    Runner->>DB: git show pinned DB files
    DB-->>Runner: Verified source bytes
    Runner->>Worker: Spawn with minimal env (no credentials, no dotenv)
    Worker->>PG: Bootstrap via SitesEvidence fixture
    PG-->>Worker: Disposable cluster + socket marker
    Worker->>Test: Launch Vitest bridge suite

    Test->>Test: Deny all network APIs

    Test->>API: captureSavedSiteReview()
    API->>API: parse journey with experienceContractSchema
    API->>API: recompute artifacts (NEW: normalize JSONB key order)
    API->>Test: Return captured evidence record
    Test->>API: assessStoredSitePublishEvidence()
    API->>API: validate stored assessment
    Test->>API: publishSelectedSiteEvidence()
    API->>API: run authority/receipt validators

    API->>Test: rpc() envelope stub
    Test->>PG: psql (Unix socket, fixed local, no shell)
    PG-->>Test: SQL result or SQLSTATE
    Test-->>API: Typed RPC response

    alt Postcommit response lost/tampered/null
        Test->>API: Simulate failure after SQL commit
        API->>API: Propagate error, no retry
    end

    alt Stale revision/pointer/artist injected
        Test->>PG: Inject actual competing SQL change
        API->>API: CAS fails → 409 (40001)
    end

    Test->>Runner: All 13 cases pass or fail
    Runner->>Runner: Collect evidence + logs
    Runner-->>CI: Loader attribution + results
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 16 files (changes from recent commits).

Confidence score: 5/5

  • scripts/sites-evidence-sql-bridge/bridge.integration.test.ts is about 298 lines, well over the repo’s 100-line style limit, and the new test adds to it. Split the tests into smaller focused files.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/sites-evidence-sql-bridge/bridge.integration.test.ts">

<violation number="1" location="scripts/sites-evidence-sql-bridge/bridge.integration.test.ts:227">
P3: Custom agent: **Enforce Clear Code Style and Maintainability Practices**

This file is 298 lines — nearly 3x the 100-line limit required by the repo style rule, and the new test case grows it further. The bulk of the length is the ~90 lines of vi.mock scaffolding plus shared helpers (uid/seed/snapshot/row/vector). Extract those into a fixtures/helpers module (or split the suite by concern) so each file stays near the 100-line limit.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 8 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Adds a disposable API-to-SQL qualification bridge and fixes JSONB key-order handling during review capture. The runtime fix is narrowly scoped to artifact comparison, preserves the original report and digests, and does not activate publication.

View guided diff | Turn on auto-fix | Re-trigger cubic

@sidneyswift
sidneyswift merged commit 37b5a07 into main Nov 18, 2026
10 checks passed

This branch was successfully deployed

1 active deployment
Preview — ddd614c9 Deployed Nov 18, 2026 by vercel[bot]
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