Skip to content

fix(cli): treat tab-close after successful create as completion#617

Merged
kaiweijw merged 2 commits intomainfrom
fix/wizard-tab-close-race
May 4, 2026
Merged

fix(cli): treat tab-close after successful create as completion#617
kaiweijw merged 2 commits intomainfrom
fix/wizard-tab-close-race

Conversation

@kaiweijw
Copy link
Copy Markdown
Collaborator

@kaiweijw kaiweijw commented May 4, 2026

Summary

The Mode A wizard's heartbeat watchdog detects a closed browser tab ~3.6s after it disappears and emits WizardOutcome::Cancelled. But if the user clicked Create service right before closing — backend already committed an active service — the resulting "✗ Wizard cancelled. No service was created." message is misleading and prompts users to re-run, creating duplicates.

This PR captures successful AiKey create responses inside the existing proxy sniff and treats them as the implicit completion ack when the soft-failure outcomes (heartbeat watchdog, max-duration timeout) fire.

closes #601

What changed

  • New KeysResponseSignal enum + pure classify_keys_response helper extracted from the inline sniff at handle_proxy. Same lifecycle behavior for pending_auth placeholders; new ActiveCreated signal captures successful creates.
  • New ServerState.completed_ai_key: Mutex<Option<Value>> snapshots the response body when the active-create signal fires AND the flow is FlowKind::AiKey. Display-once flows (api-key-create, rotate, node-register) still require the explicit /api/proxy/complete ack so secrets don't get accidentally surfaced.
  • Watchdog and timeout branches in the outcome select prefer the captured success and emit WizardOutcome::AiKeyCompleted(value); the printed message is updated to reflect what happened.
  • Ctrl+C and explicit cancel button preserved as hard cancel — those are unambiguous user gestures.

Test plan

  • cargo test -p nyxid-cli classify_keys_response (7 new classifier tests)
  • cargo test -p nyxid-cli (288 unit + freshness)
  • Manual: NYXID_WIZARD_NO_OPEN=1 nyxid service add llm-openai --label "QA tab close test", open wizard URL, paste API key, click Create service, immediately close the tab. Confirm CLI prints "Browser stopped responding (tab closed?) — using last successful create as completion." and shows the wizard summary instead of "No service was created".
  • Regression: explicit Cancel button still terminates with WizardOutcome::Cancelled.
  • Regression: Ctrl+C during a successful create still terminates with WizardOutcome::Cancelled (the user's gesture is honored).

@kaiweijw kaiweijw merged commit d599eb4 into main May 4, 2026
10 checks passed
@kaiweijw kaiweijw deleted the fix/wizard-tab-close-race branch May 4, 2026 08:39
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] [CLI Wizard] Closing the Wizard tab right after Create makes CLI say nothing was created, but backend creates an active service

1 participant