Skip to content

Provision Query API endpoint lazily instead of at service create#243

Merged
sdairs merged 2 commits into
mainfrom
issue-242-qe-provision-wait
Jun 9, 2026
Merged

Provision Query API endpoint lazily instead of at service create#243
sdairs merged 2 commits into
mainfrom
issue-242-qe-provision-wait

Conversation

@sdairs

@sdairs sdairs commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Fixes #242

Problem

chctl cloud service create --name test hung for a long time and then printed:

warning: failed to auto-provision Query API endpoint: Internal error. Run `clickhousectl cloud service query --id 6fa....` later to retry.

The control plane returns 500 "Internal error" on the query endpoint upsert while the service is still in provisioning state — which a freshly created service always is. By the time the user ran cloud service query, the service was running, so the lazy provisioning path succeeded.

Fix

Drop the create-time provisioning hook entirely and rely on lazy provisioning at first cloud service query:

  • The lazy path already worked (it's how the issue reporter recovered), and it was already the only path for --json/agent-detected output and for pre-existing services — so this makes human-mode service create consistent with everything else instead of adding wait/progress/Ctrl+C machinery around a multi-minute block.
  • service create now returns as soon as the API call completes and prints a cloud service query example plus a note that the endpoint is provisioned automatically on first use.
  • The --no-enable-query flag on service create is removed since there is no create-time hook left to skip. cloud service query --no-auto-enable remains the opt-out for the lazy path.
  • Kept from the earlier revision: ensure_service_query_setup no longer leaks the dedicated API key when the endpoint binding fails — the just-created key is deleted (best-effort) before the error propagates, so failed attempts no longer orphan one key each in the org.

Testing

  • cargo test -p clickhousectl: 358 passed. cargo clippy --all-targets: clean.
  • README and service query agent help text updated to describe lazy-only provisioning.

🤖 Generated with Claude Code

The query endpoint upsert returns 500 "Internal error" while a service
is still provisioning, so the create-time auto-provision hook always
failed and told the user to retry later (#242). `service create` now
polls the service state (every 5s, up to 10 minutes) and only enables
the endpoint once the service is ready, with state transitions printed
to stderr instead of a silent hang.

Also stop leaking the dedicated API key when the endpoint binding
fails: it is deleted (best-effort) so each retry no longer leaves an
orphaned key in the org.

Fixes #242

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sdairs sdairs requested a review from iskakaushik as a code owner June 9, 2026 19:56
@sdairs sdairs temporarily deployed to cloud-integration June 9, 2026 19:57 — with GitHub Actions Inactive
A freshly created service is still provisioning, so the create-time
endpoint upsert either blocked for minutes or failed with 500. Rather
than waiting in `service create`, drop the create-time hook entirely:
the endpoint is provisioned on first `cloud service query`, which was
already the behavior for --json/agent output and for pre-existing
services. `service create` now returns immediately and prints a hint
that the endpoint is provisioned on first use.

The now-meaningless `--no-enable-query` flag is removed
(`service query --no-auto-enable` still opts out of the lazy path).
The orphaned-key cleanup in ensure_service_query_setup stays.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sdairs sdairs changed the title Wait for service readiness before auto-provisioning Query API endpoint Provision Query API endpoint lazily instead of at service create Jun 9, 2026
@sdairs sdairs temporarily deployed to cloud-integration June 9, 2026 20:26 — with GitHub Actions Inactive
@sdairs sdairs merged commit ca14cf4 into main Jun 9, 2026
12 checks passed
@sdairs sdairs deleted the issue-242-qe-provision-wait branch June 9, 2026 21:32
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.

[bug]: failed to auto-provision Query API endpoint

2 participants