Skip to content

Conversation

@lovincyrus
Copy link
Contributor

@lovincyrus lovincyrus commented Dec 19, 2025

This PR fixes MotherDuck connector creation from the welcome screen by writing .env first. In submitAddDataForm.ts, the .env secrets are now written (and reconciled) before the connector file is created, ensuring the MotherDuck token exists before the connector’s first reconciliation. This prevents the “map has no entry for key connector” error that was causing the rollback/deletion of the connector file in the uninitialized/welcome flow.

Closes https://linear.app/rilldata/issue/APP-660/bugs-with-clickhouse-and-motherduck-connector-experiences

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@lovincyrus lovincyrus self-assigned this Dec 19, 2025
@lovincyrus lovincyrus marked this pull request as ready for review December 19, 2025 06:55
@royendo
Copy link
Contributor

royendo commented Dec 19, 2025

@ericokuma can you do PROD check here, since you know exact steps to replciate

Copy link
Contributor

@ericokuma ericokuma left a comment

Choose a reason for hiding this comment

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

@ericokuma
Copy link
Contributor

Let's try to cherry pick this into 0.78 if possible

@ericokuma
Copy link
Contributor

FWIW, I see this error message in my terminal when connecting to MotherDuck:

2025-12-19T10:45:01.707 ERROR failed to migrate db {"error": "database/sql/driver: could not connect to database: Connection Error: Can't open a connection to same database file with a different configuration than existing connections"}

@ericpgreen2
Copy link
Contributor

A few observations while reviewing this change:

Rollback coverage for connector file creation failure

If runtimeServicePutFile for the connector (lines 396-407) throws an error after .env has already been written and reconciled, the .env changes won't be rolled back. The current catch block (lines 466-472) only handles abort signals. This could leave orphaned secrets in .env if the connector file creation fails for other reasons (e.g., network error, permission issue).

A single try-catch covering both the .env write and connector file creation, with rollback logic in one place, would handle this more cleanly.

Inconsistent ordering between "Test and Connect" and "Save Anyway"

This PR fixes the ordering for "Test and Connect" (.env first, then connector), but saveConnectorAnyway still writes the connector file before .env. I understand "Save Anyway" bypasses reconciliation so the order doesn't matter today, but having consistent ordering across both paths would be easier to reason about. Not suggesting we expand scope here, but worth considering as a follow-up.

Test coverage

The checklist indicates this isn't covered by tests. Given the subtle ordering requirements here (secrets must exist before connector reconciliation), an integration test that exercises the welcome flow for MotherDuck would help prevent regressions.


Developed in collaboration with Claude Code

@lovincyrus
Copy link
Contributor Author

A few observations while reviewing this change:

Rollback coverage for connector file creation failure

If runtimeServicePutFile for the connector (lines 396-407) throws an error after .env has already been written and reconciled, the .env changes won't be rolled back. The current catch block (lines 466-472) only handles abort signals. This could leave orphaned secrets in .env if the connector file creation fails for other reasons (e.g., network error, permission issue).

A single try-catch covering both the .env write and connector file creation, with rollback logic in one place, would handle this more cleanly.

Inconsistent ordering between "Test and Connect" and "Save Anyway"

This PR fixes the ordering for "Test and Connect" (.env first, then connector), but saveConnectorAnyway still writes the connector file before .env. I understand "Save Anyway" bypasses reconciliation so the order doesn't matter today, but having consistent ordering across both paths would be easier to reason about. Not suggesting we expand scope here, but worth considering as a follow-up.

Test coverage

The checklist indicates this isn't covered by tests. Given the subtle ordering requirements here (secrets must exist before connector reconciliation), an integration test that exercises the welcome flow for MotherDuck would help prevent regressions.

Developed in collaboration with Claude Code

Addressed them!

@lovincyrus lovincyrus force-pushed the cyrus/motherduck-empty-proj-connector-yaml branch from 7cb1cbd to 4b89db3 Compare December 22, 2025 08:57
@lovincyrus lovincyrus merged commit d6a1e97 into main Dec 23, 2025
12 checks passed
@lovincyrus lovincyrus deleted the cyrus/motherduck-empty-proj-connector-yaml branch December 23, 2025 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants