From 36df7481c9e634b90a077afad28766d2cc2787d7 Mon Sep 17 00:00:00 2001 From: Mikei386 <44135113+Mikei386@users.noreply.github.com> Date: Tue, 27 Oct 2026 07:09:13 +0100 Subject: [PATCH] Fix Safari idle-callback crash in Hermes Webapp test build --- .../hermes-unraid/webapp-test/README.md | 46 +++++++++++++++- .../webapp-test/safari-fix/apply.py | 43 +++++++++++++++ .../webapp-test/safari-fix/prepare-upgrade.py | 25 +++++++++ .../webapp-test/safari-fix/source.patch | 21 ++++++++ .../safari-fix/test-safari-idle.mjs | 53 +++++++++++++++++++ 5 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 integrations/hermes-unraid/webapp-test/safari-fix/apply.py create mode 100644 integrations/hermes-unraid/webapp-test/safari-fix/prepare-upgrade.py create mode 100644 integrations/hermes-unraid/webapp-test/safari-fix/source.patch create mode 100644 integrations/hermes-unraid/webapp-test/safari-fix/test-safari-idle.mjs diff --git a/integrations/hermes-unraid/webapp-test/README.md b/integrations/hermes-unraid/webapp-test/README.md index 1369abb..ce89f3b 100644 --- a/integrations/hermes-unraid/webapp-test/README.md +++ b/integrations/hermes-unraid/webapp-test/README.md @@ -19,8 +19,9 @@ a development-build test, not a claim of a released, manufacturer-built image. - The stock Dockerfile omits Desktop source and does not build its Webapp. Our packaging-only change admits `apps/desktop` to the build context, runs upstream `node apps/desktop/scripts/build-webapp.mjs` in the frontend build - stage and copies its output into the runtime image. No Hermes application - code is patched. This packaging extension is ours, not an upstream image. + stage and copies its output into the runtime image. The initial image did + not patch Hermes application code. The later Safari compatibility fix below + is a separate local application patch. Neither image is an upstream image. - Build instructions and output are retained in `build/`; Docker manages the actual image layers in its own storage, not as loose image archives. @@ -121,3 +122,44 @@ by a working browser page. not a claim that browser behavior is identical. Production files are intact. - Native Mac/Conduit behavior and actual model/audio/browser/plugin actions remain untested. This operation initiated no inference or delivery tests. + +## Safari Advanced-editor fix — 27 October 2026 + +Reproduced in Michael's actual Safari: Edit bot → Advanced unmounted the bot +pane with `Can't find variable: requestIdleCallback`. The public catalog's +`prefetchCatalogWhenIdle()` called idle APIs without checking availability. + +Local patch: [safari-fix/apply.py](safari-fix/apply.py). Uses native idle callbacks +when both scheduling and cancellation APIs exist; otherwise uses a cancellable +100-ms timeout. It changes speculative catalog prefetch only, not permissions, +SOUL contents, model configuration or the native Mac application. + +The build runs [four targeted regression checks](safari-fix/test-safari-idle.mjs) +against the actual patched scheduler: native/fallback execution and cancellation. +All four passed before renderer compilation. The checks use no network/model. + +Image: `local/hermes-webapp-test:e5f2b153-safari1`, ID +`sha256:45e0c9dfeff1d27a43ebf0ce9deaebaea16dcfb74f7debf9769563f2c19a56f8`. +Source patch, tests, build log, updated build recipe and image ID stay under the +same test root. The previous unpatched image is retained for rollback; cleanup +must remove both test tags after removing the test container. + +[prepare-upgrade.py](safari-fix/prepare-upgrade.py) prepares private Docker create +requests from the **current test container**, preserving its environment, +mounts, ports, limits and restart policy. It does not recopy old production +data over newer test chats. Private requests stay mode `0600` on NAS, outside Git. +Only the idle test container was recreated; original Hermes and VPN containers +were not operated. Browser acceptance and the post-start audit are recorded +after the actual checks; compiled code alone is not Safari acceptance. + +Actual Safari acceptance passed on the existing HTTPS proxy, with the existing +authenticated browser session: William → Edit → Advanced opened without the +previous `requestIdleCallback`/render error. Provider/model and capabilities +loaded; switching the capabilities tab from Skills to Tools exposed the SOUL.md +field in the native accessibility tree. Canceled the editor without saving. +No capabilities, avatar, model, SOUL or other bot setting was changed by the test. +A separate Safari tab was used to preserve the user's original working tab. +Existing open tabs need a reload to receive the new compiled asset hashes. +Post-start fleet audit is unchanged at 278/280: only the two documented legacy +`/etc/hermes` symlink assertions differ from this environment-based bootstrap. +The test runs with zero Docker restarts; original production remains stopped. diff --git a/integrations/hermes-unraid/webapp-test/safari-fix/apply.py b/integrations/hermes-unraid/webapp-test/safari-fix/apply.py new file mode 100644 index 0000000..428f402 --- /dev/null +++ b/integrations/hermes-unraid/webapp-test/safari-fix/apply.py @@ -0,0 +1,43 @@ +"""Apply the bounded Safari fix to the pinned public source, not live data.""" +from pathlib import Path +import difflib + +root = Path('/test/build/source') +target = root / 'apps/desktop/src/app/capabilities/catalog/catalog-data.ts' +old = '''export function prefetchCatalogWhenIdle(kind: CatalogKind) { + const id = requestIdleCallback(() => void queryClient.prefetchQuery(catalogQuery(kind)), { timeout: 5_000 }) + + return () => cancelIdleCallback(id) +}''' +new = '''export function prefetchCatalogWhenIdle(kind: CatalogKind) { + const prefetch = () => void queryClient.prefetchQuery(catalogQuery(kind)) + + // Safari may not provide idle callbacks. Keep speculative prefetch optional + // and cancellable instead of crashing the entire bot editor. + if (typeof requestIdleCallback === 'function' && typeof cancelIdleCallback === 'function') { + const id = requestIdleCallback(prefetch, { timeout: 5_000 }) + + return () => cancelIdleCallback(id) + } + + const id = setTimeout(prefetch, 100) + + return () => clearTimeout(id) +}''' +text = target.read_text() +if new not in text: + assert text.count(old) == 1, 'Pinned source changed: refusing a speculative patch' + target.write_text(text.replace(old, new)) +patch = ''.join(difflib.unified_diff(text.splitlines(True), target.read_text().splitlines(True), + fromfile='a/apps/desktop/src/app/capabilities/catalog/catalog-data.ts', + tofile='b/apps/desktop/src/app/capabilities/catalog/catalog-data.ts', n=0)) +if patch: + Path('/test/build/safari-idle.patch').write_text(patch) +dockerfile = root / 'Dockerfile.webapp' +text = dockerfile.read_text() +old_run = 'RUN node apps/desktop/scripts/build-webapp.mjs' +new_run = 'RUN node scripts/test-safari-idle.mjs && node apps/desktop/scripts/build-webapp.mjs' +if new_run not in text: + assert text.count(old_run) == 1 + dockerfile.write_text(text.replace(old_run, new_run)) +print('Applied Safari idle callback fallback; build runs the regression checks first.') diff --git a/integrations/hermes-unraid/webapp-test/safari-fix/prepare-upgrade.py b/integrations/hermes-unraid/webapp-test/safari-fix/prepare-upgrade.py new file mode 100644 index 0000000..726f81e --- /dev/null +++ b/integrations/hermes-unraid/webapp-test/safari-fix/prepare-upgrade.py @@ -0,0 +1,25 @@ +"""Prepare private Docker requests for ONLY the existing Webapp test container.""" +import json +from pathlib import Path + +root = Path('/test/build') +old = json.loads((root/'pre-safari-container.private.json').read_text())[0] +assert old['Name'] == '/Hermes-Webapp-Test' +assert old['Image'] == 'sha256:95a5bb76a1683292a3fe87464d62f17711b43afb796864aa759a8205f421a9aa' +assert old['HostConfig']['NetworkMode'].startswith('container:') +binds = old['HostConfig'].get('Binds') or [] +assert len(binds) == 1 +assert binds[0].split(':')[:2] == ['/mnt/nvme-storage/appdata/Hermes-Webapp-Test/data','/opt/data'] +for filename, image in ( + ('rollback-create.private.json', old['Image']), + ('safari-create.private.json', (root/'image-safari.id').read_text().strip()), +): + config = old['Config'].copy() + config.pop('Hostname', None) + config.pop('Domainname', None) + config['Image'] = image + body = {**config, 'HostConfig': old['HostConfig']} + p = root/filename + p.write_text(json.dumps(body)) + p.chmod(0o600) +print('Prepared upgrade and rollback requests; test data, environment and network settings preserved.') diff --git a/integrations/hermes-unraid/webapp-test/safari-fix/source.patch b/integrations/hermes-unraid/webapp-test/safari-fix/source.patch new file mode 100644 index 0000000..0276771 --- /dev/null +++ b/integrations/hermes-unraid/webapp-test/safari-fix/source.patch @@ -0,0 +1,21 @@ +--- a/apps/desktop/src/app/capabilities/catalog/catalog-data.ts ++++ b/apps/desktop/src/app/capabilities/catalog/catalog-data.ts +@@ -300,4 +300,14 @@ +- const id = requestIdleCallback(() => void queryClient.prefetchQuery(catalogQuery(kind)), { timeout: 5_000 }) +- +- return () => cancelIdleCallback(id) +-} ++ const prefetch = () => void queryClient.prefetchQuery(catalogQuery(kind)) ++ ++ // Safari may not provide idle callbacks. Keep speculative prefetch optional ++ // and cancellable instead of crashing the entire bot editor. ++ if (typeof requestIdleCallback === 'function' && typeof cancelIdleCallback === 'function') { ++ const id = requestIdleCallback(prefetch, { timeout: 5_000 }) ++ ++ return () => cancelIdleCallback(id) ++ } ++ ++ const id = setTimeout(prefetch, 100) ++ ++ return () => clearTimeout(id) ++} diff --git a/integrations/hermes-unraid/webapp-test/safari-fix/test-safari-idle.mjs b/integrations/hermes-unraid/webapp-test/safari-fix/test-safari-idle.mjs new file mode 100644 index 0000000..324ae69 --- /dev/null +++ b/integrations/hermes-unraid/webapp-test/safari-fix/test-safari-idle.mjs @@ -0,0 +1,53 @@ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import vm from 'node:vm' +import ts from 'typescript' + +// Execute the actual scheduler from the patched source, with only its catalog +// and browser scheduling dependencies stubbed. No requests or services run. +const source = readFileSync('apps/desktop/src/app/capabilities/catalog/catalog-data.ts', 'utf8') +const start = source.lastIndexOf('export function prefetchCatalogWhenIdle(') +assert.ok(start >= 0) +const js = ts.transpileModule(source.slice(start).replace('export function', 'function'), { + compilerOptions: { target: ts.ScriptTarget.ES2022 } +}).outputText + +function fixture(native = false) { + let calls = 0 + let queued + let cleared + const context = { + catalogQuery: kind => kind, + queryClient: { prefetchQuery: () => { calls++ } }, + setTimeout: (fn, delay) => { assert.equal(delay, 100); queued = fn; return 11 }, + clearTimeout: id => { cleared = id; queued = undefined } + } + if (native) { + context.requestIdleCallback = (fn, options) => { + assert.equal(options.timeout, 5000); queued = fn; return 22 + } + context.cancelIdleCallback = id => { cleared = id; queued = undefined } + } + vm.createContext(context) + vm.runInContext(js, context) + return { + start: () => context.prefetchCatalogWhenIdle('skills'), + flush: () => queued?.(), + calls: () => calls, + cleared: () => cleared + } +} + +for (const native of [false, true]) { + const run = fixture(native) + run.start() + assert.equal(run.calls(), 0) + run.flush() + assert.equal(run.calls(), 1) + const cancel = fixture(native) + cancel.start()() + cancel.flush() + assert.equal(cancel.calls(), 0) + assert.equal(cancel.cleared(), native ? 22 : 11) +} +console.log('Safari scheduler regression: 4 checks passed (fallback/native execution and cancellation).')