Skip to content

feat: add execution progress handler#56

Open
peterfoldes wants to merge 3 commits intomainfrom
peter/progress-handler
Open

feat: add execution progress handler#56
peterfoldes wants to merge 3 commits intomainfrom
peter/progress-handler

Conversation

@peterfoldes
Copy link
Contributor

@peterfoldes peterfoldes commented Feb 25, 2026

Summary

Add Connection.set_progress_handler() that lets callers receive real-time execution progress events from the SQL session.

When a handler is registered, execute_sql requests automatically include enable_progress_events: true. The server streams execution_progress events with task counts, and the SDK dispatches them to the user's callback. Pass None to disable.

This is a backwards-compatible change. The SDK can safely send enable_progress_events: true to older server versions that don't support it — the unknown field is silently ignored and queries execute normally. Progress events are best-effort: depending on the server version and query type, the handler may not be invoked.

Companion server-side PR: https://github.com/wherobots/sql-session/pull/189

Related Issues

Relates to sql-session#189


Requester Checklist

Complete these before marking Ready for Review

  • I have self-reviewed my own code
  • I have added/updated tests that prove my fix/feature works
  • I have included visual proof (screenshot, video, or test output) if applicable
  • All CI checks are passing
  • PR size is S/M, OR I have justified the size and added a walkthrough
  • I have updated documentation if needed

Visual Proof

Tested end-to-end on staging with a custom image built from the sql-session peter/execution-progress branch:

Without --progress (baseline — no regression):

Request: {"kind": "execute_sql", "execution_id": "dfe6b4eb-...", "statement": "SELECT 1 AS test_col"}
┏━━━┳━━━━━━━━━━┓
┃ # ┃ test_col ┃
┡━━━╇━━━━━━━━━━┩
│ 0 │ 1        │
└───┴──────────┘

With --progress (progress events flowing):

Request: {"kind": "execute_sql", ..., "enable_progress_events": true}
< {"kind":"execution_progress","execution_id":"90199781-...","tasks_total":0,"tasks_completed":0,"tasks_active":0}
  [progress] ?  0/0 tasks (0 active)  90199781
┏━━━┳━━━━━━━━━━┓
┃ # ┃ cnt      ┃
┡━━━╇━━━━━━━━━━┩
│ 0 │ 10000000 │
└───┴──────────┘

Backwards compatibility (against current released staging, no custom image):

Request: {"kind": "execute_sql", ..., "enable_progress_events": true}
(no progress events received — server ignores unknown field)
┏━━━┳━━━━━━━━━━┓
┃ # ┃ test_col ┃
┡━━━╇━━━━━━━━━━┩
│ 0 │ 1        │
└───┴──────────┘

Size Justification (if L/XL)

N/A — small PR (+83/-2 lines across 4 files)


Reviewer Checklist

If these are not met, close the tab — this PR is not ready for review

  • Requester checklist above is complete
  • All CI checks are passing
  • Tests adequately cover the changes

@peterfoldes peterfoldes force-pushed the peter/progress-handler branch 2 times, most recently from 65b446a to 6eaca5b Compare February 25, 2026 11:51
@peterfoldes peterfoldes marked this pull request as ready for review February 25, 2026 11:57
@peterfoldes peterfoldes requested a review from a team as a code owner February 25, 2026 11:57
@peterfoldes peterfoldes requested review from mpetazzoni and removed request for a team February 25, 2026 11:57
@peterfoldes peterfoldes force-pushed the peter/progress-handler branch from 9d5f0cd to 61610de Compare February 25, 2026 12:14
… pattern

Implement connection-level progress reporting as a PEP 249 vendor extension:

- ProgressInfo NamedTuple and ProgressHandler type alias in connection.py
- set_progress_handler(handler) method on Connection
- Automatically sends enable_progress_events: true when handler is set
- Handles execution_progress WebSocket events independently of the
  query state machine, with exception isolation
- Export ProgressInfo from wherobots.db
- Add --progress flag to tests/smoke.py for manual testing with rich output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants