Skip to content

Commit 07a10a8

Browse files
committed
Review comments
1 parent a34f9c6 commit 07a10a8

File tree

1 file changed

+22
-85
lines changed

1 file changed

+22
-85
lines changed

src/remote/remote.ts

Lines changed: 22 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -545,21 +545,9 @@ export class Remote {
545545
const updatedAgent = await this.waitForAgentWithProgress(
546546
monitor,
547547
agent,
548-
{
549-
progressTitle: "Waiting for the agent to connect...",
550-
timeoutMs: 3 * 60 * 1000,
551-
errorDialogTitle: `Failed to wait for ${agent.name} connection`,
552-
},
553-
(foundAgent) => {
554-
if (foundAgent.status !== "connecting") {
555-
return foundAgent;
556-
}
557-
return undefined;
558-
},
548+
`Waiting for agent ${agent.name} to connect...`,
549+
(foundAgent) => foundAgent.status !== "connecting",
559550
);
560-
if (!updatedAgent) {
561-
return;
562-
}
563551
agent = updatedAgent;
564552
this.logger.info(`Agent ${agent.name} status is now`, agent.status);
565553
}
@@ -606,28 +594,15 @@ export class Remote {
606594
const agentStatePromise = this.waitForAgentWithProgress(
607595
monitor,
608596
agent,
609-
{
610-
progressTitle: "Waiting for agent startup scripts...",
611-
timeoutMs: 5 * 60 * 1000,
612-
errorDialogTitle: `Failed to wait for ${agent.name} startup`,
613-
},
614-
(foundAgent) => {
615-
if (foundAgent.lifecycle_state !== "starting") {
616-
return foundAgent;
617-
}
618-
return undefined;
619-
},
597+
`Waiting for agent ${agent.name} startup scripts...`,
598+
(foundAgent) => foundAgent.lifecycle_state !== "starting",
620599
);
621600

622-
// Race between logs completion (which fails on socket error) and agent state change
601+
// Race between logs completion and agent state change
623602
const updatedAgent = await Promise.race([
624603
agentStatePromise,
625604
logsCompletion.then(() => agentStatePromise),
626605
]);
627-
628-
if (!updatedAgent) {
629-
return;
630-
}
631606
agent = updatedAgent;
632607
this.logger.info(
633608
`Agent ${agent.name} lifecycle state is now`,
@@ -766,70 +741,34 @@ export class Remote {
766741
}
767742

768743
/**
769-
* Waits for an agent condition with progress notification and error handling.
770-
* Returns the updated agent or undefined if the user chooses to close remote.
744+
* Waits for an agent condition with progress notification.
771745
*/
772746
private async waitForAgentWithProgress(
773747
monitor: WorkspaceMonitor,
774748
agent: WorkspaceAgent,
775-
options: {
776-
progressTitle: string;
777-
timeoutMs: number;
778-
errorDialogTitle: string;
779-
},
780-
checker: (agent: WorkspaceAgent) => WorkspaceAgent | undefined,
781-
): Promise<WorkspaceAgent | undefined> {
782-
try {
783-
const foundAgent = await vscode.window.withProgress(
784-
{
785-
title: options.progressTitle,
786-
location: vscode.ProgressLocation.Notification,
787-
},
788-
async () =>
789-
this.waitForAgentCondition(
790-
monitor,
791-
agent,
792-
checker,
793-
options.timeoutMs,
794-
`Timeout: ${options.errorDialogTitle}`,
795-
),
796-
);
797-
return foundAgent;
798-
} catch (error) {
799-
this.logger.error(options.errorDialogTitle, error);
800-
const result = await this.vscodeProposed.window.showErrorMessage(
801-
options.errorDialogTitle,
802-
{
803-
useCustom: true,
804-
modal: true,
805-
detail: error instanceof Error ? error.message : String(error),
806-
},
807-
"Close Remote",
808-
);
809-
if (result === "Close Remote") {
810-
await this.closeRemote();
811-
}
812-
return undefined;
813-
}
749+
progressTitle: string,
750+
checker: (agent: WorkspaceAgent) => boolean,
751+
): Promise<WorkspaceAgent> {
752+
const foundAgent = await vscode.window.withProgress(
753+
{
754+
title: progressTitle,
755+
location: vscode.ProgressLocation.Notification,
756+
},
757+
async () => this.waitForAgentCondition(monitor, agent, checker),
758+
);
759+
return foundAgent;
814760
}
815761

816762
/**
817763
* Waits for an agent condition to be met by monitoring workspace changes.
818764
* Returns the result when the condition is met or throws an error on timeout.
819765
*/
820-
private async waitForAgentCondition<T>(
766+
private async waitForAgentCondition(
821767
monitor: WorkspaceMonitor,
822768
agent: WorkspaceAgent,
823-
checker: (agent: WorkspaceAgent) => T | undefined,
824-
timeoutMs: number,
825-
timeoutMessage: string,
826-
): Promise<T> {
827-
return new Promise<T>((resolve, reject) => {
828-
const timeout = setTimeout(() => {
829-
updateEvent.dispose();
830-
reject(new Error(timeoutMessage));
831-
}, timeoutMs);
832-
769+
checker: (agent: WorkspaceAgent) => boolean,
770+
): Promise<WorkspaceAgent> {
771+
return new Promise<WorkspaceAgent>((resolve, reject) => {
833772
const updateEvent = monitor.onChange.event((workspace) => {
834773
try {
835774
const agents = extractAgents(workspace.latest_build.resources);
@@ -841,12 +780,10 @@ export class Remote {
841780
}
842781
const result = checker(foundAgent);
843782
if (result !== undefined) {
844-
clearTimeout(timeout);
845783
updateEvent.dispose();
846-
resolve(result);
784+
resolve(foundAgent);
847785
}
848786
} catch (error) {
849-
clearTimeout(timeout);
850787
updateEvent.dispose();
851788
reject(error);
852789
}

0 commit comments

Comments
 (0)