Commit Graph
6814 Commits
Author SHA1 Message Date
DottaandPaperclip 4336b9ee02 fix(db): reserve transactions before checking pipeline capacity (#17831)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Interactive requests share a PostgreSQL connection pool with
background work.
> - Prepared queries can queue behind a slow query on a busy connection.
> - Disabling pipelining lets queued work use the next free connection.
> - The driver skips its transaction reservation callback when the
pipeline limit is zero.
> - This pull request runs that callback before the capacity check.
> - Operators can test a pool without pipelining while transactions
retain their connection ownership.

## Linked Issues or Issue Description

**What happened?**

With `PGMAX_PIPELINE=0`, postgres.js 3.4.9 skips `onexecute` in its
short-circuit capacity check. A transaction then lacks its reserved
connection. Real PostgreSQL reproduces `UNSAFE_TRANSACTION` through the
app client and an undefined connection error through the raw driver.
This prevents safe use of the existing setting to reduce query queue
delays.

**Expected behavior**

A transaction must reserve its connection regardless of pipeline
capacity. Commit, rollback, savepoints, and disconnect recovery must
preserve their existing contracts.

**Steps to reproduce**

1. Use the pre-change driver patch from
`e61ee4b005f8e13f64af15f69cb62305dd869f82`.
2. Start disposable PostgreSQL and run the `no-pipeline` scenario in
`packages/db/src/__fixtures__/postgres-connection-recovery.mjs` with
`TEST_DATABASE_URL`, `DRIVER_FORMAT=esm`, and
`RECOVERY_CASE=no-pipeline`.
3. Observe the transaction failure. Apply this patch and repeat with
both `esm` and `cjs`.

Refs #13643, which introduced the existing connection recovery patch.
Searched related open and closed driver PRs. This change extends that
patch and preserves its disconnect safeguards.

## What Changed

- Move the transaction reservation callback before the pipeline capacity
check in both driver distributions.
- Add real PostgreSQL regressions for commits, concurrent transaction
reads, isolation, rollback, savepoints, reserved connections, and
progress on a freed pool connection.
- Document the existing `PGMAX_PIPELINE=0` setting and its driver
prerequisite. Keep the default pipeline limit unchanged.

## Verification

- `pnpm -r typecheck`: passed.
- `pnpm build`: passed.
- Real PostgreSQL 18.6 in an owned, disposable Docker container: the old
patch fails the new transaction scenario in both ESM and CommonJS. The
corrected patch passes all 18 scenarios, including all 12 existing
disconnect recovery cases. The container was removed afterward.
- Local service benchmark: actual `createDb` with prepared statements,
two warmed connections, two controlled advisory lock waits, and the
complete three-query `getDefaultCompanyGoal` path. Two warmups and five
alternating measured samples per setting. Pipeline 100: median 413.44
ms, range 413.33–416.10 ms. Pipeline 0 with the patch: median 12.22 ms,
range 11.86–12.57 ms. Complete SQL, bindings, and results match. Five of
five reads finish while the unrelated slow query remains blocked. These
are synthetic local queue measurements, not hosted latency claims.
- App client compatibility on real PostgreSQL: commit, concurrent
transaction reads, rollback, nested savepoint rollback, dedicated
connections, and liveness connections passed.
- `pnpm test:run`: attempted, then stopped after repeated local embedded
PostgreSQL startup failures caused by the host semaphore limit. This is
an incomplete local full-suite run, not a pass. The focused driver
checks above used disposable Docker PostgreSQL instead. The initial
sandbox attempt also stopped before test execution because tsx could not
bind its IPC socket. Final CI results will be recorded here.
- Current head `72039f71f63530300bf241475d42e857297dfb90`: Greptile and
Paperclip review are both 5/5. All three earlier findings are resolved.
[CI run
40431567516](https://github.com/paperclipai/paperclip/actions/runs/40431567516)
ran the complete validation matrix. The database lane passed all 265
tests, including all 18 real PostgreSQL driver regressions. One cleanup
timer case timed out in server shard 6/12; its isolated real-PostgreSQL
reproduction passed once and failed once, while five runs with the
pre-change driver passed. That evidence is retained and does not
establish the timer failure's cause. A single CI retry of the failed
shard passed. The final aggregate `ci / verify` gate is waiting for a
runner. Its first queued request did not start for more than 14 minutes.
A guarded queue reset confirmed that it was the only unfinished job and
that every test job had passed; attempt 3 restarts only that gate. No
test result was replaced or bypassed. The required gate must pass before
merge.

## Risks

- This changes a shared driver callback order. Both module formats and
existing disconnect recovery are covered by real database tests.
- This PR does not change pool size, enable the setting by default,
retry SQL, or change schemas. Disabling pipelining may reduce batch
throughput. Operators must compare the workload before retaining that
setting.
- The local queue benchmark proves the mechanism. Hosted request
improvement still needs acceptance after the patched image is deployed.

## Model Used

OpenAI GPT-6 in Codex, with code execution and browser developer tools.
The exact serving model identifier and context window are not exposed in
this session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-27 03:00:01 +00:00
Dotta fdd772c7a7 test: cover corrected case facts and concurrent reread 2026-10-26 21:58:21 -05:00
Dotta 89163d7f73 test(evals): author governed independent native review journey 2026-10-26 21:57:06 -05:00
Dotta 6d04ec8d5f test(evals): rotate gateway tokens through isolated real UI flow 2026-10-26 21:56:37 -05:00
Dotta bcd7ca5e77 test(evals): distinguish substantive blue steering and observed branch 2026-10-26 21:52:31 -05:00
Dotta 1ad14e1abc docs(evals): pin pending handoff cutoff to committed active steering 2026-10-26 21:50:01 -05:00
Dotta 77b5eadea1 docs(evals): record finite pending authoring and privacy handoffs 2026-10-26 21:49:44 -05:00
Dotta ac8ac79d68 test(evals): author actual native same-turn steering journey 2026-10-26 21:48:43 -05:00
Dotta 37b72e28e3 test(evals): provision genuine plugin-managed routine and preserve its controls 2026-10-26 21:48:20 -05:00
Dotta edbf426db3 test(evals): distinguish unsupported skill action from unfinished denial coverage 2026-10-26 21:48:20 -05:00
Dotta 8a5da0ab01 test(evals): exercise actual board test-as-agent and provider outcome 2026-10-26 21:47:45 -05:00
Dotta f097a9da02 test(evals): accept independently accessible delegation briefs 2026-10-26 21:45:07 -05:00
Dotta d4f02a1e67 test(evals): reject premature and wrong-client rotation guidance 2026-10-26 21:44:36 -05:00
Dotta c211c554b4 test(evals): verify scoped token rotation and Notion assignment continuation 2026-10-26 21:41:11 -05:00
Dotta fe05c54c11 test(evals): probe real skill assignment authority and future version delivery 2026-10-26 21:40:00 -05:00
Dotta fa7eba012e evals: carry real launch brief through one Morgan handoff and result 2026-10-26 21:36:20 -05:00
Dotta 29485d6a45 test(evals): verify real team installation and member configuration 2026-10-26 21:34:13 -05:00
Dotta 6cc0012da0 test(evals): reject negated mobile checkout failure claims 2026-10-26 21:33:38 -05:00
Dotta d1fa9efdaf test(evals): cover encoded diagnostics and enforce private host isolation 2026-10-26 21:33:38 -05:00
Dotta 7154ba9e85 test(evals): bind approved workspace repositories and preserve no-profile setup 2026-10-26 21:33:38 -05:00
Dotta 69b2e2b1a2 test(evals): keep authenticated API cookies outside Test parameters 2026-10-26 21:33:37 -05:00
Dotta 8d4168d1ed evals: reject contrary managed qualification and retention advice 2026-10-26 21:30:23 -05:00
Dotta 2e4258749a evals: verify truthful operator path for unqualified managed profiles 2026-10-26 21:27:36 -05:00
Dotta 2d53c3952f test(evals): hand off Morgan primary through genuine native authority 2026-10-26 21:19:08 -05:00
Dotta 4e73b7bb70 test(evals): protect short multiline diagnostic credentials 2026-10-26 21:18:45 -05:00
Dotta db4c051441 evals: route existing website feedback while preserving delivered logo 2026-10-26 21:14:24 -05:00
Dotta ad4b0162ae test(e2e): isolate identity entry and verify post-retry chat result 2026-10-26 21:12:12 -05:00
Dotta b72f0f7cbb test(evals): redact private diagnostic streams and opaque reporter sinks 2026-10-26 21:10:10 -05:00
Dotta bf54b256db evals: prove design dependency gates actual website admission 2026-10-26 21:09:24 -05:00
Dotta c410c08205 evals: keep standalone browser privacy canary explicit and opt in 2026-10-26 21:09:24 -05:00
Dotta 098303bf13 evals: install disabled-chat human session through private state file 2026-10-26 21:04:31 -05:00
Dotta 1ef868b0ac evals: isolate human API key UI and leakage scans from Test recording 2026-10-26 21:02:32 -05:00
Dotta 2f31e660e2 test(evals): separate schedule pause from genuine running routine work 2026-10-26 20:55:36 -05:00
Dotta 84cd4a4366 test(evals): isolate secure entry from Playwright reporter artifacts 2026-10-26 20:55:27 -05:00
Dotta 766afb3149 evals: verify human subtree pause and independent child gates 2026-10-26 20:55:24 -05:00
Dotta 2e1943a7c7 test(evals): prove case work links and current principal access 2026-10-26 20:52:51 -05:00
Dotta ce5fbfc2af evals: cover pending discard and consumed cancellation as new direction 2026-10-26 20:50:07 -05:00
Dotta baca00beb9 test(evals): verify real bounded Studio input revision and output 2026-10-26 20:49:44 -05:00
Dotta e1000c7fcc test(evals): observe manual routine delivery and actual later result 2026-10-26 20:46:07 -05:00
Dotta 0d73ba89c3 test(evals): prove secure key setup and flexible Notion semantics 2026-10-26 20:41:55 -05:00
Dotta 8e57349a43 test(evals): bind Morgan handoff chat to a real engineer principal 2026-10-26 20:38:47 -05:00
Dotta 079d05e893 test(evals): author named Notion read proof and viewer boundary 2026-10-26 20:34:39 -05:00
Dotta 81e03353d5 test(evals): cover real preview lifecycle and queued requirement delivery 2026-10-26 20:34:24 -05:00
Dotta 40af4fe402 test(evals): verify viewer-limited assistant consent 2026-10-26 20:28:44 -05:00
Dotta 94cf8870d6 test(evals): accept concise truthful routine history answers 2026-10-26 20:28:08 -05:00
Dotta d162a92c3f test(evals): capture the actual authenticated disabled chat page 2026-10-26 20:27:18 -05:00
Dotta 089283890d test(evals): preserve routine invocation and native failure history 2026-10-26 20:26:13 -05:00
Dotta 6e41ca33d8 test(evals): cover disabled chat and actual failed native history phases 2026-10-26 20:24:50 -05:00
Dotta 43d984ae5a test(evals): bind strict SSH known-host input declarations 2026-10-26 20:24:48 -05:00
Dotta 8b82676ed6 test(e2e): author native accounting and partial subscription journeys 2026-10-26 20:22:47 -05:00