Repository navigation
fix: enable production PostgreSQL persistence - #142
Conversation
maralbahari
left a comment
There was a problem hiding this comment.
Thanks for the work. I left some inline comments
Signed-off-by: Francisco Javier Arceo <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
2c1ba13 to
b56cf79
Compare
ashwing
left a comment
There was a problem hiding this comment.
The earlier fixes hold up on 2c1ba13 and CI genuinely exercises the Postgres path via the --ignored integration run. One schema-validation portability issue I reproduced against a stock Postgres 17, plus an accuracy nit inline — none blocking.
Two more:
[nit]storage/response.rs— the row-lock hardening is conversation-scoped only.previous_response_idcontinuations readget(prev_id).history_item_idsoutside any lock, so two concurrent continuations of the same response read the same history and fork. That's legitimate under OpenAI response-chaining (forks are allowed) and each row is independent — not a bug — but worth stating so nobody assumes response chains are serialized the way conversations now are.- The two
docs/superpowers/...pr-142-review-followups*.mdfiles look like PR-process planning docs rather than user-facing deployment docs, and they're not in the mkdocs nav. There's precedent (a websocket-shutdown pair already on main), so if this is a deliberate planning archive that's fine — just checking they're meant to ship, and if so maybe excludedocs/superpowers/from the mkdocs build so it doesn't rot in the published docs.
| WHERE table_namespace.nspname = current_schema() \ | ||
| AND table_relation.relname = required.table_name \ | ||
| AND constraint_metadata.contype::text = required.constraint_type \ | ||
| AND pg_get_constraintdef(constraint_metadata.oid) = required.definition \ |
There was a problem hiding this comment.
[concern] current_schema()-pinned constraint validation fails to start under a non-public search_path.
postgres_required_constraint_count matches each constraint by exact string pg_get_constraintdef(oid) = definition and pins table_namespace.nspname = current_schema(), and it runs unconditionally on the auto-migrate path (widen_postgres_integer_columns -> validate_required_postgres_schema) — i.e. right after sqlx applies our own migrations into public.
I reproduced this on postgres:17-alpine: an app role with a role-named schema and the default managed-Postgres search_path = "$user", public makes current_schema() return the role's schema, not public. The validation then counts 0 of 6 required constraints and returns Err, so every replica fails to start even though the schema is correct:
as role 'agentic' (search_path="$user",public): current_schema() = agentic
constraint count found under current_schema(): 0 # expected 6
(I also checked the PG-version angle — 16 and 17 emit byte-identical pg_get_constraintdef output, so formatting drift isn't the issue; the schema-resolution is.)
It fails loud, not silent, so no corruption — but "app deployed with a per-role schema" is a common managed-PG default, not an edge case. Two options: resolve the tables' actual namespace instead of current_schema(), or scope the strict constraint-string check to the supervisor/AGENTIC_API_SCHEMA_READY path and trust sqlx's migration tracking on auto-migrate.
|
|
||
| /// Locks an existing conversation for the lifetime of the transaction. | ||
| /// | ||
| /// `PostgreSQL` takes a row lock without writing the row. `SQLite` uses a no-op |
There was a problem hiding this comment.
[nit] the doc comment says both backends "serialize per-conversation sequence allocation." Postgres does (SELECT id ... FOR UPDATE). But the SQLite no-op UPDATE ... WHERE id = $1 takes SQLite's database-level write lock, so it serializes all conversation persists globally, not per-conversation. Correct for safety — the granularity claim is just off, and it hides a SQLite write-throughput ceiling worth naming.
Signed-off-by: Francisco Javier Arceo <[email protected]>
## Summary - capture a typed conversation version alongside rehydrated history - reject stale explicit-conversation turns under the existing row lock before persistence - return a consistent `conversation_locked` error over HTTP, SSE, and WebSocket, including `generate: false` - preserve `previous_response_id` fork behavior and the existing unchecked storage API - add SQLite, transport, and two-pool PostgreSQL race coverage plus deployment documentation This builds on the PostgreSQL persistence foundation merged in #142. This implements optimistic conflict detection at persistence time. A pre-inference distributed lease or queue that also suppresses external tool side effects remains separate policy work. ## Test Plan - `cargo fmt --all -- --check` - `cargo clippy --all-targets -- -D warnings` - `cargo test` - `pre-commit run --all-files` - `postgres_concurrent_conversation_writes_have_contiguous_sequences` against PostgreSQL 17 - `postgres_optimistic_conversation_conflict` against PostgreSQL 17 - `postgres_lock_wait_is_bounded_without_blocking_other_conversations` against PostgreSQL 17 - read-only Claude review: no actionable findings - gstack pre-landing review: all in-scope actionable findings resolved Signed-off-by: Francisco Javier Arceo <[email protected]>
Summary
This is the PostgreSQL persistence slice of #102.
Closes #103.
Refs #102.
Test Plan