Repository navigation
perf(proxy): track the first reply to each simple query - #531
Conversation
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed 55c961fe · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review · claude-opus-5-5; rust-security · claude-opus-5-5 (no findings)
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check
No blocking findings. The reply tracking is correct for pg-proto 0.12.0, and the changelog move is correct because #497 merged after v3.1.0. cargo test -p cipherstash-proxy --lib postgresql::middleware passed: 210 tests.
Findings (5): 5 minor: 4 inline, 1 below.
packages/cipherstash-proxy/src/postgresql/middleware/settings_rollback_tests.rs:104(outside diff) minor This harness still buildsFrontendandBackendseparately and callsfrontend.interceptdirectly, soquery_forwardednever runs and a simple Query never releases the unnamed statement, unlike production.rollback_restores_original_keyset(extended) andpipelined_batch_that_changes_settings_and_rolls_back_restores_themmix the two paths, so their state differs from production. RouteClientthroughCipherStashMiddleware::intercept_frontend, asmiddleware/mod.rsnow does.
Source: code-review · claude-opus-5-5
Generated by Claude Code
cipherstash-bot
left a comment
There was a problem hiding this comment.
Recommendation: 🟢 merge as it is
Nothing must change before merging. Two optional test gaps can wait for a follow-up.
How this review was made
| Agent | Model | Review type | Result |
|---|---|---|---|
| claude | claude-opus-5-5 | test-gap | 2 found, 2 posted |
| claude | claude-opus-5-5 | rust | 0 found, 0 posted |
| codex | gpt-5.6-terra | test-gap | 0 found, 0 posted |
| codex | gpt-5.6-terra | rust | 0 found, 0 posted |
Synthesis: claude-sonnet-5-5 merged the findings, removed duplicates and dropped findings it could not confirm in the code. 0 posted finding(s) were raised by two or more models.
Plain language: claude-sonnet-5-5 read every comment as a new reader would. 1 comment(s) had a problem that stopped the reader acting; it rewrote 0.
Stack: not part of a stack.
Context loaded: the description, 0 linked issue(s) and 5 discussion entries.
Other findings not posted as comments
packages/cipherstash-proxy/src/postgresql/middleware/mod.rs:1546— Optional: No test checks that a Query that Proxy refuses is not added topending_queries.
| { | ||
| self.context.operation_answered(operation)?; | ||
| if let Some(query) = operation.filter(|&operation| self.take_first_query_reply(operation)) { | ||
| self.context.release_unnamed_statement(query)?; |
There was a problem hiding this comment.
Optional: No test forwards an unnamed Parse after a simple Query and before that Query's first reply.
Impact: release_unnamed_statement now runs when the Query's first reply arrives. By then, Proxy may already track a new unnamed statement from a pipelined Parse "". If deallocate_statements stops comparing operation order, Proxy deletes the new statement. No test would fail. The next Bind to "" would then use missing metadata.
Evidence: reparse_pipelined_after_deallocate_finishes_the_old_metrics in middleware/mod.rs covers the same order for a named statement after DEALLOCATE. No test covers a Parse "" after the Query.
Fix: Add a test next to reparse_pipelined_after_deallocate_finishes_the_old_metrics in middleware/mod.rs. It sends a Query, then Parse "", then Sync. It then delivers the Query replies, the ParseComplete and the Sync reply. It asserts connection.holds_statement(b"") and connection.sizes().pending_queries == 0.
Found by 1 model: claude
Track forwarded simple queries in wire order so unrelated replies avoid the protocol-state write lock. Exercise a query discarded after an extended error and document the model's batch boundary. Signed-off-by: Toby Hede <[email protected]>
7670abe to
e61d0d7
Compare
Summary
Proxy releases the unnamed prepared statement when PostgreSQL first answers a simple Query.
Tracking forwarded Queries in wire order lets unrelated backend replies skip the write lock used for that release.
Changes
Verification
On commit
55c961fe, 797 workspace unit tests passed and six were skipped.Formatting, Clippy and all 15 release-metadata checks passed.
The regression for a Query received after an extended-protocol error failed before the model change and passed afterward.
Related
Follow-up to #497.
Acknowledgment
By submitting this pull request, I confirm that CipherStash can use, modify, copy, and redistribute this contribution, under the terms of CipherStash's choice.