mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Paperclip stores control-plane state in PostgreSQL through
`packages/db`
> - A self-hosted instance can reach a local PostgreSQL service through
a Unix socket
> - libpq URIs select the socket with the `host` query parameter, but
postgres.js sends that parameter as a server setting and uses TCP
> - This pull request maps the URI `host` parameter to the driver host
option in one shared helper
> - The benefit is that app connections, migrations, backups, and
restores use the socket that the URI selects
## Linked Issues or Issue Description
**What happened?**
With
`DATABASE_URL=postgresql://paperclip@localhost:5432/paperclip?host=/run/postgresql`,
Paperclip connected over TCP to `localhost` instead of the socket.
**Expected behavior**
All JavaScript connections use the socket directory in `host`.
Percent-encoded paths also work. TCP URIs do not change.
**Steps to reproduce**
1. Run PostgreSQL with a Unix socket directory.
2. Set `DATABASE_URL` to a URI with `?host=<socket-directory>`.
3. Start Paperclip or run a JavaScript backup.
4. See that the connection uses TCP, not the socket.
**Paperclip version or commit**
upstream master cde944ed7
**Operating system**
Linux, Node 24
## What Changed
- Add `connectPostgres` in `packages/db/src/postgres-connection.ts`. It
moves the URI `host` parameter into the driver `host` option. Explicit
options still win.
- Use it in `createDb`, the utility clients, and `backup-lib.ts`.
- Key the teardown registry by the `host` parameter when it is set.
- Add tests, including a socket backup and restore with an unreachable
TCP hostname.
- Document socket URIs in `doc/DATABASE.md`.
## Verification
Rebased onto upstream `322fa6b65c` (squashed into one commit; conflicts
in `client.ts` and `client-teardown-registry.test.ts` resolved,
`codex-credentials.test.ts` taken from upstream because it already
carries the quorum fixture fix).
- `pnpm exec vitest run packages/db/src/postgres-connection.test.ts
packages/db/src/postgres-uri-host.test.ts
packages/db/src/client-teardown-registry.test.ts
packages/db/src/client.test.ts packages/db/src/backup-lib.test.ts`: 5
files, 47 tests passed.
- `pnpm --filter @paperclipai/db typecheck`: pass.
- The new tests fail when the helper ignores `host`.
- Added code comments removed per CONTRIBUTING.md; the same five test
files and `tsc` re-run after removal: pass.
## Risks
- Low risk. URIs without a `host` query parameter use the old code path.
- A URI with both a hostname and `host` now connects to `host`. This is
the libpq rule.
## Model Used
Original change: OpenAI gpt-6.1-sol via OpenCode. Cleanup and rebase:
Anthropic Claude Opus 5.5 (claude-opus-5-5), 1M context, tool use.
## 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
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { connectPostgres } from "./postgres-connection.js";
|
|
|
|
it("uses a Unix socket rather than TCP for libpq host URIs", async () => {
|
|
const client = connectPostgres("postgresql://runtime@localhost:5433/example?host=/run/postgresql");
|
|
try {
|
|
expect(client.options.host).toEqual(["/run/postgresql"]);
|
|
expect(client.options.path).toBe("/run/postgresql/.s.PGSQL.5433");
|
|
expect(client.options.connection).not.toHaveProperty("host");
|
|
} finally {
|
|
await client.end();
|
|
}
|
|
});
|
|
|
|
it("preserves explicit driver host overrides", async () => {
|
|
const client = connectPostgres("postgresql://runtime@localhost/example?host=/run/postgresql", {
|
|
host: "/other/socket",
|
|
port: 5434,
|
|
});
|
|
try {
|
|
expect(client.options.path).toBe("/other/socket/.s.PGSQL.5434");
|
|
expect(client.options.connection).not.toHaveProperty("host");
|
|
} finally {
|
|
await client.end();
|
|
}
|
|
});
|
|
|
|
it("supports TCP hosts in the libpq host query parameter", async () => {
|
|
const client = connectPostgres("postgresql://runtime@localhost:5433/example?host=db.example");
|
|
try {
|
|
expect(client.options.host).toEqual(["db.example"]);
|
|
expect(client.options.path).toBeFalsy();
|
|
expect(client.options.connection).not.toHaveProperty("host");
|
|
} finally {
|
|
await client.end();
|
|
}
|
|
});
|