Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

chore(remote-desktop): add disconnect and heartbeat diagnostics

Dash6c516e5399f2
diff --git a/apps/desktop/src/main/device-link/dispatch.ts b/apps/desktop/src/main/device-link/dispatch.ts
index a8741d94ba..db76d308ef 100644
--- a/apps/desktop/src/main/device-link/dispatch.ts
+++ b/apps/desktop/src/main/device-link/dispatch.ts
@@ -2379,7 +2379,11 @@ export function dropAllControllers(
): void {
stopFilePeers();
remoteAgentHandler?.abortAll();
- remoteDesktop.stop();
+ remoteDesktop.stop(
+ undefined,
+ undefined,
+ reason === 'user' ? 'user-stop' : reason === 'shutdown' ? 'shutdown' : 'disabled',
+ );
void remoteCredentialHost.closeAll().catch(() => remoteCredentialHost.dispose());
const controllerIds = new Set([
...subscriptions.getControllerIds(),
@@ -2442,7 +2446,7 @@ function deactivateControllerState(
changed = acceptedLinkControllers.delete(deviceId) || changed;
stopFilePeers(deviceId);
if (transientSignalingLoss) remoteDesktop.signalingLost(deviceId);
- else remoteDesktop.stop(deviceId);
+ else remoteDesktop.stop(deviceId, undefined, 'peer-closed');
void remoteCredentialHost.close(deviceId).catch(() => remoteCredentialHost.dispose());
changed = controllerConnectionEpochByDevice.delete(deviceId) || changed;
changed = controllerLinkGenerationByDevice.delete(deviceId) || changed;
@@ -2528,7 +2532,7 @@ export function forgetControllerInvokeState(deviceId: string): void {
/** 显式撤销时清理短时离线队列与 remembered topic,避免恢复后重放撤权期间数据。 */
export function purgeRevokedController(deviceId: string): void {
stopFilePeers(deviceId);
- remoteDesktop.stop(deviceId);
+ remoteDesktop.stop(deviceId, undefined, 'authorization-lost');
const changed = deactivateControllerState(deviceId);
topicSubscriptionControllers.delete(deviceId);
offlinePushQueue.clear(deviceId);
@@ -2579,7 +2583,7 @@ async function handleFrame(client: DeviceLinkClient, env: Envelope): Promise<voi
clearRemoteInvokeStateFor(src);
stopFilePeers(src);
invalidatePluginOauth(src);
- remoteDesktop.stop(src);
+ remoteDesktop.stop(src, undefined, 'peer-closed');
void remoteCredentialHost.close(src).catch(() => remoteCredentialHost.dispose());
offlinePushQueue.clear(src);
const deactivated = deactivateControllerState(src);
diff --git a/apps/desktop/src/main/remote-desktop-viewer/__tests__/windows.test.ts b/apps/desktop/src/main/remote-desktop-viewer/__tests__/windows.test.ts
index 25ea9c9bd2..8c29a5fd5c 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/__tests__/windows.test.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/__tests__/windows.test.ts
@@ -5,6 +5,7 @@ const fixture = vi.hoisted(() => ({
handlers: new Map<string, Function>(),
calls: [] as any[],
owner: 'a:1',
+ debug: vi.fn(),
}));
vi.mock('electron', () => ({
BrowserWindow: { fromWebContents: () => null },
@@ -13,7 +14,7 @@ vi.mock('electron', () => ({
ipcMain: { handle: (name: string, fn: Function) => fixture.handlers.set(name, fn) },
}));
vi.mock('../../logger', () => ({
- createLogger: () => ({ warn: vi.fn(), error: vi.fn(), info: vi.fn() }),
+ createLogger: () => ({ warn: vi.fn(), error: vi.fn(), info: vi.fn(), debug: fixture.debug }),
}));
vi.mock('../../appSessionState', () => ({
activeOwnerScopeKey: () => fixture.owner,
@@ -42,6 +43,8 @@ vi.mock('../preferences', () => ({
vi.mock('../../i18n', () => ({ t: (s: string) => s }));
vi.mock('../../device-link/index', () => ({
getSelfDeviceId: () => 'local',
+ getDeviceLinkStatus: () => 'online',
+ getUnresponsiveDeviceIds: () => ['a'],
remoteInvoke: vi.fn(async (...args: any[]) => {
args[3]?.preSend?.();
fixture.calls.push(args);
@@ -116,10 +119,38 @@ afterEach(() => {
fixture.calls = [];
fixture.handlers.clear();
fixture.owner = 'a:1';
+ fixture.debug.mockClear();
});
const event = (win: any) => ({ sender: win.webContents, senderFrame: win.webContents.mainFrame });
const call = (channel: string, win: any, ...args: unknown[]) =>
fixture.handlers.get(channel)!(event(win), ...args);
+it('records signaling and peer state on a failed request without leaking its payload', async () => {
+ const sender: any = { id: 100 };
+ manager = new RemoteDesktopViewerWindows((value) => value === sender);
+ manager.register();
+ manager.open(sender, { deviceId: 'a', name: 'private computer' });
+ const win = fixture.windows[0];
+ call(REMOTE_VIEWER.READY, win);
+ call(REMOTE_VIEWER.PRESENTED, win);
+ const { generation } = call(REMOTE_VIEWER.STATE, win);
+ await call(REMOTE_VIEWER.REQUEST, win, generation, { op: 'start', displayId: 'screen' });
+ vi.mocked(remoteInvoke).mockRejectedValueOnce(new Error('DESKTOP_LEASE_EXPIRED'));
+ await expect(
+ call(REMOTE_VIEWER.REQUEST, win, generation, { op: 'heartbeat', lease: 'lease-a' }),
+ ).rejects.toThrow('DESKTOP_LEASE_EXPIRED');
+ expect(fixture.debug).toHaveBeenCalledWith(
+ 'desktop request failed',
+ expect.objectContaining({
+ operation: 'heartbeat',
+ code: 'DESKTOP_LEASE_EXPIRED',
+ signaling: 'online',
+ peerUnresponsive: true,
+ }),
+ );
+ expect(JSON.stringify(fixture.debug.mock.calls)).not.toContain('lease-a');
+ expect(JSON.stringify(fixture.debug.mock.calls)).not.toContain('private computer');
+});
+
it.each(['resolve', 'reject'])(
'closes immediately while stop is pending and ignores its late %s',
async (outcome) => {
diff --git a/apps/desktop/src/main/remote-desktop-viewer/windows.ts b/apps/desktop/src/main/remote-desktop-viewer/windows.ts
index 85c1fc106a..cae6e2313c 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/windows.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/windows.ts
@@ -6,11 +6,23 @@ import {
type IpcMainInvokeEvent,
type WebContents,
} from 'electron';
-import { REMOTE_DESKTOP_CHANNEL, DeviceLinkError, parseClipboardContent } from '@cindy/device-link';
+import {
+ REMOTE_DESKTOP_CHANNEL,
+ DeviceLinkError,
+ parseClipboardContent,
+ parseRemoteDesktopRequest,
+} from '@cindy/device-link';
+import { createHash } from 'node:crypto';
+import { desktopDiagnosticCode } from '../../shared/remoteDesktopDiagnostics';
import { REMOTE_VIEWER, type RemoteViewerTarget } from '../../shared/remoteDesktopViewer.js';
import { activeOwnerScopeKey, isAppSessionBoundaryPending } from '../appSessionState.js';
import { getAppCapabilities } from '../appCapabilities.js';
-import { getSelfDeviceId, remoteInvoke } from '../device-link/index.js';
+import {
+ getSelfDeviceId,
+ remoteInvoke,
+ getDeviceLinkStatus,
+ getUnresponsiveDeviceIds,
+} from '../device-link/index.js';
import { loadDesktopIceServers } from '../remote-desktop/iceConfig.js';
import {
assertTrustedAppRendererEvent,
@@ -39,6 +51,7 @@ async function requestRemote<T>(device: string, request: unknown, check: () => v
check();
if (!getAppCapabilities().canUseDeviceLink || isAppSessionBoundaryPending())
throw new Error('DESKTOP_STOPPED');
+ const startedAt = Date.now();
try {
const result = await remoteInvoke(device, REMOTE_DESKTOP_CHANNEL, [request], {
preSend: () => {
@@ -51,6 +64,27 @@ async function requestRemote<T>(device: string, request: unknown, check: () => v
throw new Error(result.error.code === 'IPC_ERROR' ? result.error.message : result.error.code);
return result.result as T;
} catch (error) {
+ try {
+ const parsed = parseRemoteDesktopRequest(request);
+ const lease = 'lease' in parsed ? parsed.lease : null;
+ log.debug('desktop request failed', {
+ at: Date.now(),
+ startedAt,
+ elapsedMs: Date.now() - startedAt,
+ operation: parsed.op,
+ session: lease ? createHash('sha256').update(lease).digest('hex').slice(0, 16) : null,
+ code: desktopDiagnosticCode(
+ error instanceof DeviceLinkError
+ ? error.code
+ : (extractIpcError(error)?.message ?? error),
+ ),
+ signaling: getDeviceLinkStatus(),
+ peerUnresponsive: getUnresponsiveDeviceIds().includes(device),
+ inFlight: error instanceof DeviceLinkError ? (error.inFlight ?? null) : null,
+ });
+ } catch {
+ /* Diagnostics must preserve the original request failure. */
+ }
if (error instanceof DeviceLinkError) throw new Error(error.code);
const parsed = extractIpcError(error);
if (parsed?.code === 'DEVICE_LINK_CONTROL_DISABLED') throw new Error('REMOTE_DISABLED');
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts
index 3117e33781..a3ad38b022 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/controller.test.ts
@@ -3,6 +3,12 @@ import { readFileSync } from 'node:fs';
import { RemoteDesktopController, type DesktopControllerDeps } from '../controller';
import { enumerateDesktopSources } from '../captureSource';
import type { RemoteDesktopIceReply, RemoteDesktopLease } from '@cindy/device-link';
+import { createHash } from 'node:crypto';
+
+const diagnosticLog = vi.hoisted(() => vi.fn());
+vi.mock('../../logger', () => ({
+ createLogger: () => ({ debug: diagnosticLog, warn: vi.fn() }),
+}));
function harness() {
let now = 1000;
@@ -39,6 +45,94 @@ function harness() {
controller.request('phone', { op: 'start', displayId: '1' }) as Promise<RemoteDesktopLease>,
};
}
+it('records bounded received heartbeats and the unchanged expiration deadline without lease secrets', async () => {
+ diagnosticLog.mockClear();
+ const h = harness();
+ const { lease } = await h.start();
+ for (let i = 0; i < 10; i++) {
+ h.advance(3000);
+ await h.controller.request('phone', { op: 'heartbeat', lease });
+ }
+ expect(diagnosticLog).not.toHaveBeenCalled();
+ h.advance(11999);
+ expect(h.controller.state).not.toBeNull();
+ h.advance(1);
+ expect(h.controller.state).toBeNull();
+ expect(diagnosticLog).toHaveBeenCalledOnce();
+ const data = diagnosticLog.mock.calls[0][1];
+ expect(data).toMatchObject({
+ reason: 'heartbeat-expired',
+ at: 43000,
+ ageMs: 42000,
+ lastHeartbeatAgeMs: 12000,
+ expiresInMs: 0,
+ session: createHash('sha256').update(lease).digest('hex').slice(0, 16),
+ });
+ expect(data.heartbeats).toHaveLength(8);
+ expect(data.heartbeats[0]).toEqual({ receivedAt: 10000, result: 'relay-accepted' });
+ expect(JSON.stringify(data)).not.toContain(lease);
+ expect(JSON.stringify(data)).not.toContain('phone');
+});
+
+it.each([
+ 'peer-offline',
+ 'signaling-lost',
+ 'authorization-lost',
+ 'authentication-changed',
+ 'remote-stop',
+ 'resume-replaced',
+ 'takeover',
+] as const)('identifies %s at the existing stop boundary', async (reason) => {
+ diagnosticLog.mockClear();
+ const h = harness();
+ let authentication = 'original';
+ h.deps.authenticationSession = () => authentication;
+ const { lease } = await h.start();
+ h.controller.signalingLost('unrelated');
+ expect(diagnosticLog).not.toHaveBeenCalled();
+ if (reason === 'peer-offline') h.controller.signalingLost('phone');
+ else if (reason === 'signaling-lost') h.controller.signalingLost();
+ else if (reason === 'authorization-lost') {
+ h.revoke();
+ h.controller.tick();
+ } else if (reason === 'authentication-changed') {
+ authentication = 'replacement';
+ h.controller.tick();
+ } else if (reason === 'remote-stop') await h.controller.request('phone', { op: 'stop', lease });
+ else
+ await h.controller.request(reason === 'takeover' ? 'other' : 'phone', {
+ op: 'start',
+ displayId: '1',
+ ...(reason === 'takeover' ? { takeover: true } : { resume: true }),
+ });
+ expect(diagnosticLog).toHaveBeenCalledOnce();
+ expect(diagnosticLog.mock.calls[0][1].reason).toBe(reason);
+});
+
+it('keeps the original stop reason through lock completion and tolerates a failed logger', async () => {
+ diagnosticLog.mockClear();
+ const h = harness();
+ let finish!: () => void;
+ h.deps.lockScreen = () =>
+ new Promise<void>((resolve) => {
+ finish = resolve;
+ });
+ const { lease } = await h.start();
+ await h.controller.request('phone', { op: 'heartbeat', lease, lockOnExit: true });
+ diagnosticLog.mockImplementationOnce(() => {
+ throw new Error('logger unavailable');
+ });
+ const stopped = h.controller.stop(undefined, undefined, 'capture-exited');
+ await Promise.resolve();
+ h.controller.signalingLost();
+ finish();
+ await stopped;
+ expect(h.controller.state).toBeNull();
+ expect(diagnosticLog).toHaveBeenCalledOnce();
+ expect(diagnosticLog.mock.calls[0][1].reason).toBe('capture-exited');
+ expect(h.deps.stopVideo).toHaveBeenCalled();
+});
+
it('finishes native host setup before exposing a lease or allocating temporary displays', async () => {
const h = harness();
let done!: () => void;
diff --git a/apps/desktop/src/main/remote-desktop/controller.ts b/apps/desktop/src/main/remote-desktop/controller.ts
index 8e0b81f4b7..3786a6f2f9 100644
--- a/apps/desktop/src/main/remote-desktop/controller.ts
+++ b/apps/desktop/src/main/remote-desktop/controller.ts
@@ -1,6 +1,7 @@
import { ClipboardTransfer } from './clipboardTransfer';
-import { randomUUID } from 'node:crypto';
+import { createHash, randomUUID } from 'node:crypto';
import { createLogger } from '../logger';
+import { DesktopHeartbeatHistory } from '../../shared/remoteDesktopDiagnostics';
import type { ViewerDisplayHandle } from './viewerDisplay';
import {
parseRemoteDesktopRequest,
@@ -23,6 +24,27 @@ import {
const log = createLogger('remote-desktop:controller');
+export type DesktopStopReason =
+ | 'host-stop'
+ | 'authorization-lost'
+ | 'authentication-changed'
+ | 'handoff-ended'
+ | 'heartbeat-expired'
+ | 'peer-offline'
+ | 'signaling-lost'
+ | 'peer-closed'
+ | 'capture-exited'
+ | 'capture-stop'
+ | 'user-stop'
+ | 'remote-stop'
+ | 'takeover'
+ | 'resume-replaced'
+ | 'shutdown'
+ | 'disabled'
+ | 'display-changed'
+ | 'display-failed'
+ | 'input-failed';
+
/** The one window a 代输入 live view shows; resolved by the host, never by a viewer. */
export interface DesktopHandoffWindow {
requestId: string;
@@ -162,6 +184,12 @@ export class RemoteDesktopController {
peer: string;
readonly sourceDisplayId: string;
expires: number;
+ diagnostics: {
+ id: string;
+ startedAt: number;
+ heartbeats: DesktopHeartbeatHistory;
+ stopReason?: DesktopStopReason;
+ };
sequence: number;
authenticationSession: string | undefined;
backgroundViewing?: boolean;
@@ -256,7 +284,8 @@ export class RemoteDesktopController {
/** The 代输入 request finished: its live view has nothing left to show. */
endHandoff(requestId: string): void {
const active = this.active;
- if (active?.handoff?.requestId === requestId) void this.stop(active.peer, false);
+ if (active?.handoff?.requestId === requestId)
+ void this.stop(active.peer, false, 'handoff-ended');
}
isBackgroundViewing(lease: string): boolean {
return this.active?.lease === lease && this.active.backgroundViewing === true;
@@ -293,17 +322,17 @@ export class RemoteDesktopController {
tick(): void {
const active = this.active;
if (!active) return;
- if (
- !this.deps.authorized(active.peer) ||
- !this.authenticationCurrent(active.peer, active.authenticationSession)
- ) {
+ if (!this.deps.authorized(active.peer)) {
this.lockAbort?.abort();
- void this.stop(undefined, false);
+ void this.stop(undefined, false, 'authorization-lost');
+ } else if (!this.authenticationCurrent(active.peer, active.authenticationSession)) {
+ this.lockAbort?.abort();
+ void this.stop(undefined, false, 'authentication-changed');
} else if (active.handoff && this.deps.handoffCurrent?.(active.handoff.requestId) === false) {
// The 代输入 request finished: nothing is left to show.
- void this.stop(undefined, false);
+ void this.stop(undefined, false, 'handoff-ended');
} else if (!this.locking && active.expires <= this.now()) {
- void this.stop();
+ void this.stop(undefined, undefined, 'heartbeat-expired');
}
}
/** Losing the signaling socket is expected while the phone shows PiP.
@@ -319,9 +348,13 @@ export class RemoteDesktopController {
!active.controlling
)
return;
- this.stop(peer);
+ this.stop(peer, undefined, peer ? 'peer-offline' : 'signaling-lost');
}
- stop(peer?: string, lockScreen = this.exitLockEnabled()): Promise<void> {
+ stop(
+ peer?: string,
+ lockScreen = this.exitLockEnabled(),
+ reason: DesktopStopReason = 'host-stop',
+ ): Promise<void> {
if (peer && this.active?.peer !== peer) {
// Cancelling a takeover candidate must not revoke the current owner's work.
if (this.startingPeer === peer) this.startingPeer = null;
@@ -329,6 +362,29 @@ export class RemoteDesktopController {
}
if (this.stopping) return this.stopping;
const active = this.active;
+ if (active && !active.diagnostics.stopReason) {
+ active.diagnostics.stopReason = reason;
+ const at = this.now();
+ const heartbeats = active.diagnostics.heartbeats.snapshot();
+ try {
+ log.debug('lease stopping', {
+ at,
+ session: active.diagnostics.id,
+ reason,
+ lockScreen,
+ controlling: active.controlling,
+ backgroundViewing: active.backgroundViewing === true,
+ ageMs: at - active.diagnostics.startedAt,
+ expiresInMs: active.expires - at,
+ lastHeartbeatAgeMs: heartbeats.length
+ ? at - heartbeats[heartbeats.length - 1].receivedAt!
+ : null,
+ heartbeats,
+ });
+ } catch {
+ /* Diagnostics must never prevent revocation or cleanup. */
+ }
+ }
if (active && lockScreen && this.deps.lockScreen) {
this.locking = true;
const cancellation = new AbortController();
@@ -353,7 +409,7 @@ export class RemoteDesktopController {
this.stopping = null;
this.lockAbort = null;
this.locking = false;
- if (this.active === active) await this.stop(active.peer, false);
+ if (this.active === active) await this.stop(active.peer, false, reason);
});
this.stopping = pending;
// Timer/disconnect callers have no reply channel; explicit callers still
@@ -471,7 +527,7 @@ export class RemoteDesktopController {
};
return control ? await this.withControl(peer, active, reply) : reply;
} catch (error) {
- if (this.active === active) this.stop(peer, false);
+ if (this.active === active) this.stop(peer, false, 'display-failed');
throw error;
} finally {
this.resolutionWrite = null;
@@ -513,7 +569,7 @@ export class RemoteDesktopController {
/** Join the same restoration used by disconnects before the process exits. */
async stopAndRestore(): Promise<void> {
try {
- await this.stop();
+ await this.stop(undefined, undefined, 'shutdown');
} finally {
// Locking retains the lease until it settles, even on failure. Only then
// can restoration start; process shutdown must also await that work.
@@ -591,7 +647,7 @@ export class RemoteDesktopController {
stopByUser(): void {
const target = this.active ?? this.lastEnded;
if (target) this.userStopped.set(target.peer, target.lease);
- this.stop();
+ this.stop(undefined, undefined, 'user-stop');
}
async stopPrivacyByUser(): Promise<void> {
const active = this.active;
@@ -606,7 +662,7 @@ export class RemoteDesktopController {
try {
await ending;
} finally {
- if (this.active === active) this.stop(active.peer);
+ if (this.active === active) this.stop(active.peer, undefined, 'user-stop');
}
}
private require(peer: string, lease: string) {
@@ -620,8 +676,10 @@ export class RemoteDesktopController {
/** Only the trusted capture renderer may forward live DataChannel pongs. */
viewHeartbeat(lease: string): void {
this.tick();
- if (this.active?.lease === lease && this.active.backgroundViewing && !this.active.controlling)
+ if (this.active?.lease === lease && this.active.backgroundViewing && !this.active.controlling) {
this.active.expires = this.now() + REMOTE_DESKTOP_LEASE_MS;
+ this.active.diagnostics.heartbeats.add({ receivedAt: this.now(), result: 'media-accepted' });
+ }
}
/** Also used by the exact capture renderer's DataChannel bridge. */
input(lease: string, sequence: number, events: unknown): void {
@@ -752,11 +810,11 @@ export class RemoteDesktopController {
if (request.resume && this.userStopped.has(peer)) throw new Error('DESKTOP_STOPPED');
if (request.takeover && this.active) {
this.userStopped.set(this.active.peer, this.active.lease);
- void this.stop(this.active.peer, false);
+ void this.stop(this.active.peer, false, 'takeover');
}
// A lost start reply can leave our own lease alive. Rotate it using the
// existing cleanup so the new viewer can restart its input sequence at 0.
- else if (resumesActive) this.stop(peer, false);
+ else if (resumesActive) this.stop(peer, false, 'resume-replaced');
if (this.viewerDisplay || this.originalResolution) {
const restorationGeneration = this.controlGeneration;
await this.restoreStoppedDisplay();
@@ -786,6 +844,11 @@ export class RemoteDesktopController {
peer,
sourceDisplayId: display.id,
expires: this.now() + REMOTE_DESKTOP_LEASE_MS,
+ diagnostics: {
+ id: createHash('sha256').update(lease.lease).digest('hex').slice(0, 16),
+ startedAt: this.now(),
+ heartbeats: new DesktopHeartbeatHistory(),
+ },
sequence: -1,
authenticationSession,
// Ending a look at one window never locks the whole computer.
@@ -922,7 +985,7 @@ export class RemoteDesktopController {
throw new Error('DESKTOP_VIEWER_DISPLAY_UNAVAILABLE');
if (!this.viewerDisplay) {
const handle = await this.deps.createViewerDisplay(active.display.id, current, () => {
- if (this.active === active) this.stop(peer);
+ if (this.active === active) this.stop(peer, undefined, 'display-failed');
});
if (!current()) {
handle.dispose();
@@ -981,7 +1044,7 @@ export class RemoteDesktopController {
// Input restarts on the new geometry within the same request.
return request.control ? await this.withControl(peer, active, reply) : reply;
} catch (error) {
- if (this.active === active) this.stop(peer, false);
+ if (this.active === active) this.stop(peer, false, 'display-failed');
throw error;
} finally {
this.resolutionWrite = null;
@@ -993,12 +1056,14 @@ export class RemoteDesktopController {
throw new Error('DESKTOP_LOCK_UNAVAILABLE');
// Plain stop is also used for viewer recovery and display handoff.
// Explicit exit sends lockScreen; involuntary host stops use the policy.
- await this.stop(peer, request.lockScreen === true && !active.handoff);
+ await this.stop(peer, request.lockScreen === true && !active.handoff, 'remote-stop');
return { ok: true };
}
case 'heartbeat':
- if (request.lockOnExit !== undefined && !active.handoff) active.lockOnExit = request.lockOnExit;
+ if (request.lockOnExit !== undefined && !active.handoff)
+ active.lockOnExit = request.lockOnExit;
active.expires = this.now() + REMOTE_DESKTOP_LEASE_MS;
+ active.diagnostics.heartbeats.add({ receivedAt: this.now(), result: 'relay-accepted' });
return { controlling: active.controlling };
case 'presentation': {
this.setBackgroundViewing(active, request.enabled);
@@ -1127,7 +1192,7 @@ export class RemoteDesktopController {
if (!current()) throw new Error('DESKTOP_LEASE_EXPIRED');
// Release old geometry before the native write can emit display events.
// Completion must not inspect or stop a replacement lease.
- this.stop(peer, false);
+ this.stop(peer, false, 'display-changed');
};
try {
if (this.viewerDisplay) {
@@ -1157,7 +1222,7 @@ export class RemoteDesktopController {
await this.deps.resolution(active.sourceDisplayId, request.modeId, beforeChange);
return { ok: true };
} catch (error) {
- if (restoringViewer && current()) this.stop(peer, false);
+ if (restoringViewer && current()) this.stop(peer, false, 'display-failed');
throw error;
}
}
diff --git a/apps/desktop/src/main/remote-desktop/index.ts b/apps/desktop/src/main/remote-desktop/index.ts
index 119d5f9fa5..64d382cd34 100644
--- a/apps/desktop/src/main/remote-desktop/index.ts
+++ b/apps/desktop/src/main/remote-desktop/index.ts
@@ -161,7 +161,9 @@ async function ensurePortalCapture(lease: string): Promise<void> {
});
return portalReady;
}
-const captureWindow = new DesktopCaptureWindow(() => remoteDesktop.stop());
+const captureWindow = new DesktopCaptureWindow(() =>
+ remoteDesktop.stop(undefined, undefined, 'capture-exited'),
+);
const nativeCapture = new NativeDesktopCapture();
const hyprlandCapture = new HyprlandCapture();
const linuxAudio = new LinuxDesktopAudio();
@@ -465,9 +467,9 @@ async function offer(
nativeOverlay =
Boolean(handoff) ||
(cursorOverlay === true &&
- (process.platform === 'darwin' ||
- (process.platform === 'win32' && nativeAvailable) ||
- (hyprland && (await readLinuxCursorSupport()))));
+ (process.platform === 'darwin' ||
+ (process.platform === 'win32' && nativeAvailable) ||
+ (hyprland && (await readLinuxCursorSupport()))));
if (!current() || host !== currentHost || currentHost.isDestroyed())
throw new Error('DESKTOP_LEASE_EXPIRED');
nativeSettings = settings;
@@ -962,7 +964,7 @@ export function registerRemoteDesktopIpc(
onQuit('remote-desktop-stop', () => {
clearInterval(timer);
permissions.dismiss();
- remoteDesktop.stop();
+ remoteDesktop.stop(undefined, undefined, 'shutdown');
});
onQuit('remote-desktop-restore', () => remoteDesktop.stopAndRestore(), 'async');
const linuxLayoutChanged = () => {
@@ -977,22 +979,25 @@ export function registerRemoteDesktopIpc(
if (generation !== offerGeneration || remoteDesktop.changingDisplay) return;
const display = linuxDisplay(monitor);
if (!remoteDesktop.displayGeometryMatches(id, display.width, display.height))
- remoteDesktop.stop();
+ remoteDesktop.stop(undefined, undefined, 'display-changed');
})
.catch(() => {
- if (generation === offerGeneration && !remoteDesktop.changingDisplay) remoteDesktop.stop();
+ if (generation === offerGeneration && !remoteDesktop.changingDisplay)
+ remoteDesktop.stop(undefined, undefined, 'display-failed');
});
};
screen.on('display-removed', (_event, display) => {
linuxLayoutChanged();
if (remoteDesktop.changingDisplay) return;
- if (String(display.id) === remoteDesktop.displayId) remoteDesktop.stop();
+ if (String(display.id) === remoteDesktop.displayId)
+ remoteDesktop.stop(undefined, undefined, 'display-changed');
});
screen.on('display-added', () => {
linuxLayoutChanged();
// A new screen invalidates mask coverage, not the selected capture geometry.
// Include masks still being prepared, before the controller reports enabled.
- if (privacyScreen.active && !remoteDesktop.changingDisplay) remoteDesktop.stop();
+ if (privacyScreen.active && !remoteDesktop.changingDisplay)
+ remoteDesktop.stop(undefined, undefined, 'display-changed');
});
screen.on('display-metrics-changed', (_event, display, metrics) => {
if (
@@ -1021,7 +1026,7 @@ export function registerRemoteDesktopIpc(
(metric) => metric === 'bounds' || metric === 'scaleFactor' || metric === 'rotation',
)
)
- remoteDesktop.stop();
+ remoteDesktop.stop(undefined, undefined, 'display-changed');
});
let sessionTransition = 0;
const sessionChanged = (unlock = false) => {
@@ -1033,7 +1038,7 @@ export function registerRemoteDesktopIpc(
try {
input.input([{ kind: 'release' }]);
} catch {
- remoteDesktop.stop();
+ remoteDesktop.stop(undefined, undefined, 'input-failed');
}
}
if (videoLease && nativeDisplay && host && !host.isDestroyed())
@@ -1149,7 +1154,7 @@ export function registerRemoteDesktopIpc(
if (event.sender !== getDeepLinkMainWindow()?.webContents || windowsSetupBusy)
throwIpcError('PERMISSION_DENIED', 'Windows desktop setup unavailable');
windowsSetupBusy = true;
- remoteDesktop.stop();
+ remoteDesktop.stop(undefined, undefined, 'disabled');
try {
await configureWindowsDesktopSupport(enabled);
} catch {
@@ -1164,7 +1169,7 @@ export function registerRemoteDesktopIpc(
if (typeof enabled !== 'boolean') throwIpcError('INVALID_PARAMS', 'Invalid desktop setting');
await writeDeviceLinkSetting('remoteDesktopEnabled', enabled);
if (!enabled) {
- remoteDesktop.stop();
+ remoteDesktop.stop(undefined, undefined, 'disabled');
permissions.dismiss();
} else {
await permissions.showIfNeeded(() => readDeviceLinkSettings().remoteDesktopEnabled);
@@ -1266,7 +1271,7 @@ export function registerRemoteDesktopIpc(
});
ipcMain.handle(DESKTOP_LOCAL.CAPTURE_STOP, (event) => {
captureWindow.assertSender(event);
- remoteDesktop.stop();
+ remoteDesktop.stop(undefined, undefined, 'capture-stop');
});
ipcMain.handle(DESKTOP_LOCAL.REPLY, (event, id: unknown, sdp: unknown) => {
captureWindow.assertSender(event);
diff --git a/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerLifecycle.test.ts b/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerLifecycle.test.ts
index e34ca34141..0cb5a432fe 100644
--- a/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerLifecycle.test.ts
+++ b/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerLifecycle.test.ts
@@ -8,6 +8,12 @@ const runtime = vi.hoisted(() => ({
post: null as ((message: Record<string, unknown>) => void) | null,
receive: vi.fn(),
}));
+const diagnosticLog = vi.hoisted(() => vi.fn());
+vi.mock('@/lib/logger', () => ({ createLogger: () => ({ debug: diagnosticLog }) }));
+vi.mock('../../../../shared/remoteDesktopDiagnostics', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../../../../shared/remoteDesktopDiagnostics')>()),
+ desktopDiagnosticId: async () => 'hashed-session',
+}));
vi.mock('@cindy/maker-shared/remote-desktop-viewer', () => ({
mountRemoteDesktopViewer: (_root: HTMLElement, post: typeof runtime.post) => {
runtime.post = post;
@@ -40,6 +46,7 @@ async function fixture(
busy?: boolean;
alwaysTimeout?: boolean;
portal?: boolean;
+ heartbeat?: () => Promise<{ controlling: boolean }>;
} = {},
) {
const start = deferred();
@@ -89,6 +96,7 @@ async function fixture(
if (hostLease === request.lease) hostLease = null;
return {};
}
+ if (request.op === 'heartbeat' && options.heartbeat) return options.heartbeat();
if (request.op === 'control' || request.op === 'heartbeat') return { controlling: true };
return { jpeg: null };
},
@@ -130,6 +138,73 @@ async function fixture(
return { start, stop, requests, restart, hostLease: () => hostLease };
}
+it('dumps recent heartbeat results only on failure and preserves the timeout/retry policy', async () => {
+ let calls = 0;
+ const current = await fixture({
+ heartbeat: async () => {
+ if (++calls === 2) throw new Error('INVOKE_TIMEOUT');
+ if (calls === 3) throw new Error('DESKTOP_LEASE_EXPIRED');
+ return { controlling: true };
+ },
+ });
+ runtime.post?.({ type: 'streaming', epoch: 'lease-one' });
+ await vi.advanceTimersByTimeAsync(6000);
+ expect(snapshot.status).toBe('live');
+ expect(diagnosticLog).not.toHaveBeenCalled();
+ await vi.advanceTimersByTimeAsync(3000);
+ expect(snapshot.status).toBe('reconnecting');
+ expect(diagnosticLog).toHaveBeenCalledOnce();
+ const data = diagnosticLog.mock.calls[0][1];
+ expect(data).toMatchObject({
+ source: 'heartbeat',
+ code: 'DESKTOP_LEASE_EXPIRED',
+ session: 'hashed-session',
+ streaming: true,
+ lastRequestFailure: { operation: 'heartbeat', code: 'DESKTOP_LEASE_EXPIRED' },
+ });
+ expect(data.heartbeats.map((sample: { result: string }) => sample.result)).toEqual([
+ 'controlling',
+ 'INVOKE_TIMEOUT',
+ 'DESKTOP_LEASE_EXPIRED',
+ ]);
+ expect(
+ data.heartbeats.every(
+ (sample: { requestedAt: number; settledAt: number }) =>
+ sample.settledAt >= sample.requestedAt,
+ ),
+ ).toBe(true);
+ expect(JSON.stringify(data)).not.toContain('lease-one');
+ await vi.advanceTimersByTimeAsync(3000);
+ expect(current.requests.filter((r) => r.op === 'start')).toHaveLength(2);
+});
+
+it('does not attach a late old heartbeat result to a replacement display lease', async () => {
+ let reject!: (error: Error) => void;
+ let count = 0;
+ await fixture({
+ heartbeat: async () => {
+ if (++count === 1)
+ return new Promise((_resolve, fail) => {
+ reject = fail;
+ });
+ throw new Error('DESKTOP_LEASE_EXPIRED');
+ },
+ });
+ runtime.post?.({ type: 'streaming', epoch: 'lease-one' });
+ await vi.advanceTimersByTimeAsync(3000);
+ controller.selectDisplay('two');
+ await vi.advanceTimersByTimeAsync(0);
+ runtime.post?.({ type: 'streaming', epoch: 'lease-two' });
+ reject(new Error('private old failure'));
+ await vi.advanceTimersByTimeAsync(0);
+ expect(diagnosticLog).not.toHaveBeenCalled();
+ await vi.advanceTimersByTimeAsync(3000);
+ const data = diagnosticLog.mock.calls[0][1];
+ expect(data.heartbeats).toHaveLength(1);
+ expect(data.heartbeats[0].result).toBe('DESKTOP_LEASE_EXPIRED');
+ expect(JSON.stringify(data)).not.toContain('private');
+});
+
it('retries an initial capabilities timeout on a legacy host without inventing a resume', async () => {
const current = await fixture({ legacyTimeout: true });
await vi.advanceTimersByTimeAsync(3001);
diff --git a/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts b/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts
index 6a0ff3d940..00f0e17be7 100644
--- a/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts
+++ b/apps/desktop/src/renderer/features/remote-desktop/viewerController.ts
@@ -22,6 +22,12 @@ import {
} from '@cindy/device-link';
import { mountRemoteDesktopViewer } from '@cindy/maker-shared/remote-desktop-viewer';
import { extractIpcError } from '@/utils/ipcError';
+import { createLogger } from '@/lib/logger';
+import {
+ DesktopHeartbeatHistory,
+ desktopDiagnosticCode,
+ desktopDiagnosticId,
+} from '../../../shared/remoteDesktopDiagnostics';
import type {
RemoteDesktopViewerApi,
RemoteViewerState,
@@ -37,6 +43,9 @@ import {
} from '../../../shared/remoteDesktopViewer';
type Size = { width: number; height: number };
+const log = createLogger('remote-desktop:viewer');
+type FailureSource =
+ 'connection-timeout' | 'connect' | 'heartbeat' | 'frame' | 'media' | 'input-overflow' | 'input';
export interface ViewerSnapshot {
target: RemoteViewerState['target'];
@@ -135,6 +144,12 @@ export class DesktopViewerController {
private connectionTimer: ReturnType<typeof setTimeout> | null = null;
private frameBusy: string | null = null;
private heartbeatBusy: string | null = null;
+ private heartbeats = new DesktopHeartbeatHistory();
+ private lastRequestFailure: {
+ at: number;
+ operation: RemoteDesktopRequest['op'];
+ code: string;
+ } | null = null;
private streaming = false;
private clipboardQueue: Promise<void> = Promise.resolve();
private clipboardQueued = 0;
@@ -259,7 +274,7 @@ export class DesktopViewerController {
} else if (this.connectionTimer === null) {
// Transient failures and media fallback must not renew the total budget.
this.connectionTimer = setTimeout(() => {
- this.fail(new Error('DESKTOP_CONNECTION_TIMEOUT'));
+ this.fail(new Error('DESKTOP_CONNECTION_TIMEOUT'), 'connection-timeout');
}, budget);
}
if (!this.disposed) this.changed(this.state);
@@ -316,6 +331,7 @@ export class DesktopViewerController {
): Promise<T> => {
beforeSend?.();
const scope = this.scope;
+ const epoch = this.epoch;
if (!scope.active || this.disposed) throw new Error('DESKTOP_STOPPED');
try {
return (await this.api.request(
@@ -324,7 +340,14 @@ export class DesktopViewerController {
request.op === 'offer' || request.op === 'ice' ? this.media.attemptId : undefined,
)) as T;
} catch (error) {
- throw new Error(extractIpcError(error)?.message ?? 'DESKTOP_UNAVAILABLE');
+ const message = extractIpcError(error)?.message ?? 'DESKTOP_UNAVAILABLE';
+ if (epoch === this.epoch)
+ this.lastRequestFailure = {
+ at: Date.now(),
+ operation: request.op,
+ code: desktopDiagnosticCode(message),
+ };
+ throw new Error(message);
}
};
private updateScope(scope: RemoteViewerState): void {
@@ -369,6 +392,8 @@ export class DesktopViewerController {
}
private cancel(preserveFrame = false): void {
this.epoch++;
+ this.heartbeats = new DesktopHeartbeatHistory();
+ this.lastRequestFailure = null;
if (this.settingsTimer) clearTimeout(this.settingsTimer);
this.settingsTimer = null;
// A paste waiting on the old session must not open the next session's gate.
@@ -453,13 +478,35 @@ export class DesktopViewerController {
this.applySettings();
} else await this.acquireControl();
} catch (error) {
- if (epoch === this.epoch) this.fail(error);
+ if (epoch === this.epoch) this.fail(error, 'connect');
} finally {
if (epoch === this.epoch) this.opening = false;
}
}
- private fail(error: unknown): void {
+ private fail(error: unknown, source: FailureSource): void {
const code = error instanceof Error ? error.message : '';
+ const lease = this.session.lease?.lease;
+ const diagnostic = {
+ at: Date.now(),
+ source,
+ code: desktopDiagnosticCode(code),
+ generation: this.scope.generation,
+ active: this.scope.active,
+ ready: this.state.ready,
+ streaming: this.streaming,
+ hidden: this.hidden,
+ transport: this.state.transport,
+ latencyMs: this.state.latency,
+ controlling: this.session.lease?.controlling ?? false,
+ heartbeatPending: !!lease && this.heartbeatBusy === lease,
+ heartbeats: this.heartbeats.snapshot(),
+ lastRequestFailure: this.lastRequestFailure,
+ };
+ // Capture before cancel resets the session. Hashing never delays recovery.
+ void (lease ? desktopDiagnosticId(lease) : Promise.resolve(null))
+ .catch(() => null)
+ .then((session) => log.debug('viewer failure', { ...diagnostic, session }))
+ .catch(() => {});
const blocked =
remoteDesktopFailureKey(code) ??
(/DESKTOP_(VIEW_ONLY|INPUT_(BUSY|UNSUPPORTED|UNAVAILABLE|TIMEOUT))/.test(code)
@@ -986,17 +1033,22 @@ export class DesktopViewerController {
const leaseId = this.session.lease.lease;
if (this.heartbeatBusy === leaseId) return;
this.heartbeatBusy = leaseId;
+ const sample = this.heartbeats.add({ requestedAt: Date.now() });
const epoch = this.epoch;
try {
const result = await this.session.heartbeat();
+ sample.settledAt = Date.now();
+ sample.result = result.controlling ? 'controlling' : 'view-only';
if (epoch === this.epoch) {
if (!result.controlling && !this.opening && !this.state.controlPending)
- this.fail(new Error('DESKTOP_VIEW_ONLY'));
+ this.fail(new Error('DESKTOP_VIEW_ONLY'), 'heartbeat');
else this.syncControl();
}
} catch (error) {
+ sample.settledAt = Date.now();
+ sample.result = desktopDiagnosticCode(error);
if (epoch === this.epoch && !(error instanceof Error && error.message === 'INVOKE_TIMEOUT'))
- this.fail(error);
+ this.fail(error, 'heartbeat');
} finally {
if (this.heartbeatBusy === leaseId) this.heartbeatBusy = null;
}
@@ -1042,7 +1094,7 @@ export class DesktopViewerController {
});
}
} catch (error) {
- if (this.session.lease === lease) this.fail(error);
+ if (this.session.lease === lease) this.fail(error, 'frame');
} finally {
if (this.frameBusy === lease.lease) this.frameBusy = null;
}
@@ -1052,7 +1104,7 @@ export class DesktopViewerController {
if (!lease || message.epoch !== lease.lease || this.disposed) return;
if (['iceConfig', 'offer', 'ice'].includes(String(message.type))) {
void this.media.handle(message).catch((error) => {
- if (this.session.lease === lease) this.fail(error);
+ if (this.session.lease === lease) this.fail(error, 'media');
});
return;
}
@@ -1132,7 +1184,7 @@ export class DesktopViewerController {
break;
}
case 'inputOverflow':
- this.fail(new Error('DESKTOP_INPUT_UNAVAILABLE'));
+ this.fail(new Error('DESKTOP_INPUT_UNAVAILABLE'), 'input-overflow');
break;
case 'clipboardIntent':
if (message.action === 'paste' || message.action === 'copy')
@@ -1157,7 +1209,7 @@ export class DesktopViewerController {
this.session.lease === lease &&
!(error instanceof Error && error.message === 'INVOKE_TIMEOUT')
)
- this.fail(error);
+ this.fail(error, 'input');
})
.finally(() => {
if (this.session.lease === lease)
diff --git a/apps/desktop/src/shared/__tests__/remoteDesktopDiagnostics.test.ts b/apps/desktop/src/shared/__tests__/remoteDesktopDiagnostics.test.ts
new file mode 100644
index 0000000000..8282a89287
--- /dev/null
+++ b/apps/desktop/src/shared/__tests__/remoteDesktopDiagnostics.test.ts
@@ -0,0 +1,37 @@
+import { createHash } from 'node:crypto';
+import { expect, it } from 'vitest';
+import {
+ DesktopHeartbeatHistory,
+ desktopDiagnosticCode,
+ desktopDiagnosticId,
+} from '../remoteDesktopDiagnostics';
+
+it('correlates renderer diagnostics with Main using a hash instead of the lease', async () => {
+ const lease = '8108db5e-7b62-4cf6-9893-a2a477fce6c7';
+ expect(await desktopDiagnosticId(lease)).toBe(
+ createHash('sha256').update(lease).digest('hex').slice(0, 16),
+ );
+});
+
+it('keeps snapshots immutable when an in-flight heartbeat settles after disconnect', () => {
+ const history = new DesktopHeartbeatHistory();
+ const pending = history.add({ requestedAt: 10 });
+ const snapshot = history.snapshot();
+ pending.settledAt = 20;
+ pending.result = 'INVOKE_TIMEOUT';
+ expect(snapshot).toEqual([{ requestedAt: 10 }]);
+ for (let i = 0; i < 12; i++) history.add({ requestedAt: 30 + i });
+ expect(history.snapshot()).toHaveLength(8);
+ expect(history.snapshot()[0].requestedAt).toBe(34);
+});
+
+it('drops unknown or decorated error text rather than logging user data', () => {
+ expect(desktopDiagnosticCode(new Error('DESKTOP_LEASE_EXPIRED'))).toBe('DESKTOP_LEASE_EXPIRED');
+ for (const value of [
+ 'DESKTOP_LEASE_EXPIRED private-text',
+ 'SECRET_CONTENT',
+ new Error('/private/file'),
+ { code: 'INVOKE_TIMEOUT' },
+ ])
+ expect(desktopDiagnosticCode(value)).toBe('UNKNOWN_ERROR');
+});
diff --git a/apps/desktop/src/shared/remoteDesktopDiagnostics.ts b/apps/desktop/src/shared/remoteDesktopDiagnostics.ts
new file mode 100644
index 0000000000..2a7230c4c1
--- /dev/null
+++ b/apps/desktop/src/shared/remoteDesktopDiagnostics.ts
@@ -0,0 +1,64 @@
+/** Local diagnostics only: never include request payloads, credentials or raw leases. */
+export interface DesktopHeartbeatSample {
+ /** Viewer request time includes queueing; it is not proof of a socket write. */
+ requestedAt?: number;
+ settledAt?: number;
+ /** Host receipt time, never used for a locally timed-out viewer request. */
+ receivedAt?: number;
+ result?: string;
+}
+
+export class DesktopHeartbeatHistory {
+ private samples: DesktopHeartbeatSample[] = [];
+
+ add(sample: DesktopHeartbeatSample): DesktopHeartbeatSample {
+ this.samples.push(sample);
+ if (this.samples.length > 8) this.samples.shift();
+ return sample;
+ }
+
+ snapshot(): DesktopHeartbeatSample[] {
+ return this.samples.map((sample) => ({ ...sample }));
+ }
+}
+
+const DIAGNOSTIC_CODES = new Set([
+ 'DESKTOP_LEASE_EXPIRED',
+ 'DESKTOP_STOPPED',
+ 'DESKTOP_VIEW_ONLY',
+ 'DESKTOP_CONNECTION_TIMEOUT',
+ 'DESKTOP_INPUT_UNAVAILABLE',
+ 'DESKTOP_INPUT_TIMEOUT',
+ 'DESKTOP_INPUT_BUSY',
+ 'DESKTOP_INPUT_UNSUPPORTED',
+ 'DESKTOP_BUSY',
+ 'DESKTOP_DISABLED',
+ 'DESKTOP_AUTHENTICATION_REQUIRED',
+ 'DESKTOP_UNAVAILABLE',
+ 'INVOKE_TIMEOUT',
+ 'BACKPRESSURE',
+ 'DEVICE_LINK_BUSY',
+ 'DEVICE_UNRESPONSIVE',
+ 'DEVICE_OFFLINE',
+ 'NOT_CONNECTED',
+ 'LINK_CLOSED',
+ 'LINK_NOT_OPEN',
+ 'PEER_RESET',
+ 'ACCESS_REVOKED',
+ 'CHANNEL_NOT_ALLOWED',
+ 'REMOTE_DISABLED',
+]);
+
+/** Exact allowlist: arbitrary error messages can contain private request data. */
+export function desktopDiagnosticCode(value: unknown): string {
+ const code = value instanceof Error ? value.message : value;
+ return typeof code === 'string' && DIAGNOSTIC_CODES.has(code) ? code : 'UNKNOWN_ERROR';
+}
+
+/** Same truncated SHA-256 as Main, without exposing a lease through a new IPC. */
+export async function desktopDiagnosticId(lease: string): Promise<string> {
+ const hash = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(lease));
+ return Array.from(new Uint8Array(hash).slice(0, 8), (byte) =>
+ byte.toString(16).padStart(2, '0'),
+ ).join('');
+}