@adhdev/session-host-core 1.0.82-rc.27 → 1.0.82-rc.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/session-host-core",
3
- "version": "1.0.82-rc.27",
3
+ "version": "1.0.82-rc.29",
4
4
  "description": "ADHDev local session host core — session registry, protocol, buffers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export type {
2
+ MeshWriterAssignment,
3
+ MeshWriterStopTarget,
4
+ StopMeshWriterPayload,
2
5
  HostUpgradeLeasePayload,
3
6
  AcquireWritePayload,
4
7
  AttachSessionPayload,
package/src/ipc.ts CHANGED
@@ -311,9 +311,24 @@ export class SessionHostClient {
311
311
  request,
312
312
  };
313
313
  const timeoutLabel = timeoutMs % 1000 === 0 ? `${timeoutMs / 1000}s` : `${timeoutMs}ms`;
314
+ const startedAt = Date.now();
315
+ const startedMonotonicAt = performance.now();
314
316
  return new Promise<SessionHostResponse<T>>((resolve, reject) => {
315
317
  const timeout = setTimeout(() => {
316
- const timeoutError = Object.assign(new Error(`Session host request timed out after ${timeoutLabel} (${request.type})`), { code: 'SESSION_HOST_REQUEST_TIMEOUT', requestType: request.type });
318
+ const actualElapsedMs = Math.max(0, Math.round(performance.now() - startedMonotonicAt));
319
+ const wallElapsedMs = Math.max(0, Date.now() - startedAt);
320
+ const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
321
+ const timeoutError = Object.assign(
322
+ new Error(`Session host request timed out after ${timeoutLabel} (${request.type})`),
323
+ {
324
+ code: 'SESSION_HOST_REQUEST_TIMEOUT',
325
+ requestType: request.type,
326
+ scheduledTimeoutMs: timeoutMs,
327
+ actualElapsedMs,
328
+ wallElapsedMs,
329
+ observerLagMs,
330
+ },
331
+ );
317
332
  if (this.socket === socket) {
318
333
  this.disconnect(timeoutError);
319
334
  } else {
@@ -414,8 +429,22 @@ export class SessionHostClient {
414
429
  const connected = () => { cleanup(); establishedSockets.add(socket); resolve(); };
415
430
  const failed = (error: Error) => { cleanup(); reject(error); };
416
431
  const closed = () => failed(new Error('Session host connection closed before connect'));
432
+ const connectStartedAt = Date.now();
433
+ const connectStartedMonotonicAt = performance.now();
417
434
  const timer = setTimeout(() => {
418
- const error = Object.assign(new Error(`Session host connect timed out after ${timeoutMs}ms`), { code: 'SESSION_HOST_CONNECT_TIMEOUT' });
435
+ const actualElapsedMs = Math.max(0, Math.round(performance.now() - connectStartedMonotonicAt));
436
+ const wallElapsedMs = Math.max(0, Date.now() - connectStartedAt);
437
+ const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
438
+ const error = Object.assign(
439
+ new Error(`Session host connect timed out after ${timeoutMs}ms`),
440
+ {
441
+ code: 'SESSION_HOST_CONNECT_TIMEOUT',
442
+ scheduledTimeoutMs: timeoutMs,
443
+ actualElapsedMs,
444
+ wallElapsedMs,
445
+ observerLagMs,
446
+ },
447
+ );
419
448
  failed(error);
420
449
  if (this.socket === socket) this.disconnect(error);
421
450
  }, timeoutMs);
@@ -462,12 +491,26 @@ export class SessionHostClient {
462
491
  // client; that task may have started with the normal 30s timeout.
463
492
  if (options.timeoutMs !== undefined) {
464
493
  let timer: ReturnType<typeof setTimeout> | undefined;
494
+ const raceStartedAt = Date.now();
495
+ const raceStartedMonotonicAt = performance.now();
465
496
  try {
466
497
  await Promise.race([
467
498
  this.connect(timeoutMs),
468
499
  new Promise<never>((_resolve, reject) => {
469
500
  timer = setTimeout(() => {
470
- const error = Object.assign(new Error(`Session host connect timed out after ${timeoutMs}ms`), { code: 'SESSION_HOST_CONNECT_TIMEOUT' });
501
+ const actualElapsedMs = Math.max(0, Math.round(performance.now() - raceStartedMonotonicAt));
502
+ const wallElapsedMs = Math.max(0, Date.now() - raceStartedAt);
503
+ const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
504
+ const error = Object.assign(
505
+ new Error(`Session host connect timed out after ${timeoutMs}ms`),
506
+ {
507
+ code: 'SESSION_HOST_CONNECT_TIMEOUT',
508
+ scheduledTimeoutMs: timeoutMs,
509
+ actualElapsedMs,
510
+ wallElapsedMs,
511
+ observerLagMs,
512
+ },
513
+ );
471
514
  reject(error);
472
515
  this.disconnect(error);
473
516
  }, timeoutMs);
package/src/types.ts CHANGED
@@ -157,6 +157,15 @@ export interface ResizeSessionPayload {
157
157
  export interface StopSessionPayload {
158
158
  sessionId: string;
159
159
  }
160
+ export interface MeshWriterAssignment {
161
+ meshId: string; nodeId: string; taskId: string; attemptId: string;
162
+ generation: number; dispatchNonce: number; ownerDaemonId: string;
163
+ }
164
+ export interface MeshWriterStopTarget {
165
+ runtimeKey: string; startedAt: number; osPid: number; providerType: string;
166
+ assignment: MeshWriterAssignment;
167
+ }
168
+ export interface StopMeshWriterPayload extends MeshWriterStopTarget { sessionId: string; clientId: string }
160
169
 
161
170
  export interface DeleteSessionPayload {
162
171
  sessionId: string;
@@ -317,6 +326,7 @@ export type SessionHostRequest =
317
326
  | { type: 'send_input'; payload: SendInputPayload }
318
327
  | { type: 'resize_session'; payload: ResizeSessionPayload }
319
328
  | { type: 'stop_session'; payload: StopSessionPayload }
329
+ | { type: 'stop_mesh_writer'; payload: StopMeshWriterPayload }
320
330
  | { type: 'delete_session'; payload: DeleteSessionPayload }
321
331
  | { type: 'resume_session'; payload: ResumeSessionPayload }
322
332
  | { type: 'acquire_write'; payload: AcquireWritePayload }
@@ -344,6 +354,7 @@ export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestTy
344
354
  'send_input',
345
355
  'resize_session',
346
356
  'stop_session',
357
+ 'stop_mesh_writer',
347
358
  'delete_session',
348
359
  'resume_session',
349
360
  'acquire_write',