Skip to content

Commit ac7901c

Browse files
refactor(Wind): Improve extension host debugging observability
Enhance the extension host handshake and RPC message handling in Preload with more granular performance marks and debug logging. Changes: - Split single `handshake-complete` mark into three specific marks: `init-data-received`, `initialized-sent`, and `ready-sent` - Add debug logging that outputs init data byte size and text preview (first 200 chars) for diagnosing initialization issues - Rename message performance marks from `message:N` to `rpc:N` for clarity - Log the first 5 RPC messages with byte size and preview for debugging protocol issues These improvements enable better visibility into the extension host initialization flow and help diagnose communication problems between Wind and Cocoon.
1 parent 798d976 commit ac7901c

2 files changed

Lines changed: 62 additions & 5 deletions

File tree

Source/Preload.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,16 @@ const ipcMessagePort = {
239239
if (Length > 1) {
240240
HandshakeComplete = true;
241241
try {
242-
performance.mark("land:exthost:handshake-complete");
242+
performance.mark("land:exthost:handshake:init-data-received", {
243+
detail: { bytes: Length },
244+
});
245+
} catch {}
246+
247+
// Log init data summary for debugging
248+
try {
249+
const Bytes = Data instanceof Uint8Array ? Data : new Uint8Array(Data);
250+
const Text = new TextDecoder().decode(Bytes.slice(0, 500));
251+
console.warn("[Extension Host] Init data received:", Length, "bytes, preview:", Text.slice(0, 200));
243252
} catch {}
244253

245254
// Forward init data to Mountain for Cocoon
@@ -251,18 +260,34 @@ const ipcMessagePort = {
251260

252261
// MessageType.Initialized → byte 1
253262
port1.postMessage(new Uint8Array([1]));
263+
264+
try {
265+
performance.mark("land:exthost:handshake:initialized-sent");
266+
} catch {}
267+
console.warn("[Extension Host] Handshake complete — Initialized sent");
268+
} else {
269+
console.warn("[Extension Host] Handshake: ignoring control byte", Length > 0 ? new Uint8Array(Data instanceof ArrayBuffer ? Data : Data)[0] : "empty");
254270
}
255271
return;
256272
}
257273

258-
// Post-handshake: forward extension host protocol messages
274+
// Post-handshake: forward extension host protocol messages (RPC)
259275
MessageCount++;
260276
try {
261-
performance.mark(`land:exthost:message:${MessageCount}`, {
277+
performance.mark(`land:exthost:rpc:${MessageCount}`, {
262278
detail: { bytes: Length },
263279
});
264280
} catch {}
265281

282+
if (MessageCount <= 5) {
283+
// Log first few RPC messages for debugging
284+
try {
285+
const Bytes = Data instanceof Uint8Array ? Data : new Uint8Array(Data);
286+
const Preview = new TextDecoder().decode(Bytes.slice(0, 200));
287+
console.warn(`[Extension Host] RPC #${MessageCount}:`, Length, "bytes, preview:", Preview.slice(0, 150));
288+
} catch {}
289+
}
290+
266291
if (Length > 0) {
267292
ForwardToMountain(
268293
Data instanceof Uint8Array ? Data : new Uint8Array(Data),
@@ -287,6 +312,10 @@ const ipcMessagePort = {
287312
// MessageType.Ready → byte 2
288313
setTimeout(() => {
289314
port1.postMessage(new Uint8Array([2]));
315+
try {
316+
performance.mark("land:exthost:handshake:ready-sent");
317+
} catch {}
318+
console.warn("[Extension Host] Ready sent on MessagePort, waiting for init data...");
290319
}, 50);
291320
},
292321
};

Target/Preload.js

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)