@mentra/crust 3.5.0-dev.1359 → 3.5.0-dev.1363

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.
@@ -184,12 +184,11 @@ public final class JSCRuntime: NSObject {
184
184
  // "ready", []) flips the record's readyAcked flag (see
185
185
  // markReady). If we never see the ack, the timer logs a hung
186
186
  // context warning so observability picks it up.
187
- armReadyNackTimer(record: record, timeoutSeconds: Self.coldStartNackTimeoutSeconds, cold: true)
188
-
189
187
  // All evaluation happens on `queue`. We `sync` for the bootstrap so
190
188
  // the caller knows whether spawn succeeded before returning.
191
189
  var success = true
192
190
  queue.sync {
191
+ self.armReadyNackTimer(record: record, timeoutSeconds: Self.coldStartNackTimeoutSeconds, cold: true)
193
192
  self.installNativeBridges(ctx: ctx, record: record)
194
193
  success = self.evaluateCatching(record: record, label: "polyfill", source: polyfillBundle)
195
194
  if success {
@@ -216,42 +215,48 @@ public final class JSCRuntime: NSObject {
216
215
  }
217
216
  }
218
217
 
219
- /// Schedule (or re-schedule) a NACK timer for the next message
220
- /// delivery. Resets every time the host pushes to the JSContext.
218
+ /// Schedule (or re-schedule) the NACK timer. Call on `record.queue`, the
219
+ /// only queue that touches `readyNackTimer`, right before the work it
220
+ /// guards, and cancel it there once that work returns.
221
+ ///
222
+ /// The timer fires on `watchdogScheduler`, not `record.queue`: a handler
223
+ /// on the context's own queue can't run while an evaluate blocks that
224
+ /// queue, so it could never report a slow one. It was also armed with
225
+ /// `record.queue.async` from a block already on that queue, which queued
226
+ /// the arming behind the delivery: the delivery's cancel ran first, and
227
+ /// every delivery then raised `ready_nack` 3s after it had finished.
221
228
  private func armReadyNackTimer(record: Context, timeoutSeconds: TimeInterval, cold: Bool) {
222
- record.queue.async {
223
- record.readyNackTimer?.cancel()
224
- let timer = DispatchSource.makeTimerSource(queue: record.queue)
225
- timer.schedule(deadline: .now() + timeoutSeconds)
226
- timer.setEventHandler { [weak self, weak record] in
227
- guard let self, let record else { return }
228
- let phase = cold ? "cold-start" : "steady-state"
229
- os_log("MentraJS NACK: %{public}@ %{public}@ ready signal not received in %.0fs",
230
- log: Self.log, type: .error,
231
- record.packageName, phase, timeoutSeconds)
232
- // Surface to RN as a recoverable error frame so the
233
- // crash controller (if wired) can decide whether to
234
- // respawn. We don't auto-kill — the spec says "host
235
- // dispatchToJs returns an error to its caller"; we
236
- // emit a structured event instead.
237
- self.lock.withLock { self._onOutbound }?(
238
- OutboundMessage(
239
- packageName: record.packageName,
240
- payload: [
241
- "packageName": record.packageName,
242
- "iface": "__error",
243
- "method": "ready_nack",
244
- "argsJson": JSCRuntime.jsonString(
245
- from: ["phase": phase, "timeoutSeconds": timeoutSeconds],
246
- ) ?? "{}",
247
- ],
248
- )
229
+ record.readyNackTimer?.cancel()
230
+ let packageName = record.packageName
231
+ let timer = DispatchSource.makeTimerSource(queue: Self.watchdogScheduler)
232
+ timer.schedule(deadline: .now() + timeoutSeconds)
233
+ timer.setEventHandler { [weak self] in
234
+ guard let self else { return }
235
+ let phase = cold ? "cold-start" : "steady-state"
236
+ os_log("MentraJS NACK: %{public}@ %{public}@ ready signal not received in %.0fs",
237
+ log: Self.log, type: .error,
238
+ packageName, phase, timeoutSeconds)
239
+ // Surface to RN as a recoverable error frame so the
240
+ // crash controller (if wired) can decide whether to
241
+ // respawn. We don't auto-kill — the spec says "host
242
+ // dispatchToJs returns an error to its caller"; we
243
+ // emit a structured event instead.
244
+ self.lock.withLock { self._onOutbound }?(
245
+ OutboundMessage(
246
+ packageName: packageName,
247
+ payload: [
248
+ "packageName": packageName,
249
+ "iface": "__error",
250
+ "method": "ready_nack",
251
+ "argsJson": JSCRuntime.jsonString(
252
+ from: ["phase": phase, "timeoutSeconds": timeoutSeconds],
253
+ ) ?? "{}",
254
+ ],
249
255
  )
250
- record.readyNackTimer = nil
251
- }
252
- record.readyNackTimer = timer
253
- timer.resume()
256
+ )
254
257
  }
258
+ record.readyNackTimer = timer
259
+ timer.resume()
255
260
  }
256
261
 
257
262
  /// Diagnostic: force a JSC garbage-collection cycle on the named
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/crust",
3
- "version": "3.5.0-dev.1359",
3
+ "version": "3.5.0-dev.1363",
4
4
  "description": "Mentra Native Module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "license": "Apache-2.0",
36
36
  "homepage": "https://github.com/Mentra-Community/MentraOS/tree/dev/mobile/modules/crust#readme",
37
37
  "dependencies": {
38
- "@mentra/jspolyfill": "3.5.0-dev.1359"
38
+ "@mentra/jspolyfill": "3.5.0-dev.1363"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@expo/config-plugins": ">=8.0.0",