Skip to content

feat(dbapi): carry signed execution ownership claims - #99

Open
ClayMav wants to merge 4 commits into
mainfrom
clay/wbc-1983-dbapi-ownership
Open

ClayMav wants to merge 4 commits into
mainfrom
clay/wbc-1983-dbapi-ownership

Conversation

@ClayMav

@ClayMav ClayMav commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Problem

DBAPI can restore a running SQL execution on a fresh connection, but recovery needs to carry the current owner's proof. WBC-1983

Solution and why this one

Add an opt-in connection mode that requires the SQL-session ownership subprotocol before submitting. The driver keeps the coordinator's signed generation with each execution and reuses it for attach, result retrieval, cancellation, and transport recovery. SQL-session supplies the trust decision from its own configuration.

Protected connections require the SQL-session changes in https://github.com/wherobots/sql-session/pull/239.

Alternatives considered

The URL version is insufficient because older SQL-session builds can accept it and ignore added fields. The driver checks positive WebSocket negotiation instead.

Proof it works

  • uv run --locked pytest -q passed 363 tests. New tests cover fail-closed negotiation, malformed claims, signed terminal retrieval, and reattaching without replaying SQL.
  • Changed-file pre-commit passed.
  • A loopback TLS run against the matching SQL-session branch verified that DBAPI retrieved the original result after ownership changed and submitted a new protected query using a separate claim.

Claude Opus 5.5 at high effort reviewed twice. Addressed malformed claims, authenticated terminal result retrieval, and the typed error for reused protected IDs. The error tells callers the original query may have run.

Revision ab5856f

Salty Hambot found that a caller-supplied replacement transport skipped the capability check. The driver now rejects it before sending any claim. The new reconnect regression checks that the replacement receives no messages. The driver carries the issuer's signature and generation without a verification key from the caller.

Revision 5e0a82d

Added a regression for the protected failure reply and verified it over TLS with the real SQL-session WebSocket handler and a failing Spark query. The runtime puts the original SQL exception in the authorized result reply. The driver surfaces it as an OperationalError. Claude Opus 5.5 at high effort reviewed the test and confirmed this revision preserves the existing driver behavior. Review discussion

Revision 8c7f70f

The initial and replacement transport checks now use the same socket abort when ownership negotiation fails. The constructor regression supplies a transport with no close timeout and verifies rejection without a WebSocket close handshake or SQL request. The connect-direct and reconnect tests also verify the abort.

All seven GitHub checks passed on 8c7f70f, including Python 3.10–3.14 and pre-commit. Salty Hambot found no issues. GitHub Actions

What I did NOT test / where this is weakest

Hosted ingress and the Postgres signing coordinator are outside the local proof. Protected mode depends on SQL-session supporting the subprotocol.

Risk & confidence

  • Risk: Medium. Changes touch the driver's reconnect and cancellation paths.
  • Confidence: Medium. Legacy tests and local protected-path checks pass.
  • Blast radius: Opt-in protected SQL connections and the shared reconnect path.

New dependencies

None.

Reviewer focus

Check negotiation on reconnect and confirm that all ownership-bearing requests keep their proof out of application logs.


Author checklist

  • I read every line of this diff myself.
  • Every section above is filled in.
  • The evidence exercises this change.

Implemented by GPT-6.2 Sol through T3 Code's Codex harness.

@ClayMav ClayMav added the please-review-in-depth Changes that need thorough review label Nov 20, 2026
@ClayMav
ClayMav requested a review from a team November 20, 2026 04:16
@ClayMav

ClayMav commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

@salty-hambot review

@salty-hambot salty-hambot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings outside the diff:

wherobots/db/connection.py:752

medium: Validate ownership negotiation on replacement transports

A protected Connection can be constructed with a negotiated initial WebSocket and a transport_factory that later returns a WebSocket without the ownership subprotocol. On reconnect, __resume installs that socket and sends each pending query's signed ownership claim without checking its subprotocol; subsequent protected requests use it too. The constructor checks only the initial socket (lines 320–324). Although connect_direct's factory checks replacements, the public Connection constructor accepts other factories, so its fail-closed ownership guarantee does not hold across reconnects.

@salty-hambot salty-hambot Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Salty Hambot 🤖🧂 at 8c7f70f

No issues found.
💰 $0.1740 · 170.6k in / 2.7k out tokens · ⏱️ 27.8s · us.openai.gpt-6-sol high, prompt coverage-v1
💬 To request a re-review, comment @salty-hambot review

@ClayMav

ClayMav commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

@salty-hambot review

Comment thread wherobots/db/connection.py Resolved
@ClayMav

ClayMav commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

@salty-hambot review

Comment thread wherobots/db/connection.py Resolved
@ClayMav

ClayMav commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

@salty-hambot review

@ClayMav
ClayMav marked this pull request as ready for review November 20, 2026 20:00
@ClayMav ClayMav added please-rubber-stamp Safe changes eligible for a quick review and removed please-review-in-depth Changes that need thorough review labels Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

please-rubber-stamp Safe changes eligible for a quick review

Development

Successfully merging this pull request may close these issues.

2 participants