Skip to content

Commit 21a5f1a

Browse files
rentziassCopilot
andauthored
Fix auth prompt and buffer early stopped events
Two UX issues: 1. Auth: switch from newSession() (which always forces a new login prompt) to getSession() which silently reuses the existing session. 2. Variables not populated on connect: the runner sends a 'stopped' event immediately on websocket connect, before VS Code has finished the DAP initialization handshake (configurationDone). VS Code drops stopped events that arrive before configurationDone. The adapter now buffers any stopped events received before the client sends configurationDone and replays them once the handshake completes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 923e067 commit 21a5f1a

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/debugger/debugger.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import {newSession} from "../auth/auth";
2+
import {getSession} from "../auth/auth";
33
import {log, logError} from "../log";
44
import {validateTunnelUrl} from "./tunnelUrl";
55
import {WebSocketDapAdapter} from "./webSocketDapAdapter";
@@ -56,11 +56,13 @@ async function connectToDebugger(): Promise<void> {
5656

5757
// 2. Acquire a GitHub auth session. The token is used as a Bearer token
5858
// against the Dev Tunnel relay, which accepts VS Code's GitHub app tokens.
59-
let session: vscode.AuthenticationSession;
60-
try {
61-
session = await newSession("Sign in to GitHub to connect to the Actions job debugger.");
62-
} catch (e) {
63-
void vscode.window.showErrorMessage(`GitHub authentication required: ${(e as Error).message}`);
59+
// getSession() silently reuses the existing session; it only prompts if
60+
// the user has never signed in.
61+
const session = await getSession();
62+
if (!session) {
63+
void vscode.window.showErrorMessage(
64+
"GitHub authentication is required to connect to the Actions job debugger. Please sign in and try again."
65+
);
6466
return;
6567
}
6668

src/debugger/webSocketDapAdapter.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ export class WebSocketDapAdapter implements vscode.DebugAdapter {
2424
private _pingTimer: ReturnType<typeof setInterval> | undefined;
2525
private _disposed = false;
2626

27+
/**
28+
* Whether VS Code has completed the DAP initialization handshake. The
29+
* runner sends a `stopped` event immediately on connect (before the client
30+
* sends `configurationDone`), and VS Code ignores `stopped` events that
31+
* arrive before configuration is done. We buffer early `stopped` events
32+
* and replay them once the handshake completes.
33+
*/
34+
private _configurationDone = false;
35+
private _pendingStoppedEvents: vscode.DebugProtocolMessage[] = [];
36+
2737
constructor(
2838
private readonly _tunnelUrl: string,
2939
private readonly _token: string
@@ -92,6 +102,20 @@ export class WebSocketDapAdapter implements vscode.DebugAdapter {
92102
const json = JSON.stringify(message);
93103
logDebug(`→ DAP: ${describeDapMessage(message)}`);
94104
this._ws.send(json);
105+
106+
// Detect configurationDone and replay any stopped events the runner
107+
// sent before VS Code was ready to receive them.
108+
const m = message as Record<string, unknown>;
109+
if (m.command === "configurationDone" && m.type === "request") {
110+
this._configurationDone = true;
111+
if (this._pendingStoppedEvents.length > 0) {
112+
logDebug(`Replaying ${this._pendingStoppedEvents.length} buffered stopped event(s)`);
113+
for (const evt of this._pendingStoppedEvents) {
114+
this._onDidSendMessage.fire(evt);
115+
}
116+
this._pendingStoppedEvents = [];
117+
}
118+
}
95119
}
96120

97121
dispose(): void {
@@ -131,6 +155,17 @@ export class WebSocketDapAdapter implements vscode.DebugAdapter {
131155
}
132156

133157
logDebug(`← DAP: ${describeDapMessage(message)}`);
158+
159+
// Buffer stopped events that arrive before configurationDone — the
160+
// runner re-sends the stopped event on connect (before the client
161+
// finishes the DAP handshake) and VS Code silently drops them.
162+
const m = message as Record<string, unknown>;
163+
if (m.type === "event" && m.event === "stopped" && !this._configurationDone) {
164+
logDebug("Buffering stopped event (configurationDone not yet sent)");
165+
this._pendingStoppedEvents.push(message);
166+
return;
167+
}
168+
134169
this._onDidSendMessage.fire(message);
135170
});
136171

0 commit comments

Comments
 (0)