fix: add gateway connection debug output

This commit is contained in:
Peter Steinberger
2026-01-08 02:51:28 +01:00
parent 1ebde4dc24
commit 6aa6c837e7
8 changed files with 133 additions and 44 deletions

View File

@@ -10,6 +10,7 @@ import {
} from "../config/config.js";
import { GATEWAY_LAUNCH_AGENT_LABEL } from "../daemon/constants.js";
import { resolveGatewayService } from "../daemon/service.js";
import { buildGatewayConnectionDetails } from "../gateway/call.js";
import { formatPortDiagnostics, inspectPortUsage } from "../infra/ports.js";
import type { RuntimeEnv } from "../runtime.js";
import { defaultRuntime } from "../runtime.js";
@@ -111,6 +112,10 @@ export async function doctorCommand(
}
cfg = await maybeRepairAnthropicOAuthProfileId(cfg, prompter);
const gatewayDetails = buildGatewayConnectionDetails({ config: cfg });
if (gatewayDetails.remoteFallbackNote) {
note(gatewayDetails.remoteFallbackNote, "Gateway");
}
const legacyState = await detectLegacyStateMigrations({ cfg });
if (legacyState.preview.length > 0) {
@@ -204,6 +209,7 @@ export async function doctorCommand(
const message = String(err);
if (message.includes("gateway closed")) {
note("Gateway not running.", "Gateway");
note(gatewayDetails.message, "Gateway connection");
} else {
runtime.error(`Health check failed: ${message}`);
}
@@ -255,6 +261,7 @@ export async function doctorCommand(
const message = String(err);
if (message.includes("gateway closed")) {
note("Gateway not running.", "Gateway");
note(gatewayDetails.message, "Gateway connection");
} else {
runtime.error(`Health check failed: ${message}`);
}

View File

@@ -1,7 +1,7 @@
import { loadConfig } from "../config/config.js";
import { loadSessionStore, resolveStorePath } from "../config/sessions.js";
import { type DiscordProbe, probeDiscord } from "../discord/probe.js";
import { callGateway } from "../gateway/call.js";
import { buildGatewayConnectionDetails, callGateway } from "../gateway/call.js";
import { info } from "../globals.js";
import type { RuntimeEnv } from "../runtime.js";
import { probeTelegram, type TelegramProbe } from "../telegram/probe.js";
@@ -110,7 +110,7 @@ export async function getHealthSnapshot(
}
export async function healthCommand(
opts: { json?: boolean; timeoutMs?: number },
opts: { json?: boolean; timeoutMs?: number; verbose?: boolean },
runtime: RuntimeEnv,
) {
// Always query the running gateway; do not open a direct Baileys socket here.
@@ -124,6 +124,13 @@ export async function healthCommand(
if (opts.json) {
runtime.log(JSON.stringify(summary, null, 2));
} else {
if (opts.verbose) {
const details = buildGatewayConnectionDetails();
runtime.log(info("Gateway connection:"));
for (const line of details.message.split("\n")) {
runtime.log(` ${line}`);
}
}
runtime.log(
summary.web.linked
? `Web: linked (auth age ${summary.web.authAgeMs ? `${Math.round(summary.web.authAgeMs / 60000)}m` : "unknown"})`

View File

@@ -11,7 +11,7 @@ import {
resolveStorePath,
type SessionEntry,
} from "../config/sessions.js";
import { callGateway } from "../gateway/call.js";
import { buildGatewayConnectionDetails, callGateway } from "../gateway/call.js";
import { info } from "../globals.js";
import { buildProviderSummary } from "../infra/provider-summary.js";
import {
@@ -222,7 +222,13 @@ const buildFlags = (entry: SessionEntry): string[] => {
};
export async function statusCommand(
opts: { json?: boolean; deep?: boolean; usage?: boolean; timeoutMs?: number },
opts: {
json?: boolean;
deep?: boolean;
usage?: boolean;
timeoutMs?: number;
verbose?: boolean;
},
runtime: RuntimeEnv,
) {
const summary = await getStatusSummary();
@@ -247,6 +253,14 @@ export async function statusCommand(
return;
}
if (opts.verbose) {
const details = buildGatewayConnectionDetails();
runtime.log(info("Gateway connection:"));
for (const line of details.message.split("\n")) {
runtime.log(` ${line}`);
}
}
runtime.log(
`Web session: ${summary.web.linked ? "linked" : "not linked"}${summary.web.linked ? ` (last refreshed ${formatAge(summary.web.authAgeMs)})` : ""}`,
);