From edfeb27f7696c504895057ef5b665aae9e64c61a Mon Sep 17 00:00:00 2001 From: Will Wiriawan Date: Tue, 1 Sep 2026 12:38:44 +0700 Subject: [PATCH] fix(broker): restart broker after migrate-auth so migrated tokens load The running broker holds its auth store in memory; tokens merged by migrate-auth were invisible until the next natural restart. When the broker is running, the command now restarts it and reports the reload. docs/migration.md notes the behavior. --- docs/migration.md | 2 +- src/cli/index.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/migration.md b/docs/migration.md index d944b88..a7463b0 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -26,7 +26,7 @@ where the principal is the C2C installation (`c2c_inst_…`). To upgrade without deleting legacy files: ```bash -c2c broker migrate-auth +c2c broker migrate-auth — merges legacy per-workspace tokens into the installation store; restarts the broker when running so migrated tokens are recognized immediately. ``` This copies live client registrations and unexpired tokens into the diff --git a/src/cli/index.ts b/src/cli/index.ts index 940cbb2..2ba9a3c 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1451,6 +1451,16 @@ brokerCmd `Migrated ${result.tokensMigrated} token(s) from ${result.sourceFiles.length} legacy file(s) to ${result.installationId}` ); say("Legacy auth files were kept for rollback."); + // The running broker holds auth in memory: restart so migrated tokens + // are recognized without waiting for the next natural restart. + const { stopBroker, ensureBroker } = await import("../broker/daemon.js"); + const wasRunning = (await import("../broker/daemon.js")).installationRuntime(); + if (wasRunning) { + await stopBroker(); + await new Promise((resolve) => setTimeout(resolve, 500)); + await ensureBroker(); + check("Broker restarted to load the migrated tokens"); + } } catch (error) { handleCliError(error, opts.json); }