@naylence/runtime 0.3.5-test.936 → 0.3.5-test.938

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.
@@ -98,12 +98,12 @@ installProcessEnvShim();
98
98
  // --- END ENV SHIM ---
99
99
 
100
100
  // This file is auto-generated during build - do not edit manually
101
- // Generated from package.json version: 0.3.5-test.936
101
+ // Generated from package.json version: 0.3.5-test.938
102
102
  /**
103
103
  * The package version, injected at build time.
104
104
  * @internal
105
105
  */
106
- const VERSION = '0.3.5-test.936';
106
+ const VERSION = '0.3.5-test.938';
107
107
 
108
108
  /**
109
109
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9668,7 +9668,7 @@ class BaseAsyncConnector extends TaskSpawner {
9668
9668
  });
9669
9669
  return;
9670
9670
  }
9671
- logger$$.info('connector_shutdown_starting', {
9671
+ logger$$.debug('connector_shutdown_starting', {
9672
9672
  connector_id: this._connectorFlowId,
9673
9673
  connector_type: this.constructor.name,
9674
9674
  code,
@@ -9698,19 +9698,19 @@ class BaseAsyncConnector extends TaskSpawner {
9698
9698
  this._sendPromiseResolve = undefined;
9699
9699
  }
9700
9700
  // Close transport
9701
- logger$$.info('connector_closing_transport', {
9701
+ logger$$.debug('connector_closing_transport', {
9702
9702
  connector_id: this._connectorFlowId,
9703
9703
  connector_type: this.constructor.name,
9704
9704
  timestamp: new Date().toISOString(),
9705
9705
  });
9706
9706
  await this._transportClose(code, reason);
9707
- logger$$.info('connector_transport_closed', {
9707
+ logger$$.debug('connector_transport_closed', {
9708
9708
  connector_id: this._connectorFlowId,
9709
9709
  connector_type: this.constructor.name,
9710
9710
  timestamp: new Date().toISOString(),
9711
9711
  });
9712
9712
  // Shutdown spawned tasks
9713
- logger$$.info('connector_shutting_down_tasks', {
9713
+ logger$$.debug('connector_shutting_down_tasks', {
9714
9714
  connector_id: this._connectorFlowId,
9715
9715
  connector_type: this.constructor.name,
9716
9716
  grace_period_ms: effectiveGracePeriod * 1000,
@@ -9722,7 +9722,7 @@ class BaseAsyncConnector extends TaskSpawner {
9722
9722
  gracePeriod: effectiveGracePeriod * 1000, // Convert to milliseconds
9723
9723
  joinTimeout: this._shutdownJoinTimeout,
9724
9724
  });
9725
- logger$$.info('connector_tasks_shutdown_complete', {
9725
+ logger$$.debug('connector_tasks_shutdown_complete', {
9726
9726
  connector_id: this._connectorFlowId,
9727
9727
  connector_type: this.constructor.name,
9728
9728
  timestamp: new Date().toISOString(),
@@ -9742,7 +9742,7 @@ class BaseAsyncConnector extends TaskSpawner {
9742
9742
  if (this._closeResolver) {
9743
9743
  this._closeResolver();
9744
9744
  }
9745
- logger$$.info('connector_shutdown_complete', {
9745
+ logger$$.debug('connector_shutdown_complete', {
9746
9746
  connector_id: this._connectorFlowId,
9747
9747
  connector_type: this.constructor.name,
9748
9748
  final_state: this._state,
@@ -9883,7 +9883,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9883
9883
  this.inbox = new BoundedAsyncQueue(preferredCapacity);
9884
9884
  this.connectorId = BroadcastChannelConnector.generateConnectorId();
9885
9885
  this.channel = new BroadcastChannel(this.channelName);
9886
- logger$_.info('broadcast_channel_connector_created', {
9886
+ logger$_.debug('broadcast_channel_connector_created', {
9887
9887
  channel: this.channelName,
9888
9888
  connector_id: this.connectorId,
9889
9889
  inbox_capacity: preferredCapacity,
@@ -9964,7 +9964,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9964
9964
  // Setup visibility change monitoring
9965
9965
  this.visibilityChangeHandler = () => {
9966
9966
  const isHidden = document.hidden;
9967
- logger$_.info('broadcast_channel_visibility_changed', {
9967
+ logger$_.debug('broadcast_channel_visibility_changed', {
9968
9968
  channel: this.channelName,
9969
9969
  connector_id: this.connectorId,
9970
9970
  visibility: isHidden ? 'hidden' : 'visible',
@@ -9994,7 +9994,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9994
9994
  document.addEventListener('visibilitychange', this.visibilityChangeHandler);
9995
9995
  this.visibilityChangeListenerRegistered = true;
9996
9996
  // Log initial state
9997
- logger$_.info('broadcast_channel_initial_visibility', {
9997
+ logger$_.debug('broadcast_channel_initial_visibility', {
9998
9998
  channel: this.channelName,
9999
9999
  connector_id: this.connectorId,
10000
10000
  visibility: document.hidden ? 'hidden' : 'visible',
@@ -10044,7 +10044,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10044
10044
  return await this.inbox.dequeue();
10045
10045
  }
10046
10046
  async _transportClose(code, reason) {
10047
- logger$_.info('broadcast_channel_transport_closing', {
10047
+ logger$_.debug('broadcast_channel_transport_closing', {
10048
10048
  channel: this.channelName,
10049
10049
  connector_id: this.connectorId,
10050
10050
  code,
@@ -10053,14 +10053,14 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10053
10053
  timestamp: new Date().toISOString(),
10054
10054
  });
10055
10055
  if (this.listenerRegistered) {
10056
- logger$_.info('broadcast_channel_removing_listener', {
10056
+ logger$_.debug('broadcast_channel_removing_listener', {
10057
10057
  channel: this.channelName,
10058
10058
  connector_id: this.connectorId,
10059
10059
  timestamp: new Date().toISOString(),
10060
10060
  });
10061
10061
  this.channel.removeEventListener('message', this.onMsg);
10062
10062
  this.listenerRegistered = false;
10063
- logger$_.info('broadcast_channel_listener_removed', {
10063
+ logger$_.debug('broadcast_channel_listener_removed', {
10064
10064
  channel: this.channelName,
10065
10065
  connector_id: this.connectorId,
10066
10066
  timestamp: new Date().toISOString(),
@@ -10071,13 +10071,13 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10071
10071
  this.visibilityChangeListenerRegistered = false;
10072
10072
  this.visibilityChangeHandler = undefined;
10073
10073
  }
10074
- logger$_.info('broadcast_channel_closing', {
10074
+ logger$_.debug('broadcast_channel_closing', {
10075
10075
  channel: this.channelName,
10076
10076
  connector_id: this.connectorId,
10077
10077
  timestamp: new Date().toISOString(),
10078
10078
  });
10079
10079
  this.channel.close();
10080
- logger$_.info('broadcast_channel_closed', {
10080
+ logger$_.debug('broadcast_channel_closed', {
10081
10081
  channel: this.channelName,
10082
10082
  connector_id: this.connectorId,
10083
10083
  timestamp: new Date().toISOString(),
@@ -10168,6 +10168,28 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10168
10168
  }
10169
10169
  return undefined;
10170
10170
  }
10171
+ /**
10172
+ * Override start() to check initial visibility state
10173
+ */
10174
+ async start(inboundHandler) {
10175
+ await super.start(inboundHandler);
10176
+ // After transitioning to STARTED, check if tab is already hidden
10177
+ if (typeof document !== 'undefined' && document.hidden) {
10178
+ logger$_.debug('broadcast_channel_start_in_hidden_tab', {
10179
+ channel: this.channelName,
10180
+ connector_id: this.connectorId,
10181
+ timestamp: new Date().toISOString(),
10182
+ });
10183
+ // Immediately pause if tab is hidden at start time
10184
+ await this.pause().catch((err) => {
10185
+ logger$_.warning('broadcast_channel_initial_pause_failed', {
10186
+ channel: this.channelName,
10187
+ connector_id: this.connectorId,
10188
+ error: err instanceof Error ? err.message : String(err),
10189
+ });
10190
+ });
10191
+ }
10192
+ }
10171
10193
  _trimSeenAcks(now) {
10172
10194
  while (this.seenAckOrder.length > 0) {
10173
10195
  const candidate = this.seenAckOrder[0];
@@ -10454,6 +10476,7 @@ class UpstreamSessionManager extends TaskSpawner {
10454
10476
  this.lastHeartbeatAckTime = null;
10455
10477
  this.lastSeenEpoch = null;
10456
10478
  this.hadSuccessfulAttach = false;
10479
+ this.lastConnectorState = null;
10457
10480
  this.connectEpoch = 0;
10458
10481
  const options = normalizeOptions$k(optionsInput);
10459
10482
  this.node = options.node;
@@ -10878,15 +10901,26 @@ class UpstreamSessionManager extends TaskSpawner {
10878
10901
  if (stopEvt.isSet() || signal?.aborted) {
10879
10902
  break;
10880
10903
  }
10904
+ const currentState = connector.state;
10905
+ const previousState = this.lastConnectorState;
10906
+ this.lastConnectorState = currentState;
10881
10907
  // Skip heartbeat if connector is paused (e.g., tab is hidden)
10882
10908
  // Keep ack time current so we don't timeout immediately after resuming
10883
- if (connector.state === core.ConnectorState.PAUSED) {
10909
+ if (currentState === core.ConnectorState.PAUSED) {
10884
10910
  logger$Z.debug('skipping_heartbeat_connector_paused', {
10885
- connector_state: connector.state,
10911
+ connector_state: currentState,
10886
10912
  });
10887
10913
  this.lastHeartbeatAckTime = Date.now();
10888
10914
  continue;
10889
10915
  }
10916
+ // Reset ack time if just resumed from pause (prevents immediate timeout)
10917
+ if (previousState === core.ConnectorState.PAUSED && currentState === core.ConnectorState.STARTED) {
10918
+ logger$Z.debug('connector_just_resumed_resetting_ack_time', {
10919
+ previous_state: previousState,
10920
+ current_state: currentState,
10921
+ });
10922
+ this.lastHeartbeatAckTime = Date.now();
10923
+ }
10890
10924
  const envelope = await this.makeHeartbeatEnvelope();
10891
10925
  logger$Z.debug('sending_heartbeat', {
10892
10926
  hb_corr_id: envelope.corrId,
@@ -96,12 +96,12 @@ installProcessEnvShim();
96
96
  // --- END ENV SHIM ---
97
97
 
98
98
  // This file is auto-generated during build - do not edit manually
99
- // Generated from package.json version: 0.3.5-test.936
99
+ // Generated from package.json version: 0.3.5-test.938
100
100
  /**
101
101
  * The package version, injected at build time.
102
102
  * @internal
103
103
  */
104
- const VERSION = '0.3.5-test.936';
104
+ const VERSION = '0.3.5-test.938';
105
105
 
106
106
  /**
107
107
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9666,7 +9666,7 @@ class BaseAsyncConnector extends TaskSpawner {
9666
9666
  });
9667
9667
  return;
9668
9668
  }
9669
- logger$$.info('connector_shutdown_starting', {
9669
+ logger$$.debug('connector_shutdown_starting', {
9670
9670
  connector_id: this._connectorFlowId,
9671
9671
  connector_type: this.constructor.name,
9672
9672
  code,
@@ -9696,19 +9696,19 @@ class BaseAsyncConnector extends TaskSpawner {
9696
9696
  this._sendPromiseResolve = undefined;
9697
9697
  }
9698
9698
  // Close transport
9699
- logger$$.info('connector_closing_transport', {
9699
+ logger$$.debug('connector_closing_transport', {
9700
9700
  connector_id: this._connectorFlowId,
9701
9701
  connector_type: this.constructor.name,
9702
9702
  timestamp: new Date().toISOString(),
9703
9703
  });
9704
9704
  await this._transportClose(code, reason);
9705
- logger$$.info('connector_transport_closed', {
9705
+ logger$$.debug('connector_transport_closed', {
9706
9706
  connector_id: this._connectorFlowId,
9707
9707
  connector_type: this.constructor.name,
9708
9708
  timestamp: new Date().toISOString(),
9709
9709
  });
9710
9710
  // Shutdown spawned tasks
9711
- logger$$.info('connector_shutting_down_tasks', {
9711
+ logger$$.debug('connector_shutting_down_tasks', {
9712
9712
  connector_id: this._connectorFlowId,
9713
9713
  connector_type: this.constructor.name,
9714
9714
  grace_period_ms: effectiveGracePeriod * 1000,
@@ -9720,7 +9720,7 @@ class BaseAsyncConnector extends TaskSpawner {
9720
9720
  gracePeriod: effectiveGracePeriod * 1000, // Convert to milliseconds
9721
9721
  joinTimeout: this._shutdownJoinTimeout,
9722
9722
  });
9723
- logger$$.info('connector_tasks_shutdown_complete', {
9723
+ logger$$.debug('connector_tasks_shutdown_complete', {
9724
9724
  connector_id: this._connectorFlowId,
9725
9725
  connector_type: this.constructor.name,
9726
9726
  timestamp: new Date().toISOString(),
@@ -9740,7 +9740,7 @@ class BaseAsyncConnector extends TaskSpawner {
9740
9740
  if (this._closeResolver) {
9741
9741
  this._closeResolver();
9742
9742
  }
9743
- logger$$.info('connector_shutdown_complete', {
9743
+ logger$$.debug('connector_shutdown_complete', {
9744
9744
  connector_id: this._connectorFlowId,
9745
9745
  connector_type: this.constructor.name,
9746
9746
  final_state: this._state,
@@ -9881,7 +9881,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9881
9881
  this.inbox = new BoundedAsyncQueue(preferredCapacity);
9882
9882
  this.connectorId = BroadcastChannelConnector.generateConnectorId();
9883
9883
  this.channel = new BroadcastChannel(this.channelName);
9884
- logger$_.info('broadcast_channel_connector_created', {
9884
+ logger$_.debug('broadcast_channel_connector_created', {
9885
9885
  channel: this.channelName,
9886
9886
  connector_id: this.connectorId,
9887
9887
  inbox_capacity: preferredCapacity,
@@ -9962,7 +9962,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9962
9962
  // Setup visibility change monitoring
9963
9963
  this.visibilityChangeHandler = () => {
9964
9964
  const isHidden = document.hidden;
9965
- logger$_.info('broadcast_channel_visibility_changed', {
9965
+ logger$_.debug('broadcast_channel_visibility_changed', {
9966
9966
  channel: this.channelName,
9967
9967
  connector_id: this.connectorId,
9968
9968
  visibility: isHidden ? 'hidden' : 'visible',
@@ -9992,7 +9992,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9992
9992
  document.addEventListener('visibilitychange', this.visibilityChangeHandler);
9993
9993
  this.visibilityChangeListenerRegistered = true;
9994
9994
  // Log initial state
9995
- logger$_.info('broadcast_channel_initial_visibility', {
9995
+ logger$_.debug('broadcast_channel_initial_visibility', {
9996
9996
  channel: this.channelName,
9997
9997
  connector_id: this.connectorId,
9998
9998
  visibility: document.hidden ? 'hidden' : 'visible',
@@ -10042,7 +10042,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10042
10042
  return await this.inbox.dequeue();
10043
10043
  }
10044
10044
  async _transportClose(code, reason) {
10045
- logger$_.info('broadcast_channel_transport_closing', {
10045
+ logger$_.debug('broadcast_channel_transport_closing', {
10046
10046
  channel: this.channelName,
10047
10047
  connector_id: this.connectorId,
10048
10048
  code,
@@ -10051,14 +10051,14 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10051
10051
  timestamp: new Date().toISOString(),
10052
10052
  });
10053
10053
  if (this.listenerRegistered) {
10054
- logger$_.info('broadcast_channel_removing_listener', {
10054
+ logger$_.debug('broadcast_channel_removing_listener', {
10055
10055
  channel: this.channelName,
10056
10056
  connector_id: this.connectorId,
10057
10057
  timestamp: new Date().toISOString(),
10058
10058
  });
10059
10059
  this.channel.removeEventListener('message', this.onMsg);
10060
10060
  this.listenerRegistered = false;
10061
- logger$_.info('broadcast_channel_listener_removed', {
10061
+ logger$_.debug('broadcast_channel_listener_removed', {
10062
10062
  channel: this.channelName,
10063
10063
  connector_id: this.connectorId,
10064
10064
  timestamp: new Date().toISOString(),
@@ -10069,13 +10069,13 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10069
10069
  this.visibilityChangeListenerRegistered = false;
10070
10070
  this.visibilityChangeHandler = undefined;
10071
10071
  }
10072
- logger$_.info('broadcast_channel_closing', {
10072
+ logger$_.debug('broadcast_channel_closing', {
10073
10073
  channel: this.channelName,
10074
10074
  connector_id: this.connectorId,
10075
10075
  timestamp: new Date().toISOString(),
10076
10076
  });
10077
10077
  this.channel.close();
10078
- logger$_.info('broadcast_channel_closed', {
10078
+ logger$_.debug('broadcast_channel_closed', {
10079
10079
  channel: this.channelName,
10080
10080
  connector_id: this.connectorId,
10081
10081
  timestamp: new Date().toISOString(),
@@ -10166,6 +10166,28 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10166
10166
  }
10167
10167
  return undefined;
10168
10168
  }
10169
+ /**
10170
+ * Override start() to check initial visibility state
10171
+ */
10172
+ async start(inboundHandler) {
10173
+ await super.start(inboundHandler);
10174
+ // After transitioning to STARTED, check if tab is already hidden
10175
+ if (typeof document !== 'undefined' && document.hidden) {
10176
+ logger$_.debug('broadcast_channel_start_in_hidden_tab', {
10177
+ channel: this.channelName,
10178
+ connector_id: this.connectorId,
10179
+ timestamp: new Date().toISOString(),
10180
+ });
10181
+ // Immediately pause if tab is hidden at start time
10182
+ await this.pause().catch((err) => {
10183
+ logger$_.warning('broadcast_channel_initial_pause_failed', {
10184
+ channel: this.channelName,
10185
+ connector_id: this.connectorId,
10186
+ error: err instanceof Error ? err.message : String(err),
10187
+ });
10188
+ });
10189
+ }
10190
+ }
10169
10191
  _trimSeenAcks(now) {
10170
10192
  while (this.seenAckOrder.length > 0) {
10171
10193
  const candidate = this.seenAckOrder[0];
@@ -10452,6 +10474,7 @@ class UpstreamSessionManager extends TaskSpawner {
10452
10474
  this.lastHeartbeatAckTime = null;
10453
10475
  this.lastSeenEpoch = null;
10454
10476
  this.hadSuccessfulAttach = false;
10477
+ this.lastConnectorState = null;
10455
10478
  this.connectEpoch = 0;
10456
10479
  const options = normalizeOptions$k(optionsInput);
10457
10480
  this.node = options.node;
@@ -10876,15 +10899,26 @@ class UpstreamSessionManager extends TaskSpawner {
10876
10899
  if (stopEvt.isSet() || signal?.aborted) {
10877
10900
  break;
10878
10901
  }
10902
+ const currentState = connector.state;
10903
+ const previousState = this.lastConnectorState;
10904
+ this.lastConnectorState = currentState;
10879
10905
  // Skip heartbeat if connector is paused (e.g., tab is hidden)
10880
10906
  // Keep ack time current so we don't timeout immediately after resuming
10881
- if (connector.state === ConnectorState.PAUSED) {
10907
+ if (currentState === ConnectorState.PAUSED) {
10882
10908
  logger$Z.debug('skipping_heartbeat_connector_paused', {
10883
- connector_state: connector.state,
10909
+ connector_state: currentState,
10884
10910
  });
10885
10911
  this.lastHeartbeatAckTime = Date.now();
10886
10912
  continue;
10887
10913
  }
10914
+ // Reset ack time if just resumed from pause (prevents immediate timeout)
10915
+ if (previousState === ConnectorState.PAUSED && currentState === ConnectorState.STARTED) {
10916
+ logger$Z.debug('connector_just_resumed_resetting_ack_time', {
10917
+ previous_state: previousState,
10918
+ current_state: currentState,
10919
+ });
10920
+ this.lastHeartbeatAckTime = Date.now();
10921
+ }
10888
10922
  const envelope = await this.makeHeartbeatEnvelope();
10889
10923
  logger$Z.debug('sending_heartbeat', {
10890
10924
  hb_corr_id: envelope.corrId,
@@ -546,7 +546,7 @@ class BaseAsyncConnector extends task_spawner_js_1.TaskSpawner {
546
546
  });
547
547
  return;
548
548
  }
549
- logger.info('connector_shutdown_starting', {
549
+ logger.debug('connector_shutdown_starting', {
550
550
  connector_id: this._connectorFlowId,
551
551
  connector_type: this.constructor.name,
552
552
  code,
@@ -576,19 +576,19 @@ class BaseAsyncConnector extends task_spawner_js_1.TaskSpawner {
576
576
  this._sendPromiseResolve = undefined;
577
577
  }
578
578
  // Close transport
579
- logger.info('connector_closing_transport', {
579
+ logger.debug('connector_closing_transport', {
580
580
  connector_id: this._connectorFlowId,
581
581
  connector_type: this.constructor.name,
582
582
  timestamp: new Date().toISOString(),
583
583
  });
584
584
  await this._transportClose(code, reason);
585
- logger.info('connector_transport_closed', {
585
+ logger.debug('connector_transport_closed', {
586
586
  connector_id: this._connectorFlowId,
587
587
  connector_type: this.constructor.name,
588
588
  timestamp: new Date().toISOString(),
589
589
  });
590
590
  // Shutdown spawned tasks
591
- logger.info('connector_shutting_down_tasks', {
591
+ logger.debug('connector_shutting_down_tasks', {
592
592
  connector_id: this._connectorFlowId,
593
593
  connector_type: this.constructor.name,
594
594
  grace_period_ms: effectiveGracePeriod * 1000,
@@ -600,7 +600,7 @@ class BaseAsyncConnector extends task_spawner_js_1.TaskSpawner {
600
600
  gracePeriod: effectiveGracePeriod * 1000, // Convert to milliseconds
601
601
  joinTimeout: this._shutdownJoinTimeout,
602
602
  });
603
- logger.info('connector_tasks_shutdown_complete', {
603
+ logger.debug('connector_tasks_shutdown_complete', {
604
604
  connector_id: this._connectorFlowId,
605
605
  connector_type: this.constructor.name,
606
606
  timestamp: new Date().toISOString(),
@@ -620,7 +620,7 @@ class BaseAsyncConnector extends task_spawner_js_1.TaskSpawner {
620
620
  if (this._closeResolver) {
621
621
  this._closeResolver();
622
622
  }
623
- logger.info('connector_shutdown_complete', {
623
+ logger.debug('connector_shutdown_complete', {
624
624
  connector_id: this._connectorFlowId,
625
625
  connector_type: this.constructor.name,
626
626
  final_state: this._state,
@@ -71,7 +71,7 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
71
71
  this.inbox = new bounded_async_queue_js_1.BoundedAsyncQueue(preferredCapacity);
72
72
  this.connectorId = BroadcastChannelConnector.generateConnectorId();
73
73
  this.channel = new BroadcastChannel(this.channelName);
74
- logger.info('broadcast_channel_connector_created', {
74
+ logger.debug('broadcast_channel_connector_created', {
75
75
  channel: this.channelName,
76
76
  connector_id: this.connectorId,
77
77
  inbox_capacity: preferredCapacity,
@@ -152,7 +152,7 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
152
152
  // Setup visibility change monitoring
153
153
  this.visibilityChangeHandler = () => {
154
154
  const isHidden = document.hidden;
155
- logger.info('broadcast_channel_visibility_changed', {
155
+ logger.debug('broadcast_channel_visibility_changed', {
156
156
  channel: this.channelName,
157
157
  connector_id: this.connectorId,
158
158
  visibility: isHidden ? 'hidden' : 'visible',
@@ -182,7 +182,7 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
182
182
  document.addEventListener('visibilitychange', this.visibilityChangeHandler);
183
183
  this.visibilityChangeListenerRegistered = true;
184
184
  // Log initial state
185
- logger.info('broadcast_channel_initial_visibility', {
185
+ logger.debug('broadcast_channel_initial_visibility', {
186
186
  channel: this.channelName,
187
187
  connector_id: this.connectorId,
188
188
  visibility: document.hidden ? 'hidden' : 'visible',
@@ -232,7 +232,7 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
232
232
  return await this.inbox.dequeue();
233
233
  }
234
234
  async _transportClose(code, reason) {
235
- logger.info('broadcast_channel_transport_closing', {
235
+ logger.debug('broadcast_channel_transport_closing', {
236
236
  channel: this.channelName,
237
237
  connector_id: this.connectorId,
238
238
  code,
@@ -241,14 +241,14 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
241
241
  timestamp: new Date().toISOString(),
242
242
  });
243
243
  if (this.listenerRegistered) {
244
- logger.info('broadcast_channel_removing_listener', {
244
+ logger.debug('broadcast_channel_removing_listener', {
245
245
  channel: this.channelName,
246
246
  connector_id: this.connectorId,
247
247
  timestamp: new Date().toISOString(),
248
248
  });
249
249
  this.channel.removeEventListener('message', this.onMsg);
250
250
  this.listenerRegistered = false;
251
- logger.info('broadcast_channel_listener_removed', {
251
+ logger.debug('broadcast_channel_listener_removed', {
252
252
  channel: this.channelName,
253
253
  connector_id: this.connectorId,
254
254
  timestamp: new Date().toISOString(),
@@ -259,13 +259,13 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
259
259
  this.visibilityChangeListenerRegistered = false;
260
260
  this.visibilityChangeHandler = undefined;
261
261
  }
262
- logger.info('broadcast_channel_closing', {
262
+ logger.debug('broadcast_channel_closing', {
263
263
  channel: this.channelName,
264
264
  connector_id: this.connectorId,
265
265
  timestamp: new Date().toISOString(),
266
266
  });
267
267
  this.channel.close();
268
- logger.info('broadcast_channel_closed', {
268
+ logger.debug('broadcast_channel_closed', {
269
269
  channel: this.channelName,
270
270
  connector_id: this.connectorId,
271
271
  timestamp: new Date().toISOString(),
@@ -356,6 +356,28 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
356
356
  }
357
357
  return undefined;
358
358
  }
359
+ /**
360
+ * Override start() to check initial visibility state
361
+ */
362
+ async start(inboundHandler) {
363
+ await super.start(inboundHandler);
364
+ // After transitioning to STARTED, check if tab is already hidden
365
+ if (typeof document !== 'undefined' && document.hidden) {
366
+ logger.debug('broadcast_channel_start_in_hidden_tab', {
367
+ channel: this.channelName,
368
+ connector_id: this.connectorId,
369
+ timestamp: new Date().toISOString(),
370
+ });
371
+ // Immediately pause if tab is hidden at start time
372
+ await this.pause().catch((err) => {
373
+ logger.warning('broadcast_channel_initial_pause_failed', {
374
+ channel: this.channelName,
375
+ connector_id: this.connectorId,
376
+ error: err instanceof Error ? err.message : String(err),
377
+ });
378
+ });
379
+ }
380
+ }
359
381
  _trimSeenAcks(now) {
360
382
  while (this.seenAckOrder.length > 0) {
361
383
  const candidate = this.seenAckOrder[0];
@@ -112,6 +112,7 @@ class UpstreamSessionManager extends task_spawner_js_1.TaskSpawner {
112
112
  this.lastHeartbeatAckTime = null;
113
113
  this.lastSeenEpoch = null;
114
114
  this.hadSuccessfulAttach = false;
115
+ this.lastConnectorState = null;
115
116
  this.connectEpoch = 0;
116
117
  const options = normalizeOptions(optionsInput);
117
118
  this.node = options.node;
@@ -536,15 +537,26 @@ class UpstreamSessionManager extends task_spawner_js_1.TaskSpawner {
536
537
  if (stopEvt.isSet() || signal?.aborted) {
537
538
  break;
538
539
  }
540
+ const currentState = connector.state;
541
+ const previousState = this.lastConnectorState;
542
+ this.lastConnectorState = currentState;
539
543
  // Skip heartbeat if connector is paused (e.g., tab is hidden)
540
544
  // Keep ack time current so we don't timeout immediately after resuming
541
- if (connector.state === core_1.ConnectorState.PAUSED) {
545
+ if (currentState === core_1.ConnectorState.PAUSED) {
542
546
  logger.debug('skipping_heartbeat_connector_paused', {
543
- connector_state: connector.state,
547
+ connector_state: currentState,
544
548
  });
545
549
  this.lastHeartbeatAckTime = Date.now();
546
550
  continue;
547
551
  }
552
+ // Reset ack time if just resumed from pause (prevents immediate timeout)
553
+ if (previousState === core_1.ConnectorState.PAUSED && currentState === core_1.ConnectorState.STARTED) {
554
+ logger.debug('connector_just_resumed_resetting_ack_time', {
555
+ previous_state: previousState,
556
+ current_state: currentState,
557
+ });
558
+ this.lastHeartbeatAckTime = Date.now();
559
+ }
548
560
  const envelope = await this.makeHeartbeatEnvelope();
549
561
  logger.debug('sending_heartbeat', {
550
562
  hb_corr_id: envelope.corrId,
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  // This file is auto-generated during build - do not edit manually
3
- // Generated from package.json version: 0.3.5-test.936
3
+ // Generated from package.json version: 0.3.5-test.938
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.VERSION = void 0;
6
6
  /**
7
7
  * The package version, injected at build time.
8
8
  * @internal
9
9
  */
10
- exports.VERSION = '0.3.5-test.936';
10
+ exports.VERSION = '0.3.5-test.938';
@@ -542,7 +542,7 @@ export class BaseAsyncConnector extends TaskSpawner {
542
542
  });
543
543
  return;
544
544
  }
545
- logger.info('connector_shutdown_starting', {
545
+ logger.debug('connector_shutdown_starting', {
546
546
  connector_id: this._connectorFlowId,
547
547
  connector_type: this.constructor.name,
548
548
  code,
@@ -572,19 +572,19 @@ export class BaseAsyncConnector extends TaskSpawner {
572
572
  this._sendPromiseResolve = undefined;
573
573
  }
574
574
  // Close transport
575
- logger.info('connector_closing_transport', {
575
+ logger.debug('connector_closing_transport', {
576
576
  connector_id: this._connectorFlowId,
577
577
  connector_type: this.constructor.name,
578
578
  timestamp: new Date().toISOString(),
579
579
  });
580
580
  await this._transportClose(code, reason);
581
- logger.info('connector_transport_closed', {
581
+ logger.debug('connector_transport_closed', {
582
582
  connector_id: this._connectorFlowId,
583
583
  connector_type: this.constructor.name,
584
584
  timestamp: new Date().toISOString(),
585
585
  });
586
586
  // Shutdown spawned tasks
587
- logger.info('connector_shutting_down_tasks', {
587
+ logger.debug('connector_shutting_down_tasks', {
588
588
  connector_id: this._connectorFlowId,
589
589
  connector_type: this.constructor.name,
590
590
  grace_period_ms: effectiveGracePeriod * 1000,
@@ -596,7 +596,7 @@ export class BaseAsyncConnector extends TaskSpawner {
596
596
  gracePeriod: effectiveGracePeriod * 1000, // Convert to milliseconds
597
597
  joinTimeout: this._shutdownJoinTimeout,
598
598
  });
599
- logger.info('connector_tasks_shutdown_complete', {
599
+ logger.debug('connector_tasks_shutdown_complete', {
600
600
  connector_id: this._connectorFlowId,
601
601
  connector_type: this.constructor.name,
602
602
  timestamp: new Date().toISOString(),
@@ -616,7 +616,7 @@ export class BaseAsyncConnector extends TaskSpawner {
616
616
  if (this._closeResolver) {
617
617
  this._closeResolver();
618
618
  }
619
- logger.info('connector_shutdown_complete', {
619
+ logger.debug('connector_shutdown_complete', {
620
620
  connector_id: this._connectorFlowId,
621
621
  connector_type: this.constructor.name,
622
622
  final_state: this._state,