fix(selfhost): guard pg-adapter's rollback so it can't mask the original batch error - #6392
Conversation
…nal batch error
batch()'s catch block called client.query("ROLLBACK") unguarded, so a
rollback failure (plausible exactly when the original error was a
connection failure) would propagate instead of the real cause. Wrap
it in the same defensive try/catch { ignore } the SQLite adapter's
batch() already uses.
Added an integration test in test/integration/selfhost-pg.test.ts
(gated on PG_TEST_URL) that intercepts a real client's ROLLBACK call
to force it to throw, confirming the original batch error still
surfaces. Verified against a real local Postgres 16 container that
the test genuinely fails without the fix and passes with it.
Closes JSONbored#6282
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6392 +/- ##
===========================================
+ Coverage 52.69% 95.60% +42.90%
===========================================
Files 599 599
Lines 47238 47238
Branches 15031 15031
===========================================
+ Hits 24891 45160 +20269
+ Misses 19402 1291 -18111
+ Partials 2945 787 -2158
Flags with carried forward coverage won't be shown. Click here to find out more. |
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-16 06:22:37 UTC
Review summary Nits — 4 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
Closes #6282
Summary
pg-adapter.ts'sbatch()calledawait client.query("ROLLBACK")unguarded inside itscatchblock — if the rollback itself throws (plausible exactly when the original error was a connection failure), that new error propagated instead ofthrow error, silently discarding the real cause.d1-adapter.ts'sbatch()already wraps itsROLLBACKin a defensivetry/catch { /* ignore */ }for exactly this reason.pg-adapter.tsnow does the same.d1-adapter.tsitself is untouched — it was already correct, per the issue's explicit instruction.test/integration/selfhost-pg.test.ts(gated onPG_TEST_URL, per the issue's test coverage requirement) that grabs a real client from the pool, intercepts itsROLLBACKcall to force it to throw, and confirms the original batch error (a real SQL syntax error) still surfaces rather than the synthetic rollback failure.Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Validation
git diff --checknpm run actionlintnpm run typecheck— roottsc --noEmitreliably OOMs on this shared sandbox regardless of what changed (reproduced repeatedly this session). This change is a 4-linetry/catchwrap plus a new integration test; ran the whole root diff-check clean and the actual integration test suite against real Postgres (below).npm run test:coverage—src/selfhost/pg-adapter.tsis exempt from Codecov's unit-coverage requirement percodecov.yml(validated by the real-Postgres integration test instead, per the issue's own Test Coverage Requirements). Actually ran the integration test against a real local Postgres 16 container (docker run -d -e POSTGRES_PASSWORD=devpw -e POSTGRES_DB=gittensory -p 55432:5432 postgres:16, per the test file's own header instructions): all 7 tests intest/integration/selfhost-pg.test.tspass, including the new regression test. Verified the new test genuinely catches the bug — reverted just thepg-adapter.tsfix viagit stashand confirmed the test fails (expected ... to throw error matching /bad-sql|syntax/i but got 'simulated rollback failure') before re-confirming it passes with the fix restored.npm run test:workers— N/A, no Worker-facing code changed (this path is self-host-only).npm run build:mcp/npm run test:mcp-pack— N/A, no@loopover/mcpchanges.npm run ui:openapi:check/ui:lint/ui:typecheck/ui:build— N/A, noapps/loopover-uichanges.npm audit --audit-level=moderate— 0 vulnerabilities.git stash) before confirming it passes with it, against a real Postgres instance, not a mock.If any required check was skipped, explain why:
npm run typecheck: reliably OOMs on this shared sandbox under memory pressure from concurrent sessions, independent of the diff. This is a small, self-contained change (one guardedtry/catch, no new type surface) verified by real integration testing against actual Postgres instead.Safety
UI Evidencesection below with screenshots. — N/A, no visible UI change.CHANGELOG.mduntouched.Notes
test/integration/selfhost-pg.ts— the actual file istest/integration/selfhost-pg.test.ts(confirmed via repo search; the.ts-only name doesn't exist).