Fix MotherDuck hanging on concurrent scripts, bump to 0.18.0#184
Merged
MaxHalford merged 3 commits intomainfrom Apr 14, 2026
Merged
Fix MotherDuck hanging on concurrent scripts, bump to 0.18.0#184MaxHalford merged 3 commits intomainfrom
MaxHalford merged 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="examples/motherduck/README.md">
<violation number="1" location="examples/motherduck/README.md:17">
P2: Initialize the `jaffle_shop` submodule before symlinking it; otherwise this example fails on a normal clone because the CSV seeds are missing.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Conductor as Conductor (Orchestrator)
participant MDClient as MotherDuckClient
participant DuckDB as duckdb (Module/Instance)
participant Cursor as Job Cursor
participant Cloud as MotherDuck Service
Note over Conductor,Cloud: Session Initialization
Conductor->>MDClient: NEW: Instantiate Client
MDClient->>DuckDB: NEW: connect() (Persistent Connection)
DuckDB-->>MDClient: _conn
Conductor->>MDClient: prepare_session(write_dataset)
MDClient->>DuckDB: execute("CREATE DATABASE...")
MDClient->>DuckDB: execute("USE <dataset>")
Conductor->>MDClient: NEW: set_active_database(write_dataset)
Note right of MDClient: Stores active DB name for future cursors
Note over Conductor,Cloud: Concurrent Execution (ThreadPoolExecutor)
rect rgb(240, 240, 240)
Note over Conductor,Cursor: Parallel Task (for each SQL script)
Conductor->>MDClient: make_job_config(script)
MDClient->>DuckDB: NEW: _conn.cursor()
DuckDB-->>MDClient: cursor
opt _active_database is set
MDClient->>Cursor: NEW: execute("USE <active_db>")
end
MDClient-->>Conductor: DuckDBJob (includes cursor)
Conductor->>Cursor: execute(script.query)
Cursor->>Cloud: Remote SQL execution
Cloud-->>Cursor: Results
Cursor-->>Conductor: Job Complete
end
Note over Conductor,Cloud: CHANGED: Using per-job cursors prevents thread-safety hangs<br/>previously caused by shared module-level connection.
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
MotherDuckClient used the module-level duckdb connection which isn't thread-safe. Give it a persistent connection with per-job cursors, matching the DuckLakeClient pattern. Also bump sqlglot to >=30.2 and update the motherduck example. Closes #55 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
89bb926 to
64c3fcc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MotherDuckClientused the module-levelduckdbconnection which isn't thread-safe when multiple scripts execute concurrently viaThreadPoolExecutor. Now uses a persistent connection with per-job cursors, matching theDuckLakeClientpattern.LEA_WAREHOUSE=motherduckconfig (was using the old brokenLEA_WAREHOUSE=duckdbapproach)Closes #55
Test plan
🤖 Generated with Claude Code
Summary by cubic
Fixes MotherDuck hangs with concurrent scripts by giving
MotherDuckClienta persistent DuckDB connection and per-job cursors. Releases v0.18.0, upgradessqlglotto >=30.2, and unifies DuckLake secret env vars into a singleLEA_DUCKLAKE_SECRET(breaking).Bug Fixes
MotherDuckClientthread-safe with a persistent connection and per-job cursors.LEA_WAREHOUSE=motherduck,LEA_MOTHERDUCK_DATABASE, and run with--scripts.Migration
LEA_DUCKLAKE_*) withLEA_DUCKLAKE_SECRET; for quack useLEA_QUACK_DUCKLAKE_SECRET.Written for commit 64c3fcc. Summary will update on new commits.