Skip to content

[Bug]: Hermes Desktop renderer crashes with "tapClientLookup: Index N out of bounds" → root error-boundary forces "Reload window" #41693

Closed

Description

@iizus

Bug Description

The Hermes Desktop renderer crashes intermittently with tapClientLookup: Index N out of bounds (length: M) errors thrown from @assistant-ui/store. When this fires, the root error-boundary catches it and the UI shows the "Reload window" error screen, requiring the user to manually reload (or restart the app) to recover the chat.

The frequency has increased noticeably over the last few days of normal use (multiple hits per day).

Representative log excerpts from ~/.hermes/logs/desktop.log (renderer console relayed by Electron main):

[renderer console] Error: tapClientLookup: Index 0  out of bounds (length: 0)   .../dist/assets/index-CDQNplt5.js:8
[renderer console] Error: tapClientLookup: Index 5  out of bounds (length: 5)   .../dist/assets/index-DPLdCuM3.js:8
[renderer console] Error: tapClientLookup: Index 10 out of bounds (length: 8)   .../dist/assets/index-DPLdCuM3.js:8
[renderer console] Error: tapClientLookup: Index 23 out of bounds (length: 18)  .../dist/assets/index-DPLdCuM3.js:8
[renderer console] [error-boundary:root] Error: tapClientLookup: Index 0  out of bounds (length: 0)
[renderer console] [error-boundary:root] Error: tapClientLookup: Index 5  out of bounds (length: 5)
[renderer console] [error-boundary:root] Error: tapClientLookup: Index 10 out of bounds (length: 8)
[renderer console] [error-boundary:root] Error: tapClientLookup: Index 23 out of bounds (length: 18)
[renderer console] Uncaught Error: Minified React error #520; visit https://react.dev/errors/520
[renderer console] Error: Tried to unmount a fiber that is already unmounted
[renderer console] [error-boundary:root] Error: Tried to unmount a fiber that is already unmounted

Often co-occurring (probably a downstream symptom of the same race):

[renderer console] Uncaught (in promise) Error: Error invoking remote method 'hermes:api': Error: 404: {"detail":"Session not found"}

Steps to Reproduce

The error is timing-sensitive but the following sequences reproduce it most reliably for me on Hermes Desktop 0.16.0:

  1. Start a long chat with multiple tool calls / streaming responses (so messages.length grows past ~10–20).
  2. Switch sessions in the sidebar (or open a session whose backend record has been pruned), or
  3. Cancel an in-flight streaming response and immediately switch / reload the thread, or
  4. Have an external process modify the active session while the UI is open.
  5. Within ~1 second of the message list shrinking (e.g. messages re-fetched, session swap), the renderer throws tapClientLookup: Index N out of bounds (length: M) where N >= M, the root error-boundary fires, and the chat is replaced by the "Reload window" screen.

The exact N/M pair varies (0/0, 5/5, 10/8, 23/18 observed), suggesting a stale index captured from a previous render is being used after the underlying array was shortened.

Expected Behavior

  • A transient inconsistency between rendered indices and keys.length should not crash the entire app surface.
  • At minimum, an out-of-bounds lookup should resolve to a safe no-op (or undefined) and let React reconcile on the next render, rather than throwing and tearing down the root.
  • The user should not have to "Reload window" to recover from what is logically a one-frame race.

Actual Behavior

  • @assistant-ui/store@0.2.9 tapClientLookup({ index }) throws synchronously when lookup.index >= keys.length, which propagates out of the assistant-ui runtime client hooks (thread-runtime-client, composer-runtime-client, message-runtime-client, thread-list-runtime-client, suggestions, thread-message-client).
  • The root error-boundary in Hermes Desktop catches the throw and replaces the UI with the "Reload window" screen.
  • A secondary Tried to unmount a fiber that is already unmounted (React Feature: Tool Call Repair Middleware — Auto-Lowercase + Invalid Tool Handler (inspired by Kilocode) #520) sometimes follows, consistent with the renderer being torn down mid-commit.
  • Recovery requires Reload Window or full app restart.

Affected Component

Other (Hermes Desktop renderer / @assistant-ui integration)

Debug Report

Cannot share — the desktop / agent logs contain confidential conversation content from work usage. Happy to share sanitized excerpts privately on request. The renderer-console excerpts above are scrubbed and should be sufficient to localize the issue.

Operating System

macOS 26.5 (Apple Silicon, M4)

Python Version

n/a (renderer issue)

Hermes Version

Hermes Desktop 0.16.0 (release date 2026.6.5), built from main @ 2b119baac

Additional Logs / Traceback (optional)

The throwing function is @assistant-ui/store@0.2.9 tapClientLookup:

// node_modules/@assistant-ui/store/dist/tapClientLookup.js
export function tapClientLookup(getElements, getElementsDeps) {
    const resources = tapResources(...);
    const keys = tapMemo(() => Object.keys(resources), [resources]);
    ...
    return {
        state,
        get: (lookup) => {
            if ("index" in lookup) {
                if (lookup.index < 0 || lookup.index >= keys.length) {
                    throw new Error(`tapClientLookup: Index ${lookup.index} out of bounds (length: ${keys.length})`);
                }
                return resources[lookup.index].methods;
            }
            ...
        },
    };
}

Callers in @assistant-ui/core@* that pass an index derived from a possibly-stale snapshot:

  • runtime-clients/thread-runtime-client.js — runtimeState.messages.map((m, idx) => ...)
  • runtime-clients/composer-runtime-client.js — runtimeState.attachments.map((attachment, idx) => ...)
  • runtime-clients/message-runtime-client.js — runtimeState.content.map((part, idx) => ...) and runtimeState.attachments.map(...)
  • runtime-clients/thread-list-runtime-client.js — Object.keys(runtimeState.threadItems).map(...)
  • clients/thread-message-client.js — message.content.map((part, idx) => ...) and message.attachments
  • clients/suggestions.js — state.suggestions.map(...)

When the underlying array shrinks (session switch, message cancellation, external truncation, or thread-list refresh) and a child component re-renders with a captured index that no longer exists, the throw kills the whole tree.

Root Cause Analysis (optional)

Two-layer race:

  1. Hermes Desktop side: state updates that shrink the message / thread / attachment arrays (e.g. session swap, Session not found 404 from hermes:api, externally truncated session) are not consistently sequenced with the children that consume tapClientLookup({ index }). A stale child momentarily holds an index from the previous render and queries the store with it.
  2. @assistant-ui/store side: tapClientLookup's index path throws on every out-of-bound query instead of returning undefined (or another non-throwing sentinel). This makes the library brittle against any renderer race in any host app.

Repo grep confirms Hermes Desktop does not use tapClientLookup directly — all call sites are inside node_modules/@assistant-ui/{core,store} — so this is an interaction bug between Hermes' state lifecycle and the assistant-ui runtime.

Proposed Fix (optional)

Two complementary mitigations; either alone reduces the user-visible "Reload window" rate, both together should eliminate it:

A. Hermes Desktop — guard the root error-boundary against this throw class.
Treat tapClientLookup: Index ... out of bounds (and Tried to unmount a fiber that is already unmounted) as recoverable: log + reset the boundary and let React re-render with fresh state on the next tick, instead of replacing the entire UI with the "Reload window" screen. This preserves the chat across the inevitable one-frame races.

B. Hermes Desktop — sequence array-shrinking state transitions so children unmount before the store snapshot is committed.
Concretely, on session switch / Session not found recovery / external session truncation, clear the child runtime (messages: [] / detach thread runtime) before mutating the underlying session list, so no child renders against the new (shorter) array with an old index. The Session not found 404s in the same log block are a strong hint that the renderer is briefly pointing at a session whose state has been torn down.

C. Upstream @assistant-ui/store (out of scope for this repo but worth filing):
Switch tapClientLookup({ index }).get() from throw to undefined for the index path (the key path can keep its current behavior), so any host-app race becomes a missing-leaf-render instead of a tree-killing exception. Happy to file that upstream too if the maintainers here would like — flag in this issue.

I'd start with A since it's a one-file change in Hermes Desktop that immediately stops the "Reload window" UX regression for every user.

Are you willing to submit a PR for this?

Cannot push to external forks from my current environment (Amazon Code Defender). Happy to keep iterating in this issue if the maintainers want a verified diff for option A — just let me know which surface (error-boundary component path) you'd like the guard wired into.

Notes

  • I run an unrelated set of local UI patches (preview width caps, file-tree, mermaid rendering, IME) on local/patches. None of them touch @assistant-ui runtime clients, message state, or session lifecycle, and the throw originates entirely inside node_modules/@assistant-ui/{core,store} — so the race is independent of the local patch set.
  • Verified locally on macOS 26.5 / Apple Silicon, Hermes Desktop 0.16.0, @assistant-ui/store@0.2.9, @assistant-ui/react@^0.12.28.

Activity

  1. added
    type/bugSomething isn't working
    P3Low — cosmetic, nice to have
    on Jun 8, 2026
  2. JakubMerkandi commented on Jun 11, 2026

    @JakubMerkandi

    Confirming this also affects our Hermes Desktop setup.

    We are seeing the same renderer crash in ~/.hermes/logs/desktop.log, for example:

    [renderer console] Error: tapClientLookup: Index 6 out of bounds (length: 1)
    [renderer console] [error-boundary:root] Error: tapClientLookup: Index 6 out of bounds (length: 1)
        at UserMessage
    

    and later:

    [renderer console] Error: tapClientLookup: Index 8 out of bounds (length: 1)
    [renderer console] [error-boundary:root] Error: tapClientLookup: Index 8 out of bounds (length: 1)
        at UserMessage
    

    In practice this does appear to kill the Desktop UI / leave it in the root error boundary state, while the backend process continues running.

    One observation from local debugging: the failing path seems consistent with a stale ThreadPrimitive.MessageByIndex render after the assistant-ui runtime has already switched/reduced the message list. The virtualized thread can still have an old message index mounted for a render, and that stale index then reaches tapClientLookup.

    So #41787 looks useful as a recovery mitigation, but there may also be a lower-level fix in the Desktop thread virtualizer to avoid rendering stale MessageByIndex entries in the first place.

  3. whisky0809 commented on Jun 12, 2026

    @whisky0809

    Root cause (and a caveat for #41787)

    The throw is the index path of @assistant-ui/store's tapClientLookup, which throws whenever a consumer resolves {index} that is >= keys.length. The underlying race is in assistant-ui itself: a Derived scope's lookup closure lagged one commit behind (tapEffectEvent), so a child mounted with a stale index could resolve it against an already-shortened message list. assistant-ui fixed that in @assistant-ui/store@0.2.11 (commit db721df, "key Derived scopes by {source, query} so a meta change produces a new client function in the same render pass").

    Bumping the dependency is not a clean fix here, though, for two reasons:

    1. 0.2.11 alone did not stop the crash in the packaged Desktop app. I bumped @assistant-ui/store to 0.2.11 (and verified the new fiber-keying was present in the built bundle) — the renderer still threw tapClientLookup: Index 14 out of bounds (length: 4) from UserMessage when switching from a long chat to a short one, deterministically. A mounted MessageByIndex reads an unchanged-but-now-stale index during the session-shrink window, which 0.2.11's fix doesn't cover. The repro in fix(desktop): recover root boundary from transient render races #41787 stops throwing on 0.2.11, but the real packaged app still does — the surviving path only reproduces with the real virtualizer/scroll timing, not in jsdom.

    2. Can't simply track the latest store. @assistant-ui/store@0.2.14 renames tapClientLookup → useClientLookup, which is incompatible with the @assistant-ui/core@0.1.17 pinned transitively via @assistant-ui/react@^0.12.28. A >=0.2.11 range that floats into 0.2.14 breaks the build, so you'd need an exact 0.2.11/<0.2.12 pin — awkward against the repo's dependency-range policy.

    On the #41787 error-boundary approach (which does work as a user-visible mitigation): worth guarding against thrash. As written, a recoverable error that recurs every frame loops catch → reset → throw indefinitely. A bounded recovery budget (e.g. max N resets within a short window, then leave the fallback latched) stops a genuinely persistent error from spinning. I confirmed the unbounded-loop behavior with a test against that boundary.

    Environment: Hermes Desktop on native Windows 11, built from local main; @assistant-ui/store@0.2.9 baseline, @assistant-ui/react@^0.12.28, @assistant-ui/core@0.1.17.

  4. supplefrog commented on Jun 12, 2026

    @supplefrog

    Additional repro evidence from Windows Desktop current local build/source:

    • Hermes Agent repo: NousResearch/hermes-agent
    • Local source HEAD: a118b94a8
    • Desktop package version: 0.15.1
    • Platform: Windows 10
    • Screenshot UI text: root error screen shows Something broke in the interface with tapClientLookup: Index 14 out of bounds (length: 8) and buttons Retry, Reload window, Open logs.

    The latest local desktop.log shows the crash is still escaping to the root error boundary from UserMessage, including during/around long-context compression and after app/backend restart:

    [hermes] 📦 Preflight compression: ~249,248 tokens >= 231,200 threshold. This may take a moment.
    [hermes] 🗜️ Compacting context — summarizing earlier conversation so I can continue...
    [hermes] [renderer console] Error: tapClientLookup: Index 14 out of bounds (length: 8) (file:///C:/Users/<user>/AppData/Local/hermes/hermes-agent/apps/desktop/release/win-unpacked/resources/app.asar/dist/assets/index-CWGDLRdZ.js:8)
    [hermes] [renderer console] [error-boundary:root] Error: tapClientLookup: Index 14 out of bounds (length: 8)
    [hermes]     at Kqt (.../dist/assets/index-CWGDLRdZ.js:801:11969)
    [hermes]     at UserMessage (<anonymous>)
    

    Earlier in the same log there are repeated variants:

    [renderer console] Error: tapClientLookup: Index 4 out of bounds (length: 2)
    [renderer console] [error-boundary:root] Error: tapClientLookup: Index 4 out of bounds (length: 2)
        at UserMessage (<anonymous>)
    
    [renderer console] Error: tapClientLookup: Index 8 out of bounds (length: 8)
    [renderer console] [error-boundary:root] Error: tapClientLookup: Index 8 out of bounds (length: 8)
        at UserMessage (<anonymous>)
    

    Current source already has a local mitigation in apps/desktop/src/components/assistant-ui/message-render-boundary.tsx that is intended to swallow /tapClient(Lookup|Resource).*out of bounds/, and thread-virtualizer.tsx wraps each virtualized group in MessageRenderBoundary:

    <MessageRenderBoundary resetKey={messageSignature}>
      {group.kind === 'turn' ? (
        <div ...>
          {group.indices.map(index => (
            <ThreadPrimitive.MessageByIndex components={components} index={index} key={index} />
          ))}
        </div>
      ) : (
        <ThreadPrimitive.MessageByIndex components={components} index={group.index} />
      )}
    </MessageRenderBoundary>

    So either the packaged Desktop build being run does not include the mitigation, or there is still an escaping path outside the per-message/group boundary. The log stack still reaches [error-boundary:root], so the current user-visible failure mode remains full-interface loss rather than a single dropped/recovered message row.

    One extra observed recovery problem: closing and reopening the Desktop app did not reliably reload/recover the window state; the error screen persisted/reappeared until an explicit reload/recovery path was used. That makes the root-boundary escape worse because a normal app restart may not be perceived as a reset by users.

    This seems correlated with very long chats / context compaction / session-state replacement, not a simple bad tool-result shape only.

  5. zzj1965186613 commented on Jun 13, 2026

    @zzj1965186613

    Additional Reproduction Case

    Trigger: Running /team-pipeline (multi-agent orchestrator that spawns parallel subagents)

    Error:

    tapClientLookup: Index 30 out of bounds (length: 2)
    

    Full stack trace from desktop.log:

    [renderer console] Error: tapClientLookup: Index 30 out of bounds (length: 2)
    [renderer console] [error-boundary:root] Error: tapClientLookup: Index 30 out of bounds (length: 2) 
        at Nqt (index-_oDh6Cvi.js:801:11970)
        at UserMessage (<anonymous>)
        at oEe (index-_oDh6Cvi.js:70:56089)
        at Ok (index-_oDh6Cvi.js:68:26113)
        ...
    

    Reproduction steps:

    1. Trigger a multi-agent workflow (e.g. /team-pipeline) that spawns 2-3 subagents in parallel
    2. Each subagent produces multiple tool calls and messages
    3. The UI crashes with tapClientLookup when rendering a UserMessage component where the part index (30) far exceeds the client array length (2)

    Key observation: The N=30, M=2 gap is much larger than the other reported cases (0/0, 5/5, 10/8, 23/18). This suggests the issue is not just a one-frame race but a more fundamental state desync when the message structure changes dramatically (many subagent messages appended rapidly).

    Environment:

    • OS: Windows 10
    • Hermes Desktop (Electron, minified build)
    • Model: mimo-v2.5-pro via Xiaomi API
    • assistant-ui/store version: embedded in minified bundle

    Workaround: Click "Reload window" to recover. No data loss — its purely a frontend rendering crash.

  6. added a commit that references this issue on Jun 25, 2026
    2e3efce
  7. added a commit that references this issue on Jun 28, 2026
    79d5ade
  8. added a commit that references this issue on Jun 29, 2026
    0e4c931
  9. added a commit that references this issue on Jul 2, 2026
    10ca8d4
  10. added a commit that references this issue on Jul 8, 2026
    b466452
  11. added a commit that references this issue on Jul 13, 2026
    6748ea6
  12. added a commit that references this issue on Jul 21, 2026
    012db79
  13. added a commit that references this issue on Aug 7, 2026
    fbb22ff
  14. fzzkjd commented on Aug 8, 2026

    @fzzkjd

    Thanks for the fix in #41787 — it covers the chat message render path. However, the same transient race still surfaces through contrib panel boundaries on Windows desktop v0.20.0 (latest, 2026-08-08):

    [renderer console] Error: useClientLookup: Index 1 out of bounds (length: 1)
    [renderer console] Error: Tried to unmount a fiber that is already unmounted
    [renderer console] [error-boundary:contrib:workspace] Error: Tried to unmount a fiber that is already unmounted
    

    User-visible result: the workspace (Projects) pane shows "workspace" failed to render with a Retry button, instead of the auto-recovering behavior the message boundary now has. Retry recovers; chat/gateway are unaffected — it's a visible but non-blocking regression surface.

    Root cause: message-render-boundary.tsx guards the assistant-ui message list with isTransientLookupError, but contrib panels use their own boundary (src/contrib/react/boundary.tsx → generic ErrorBoundary), which has no transient-error auto-retry. The same useClientLookup index race (length 1, index 1) throws there and does not self-heal.

    Suggestion: extract/share isTransientLookupError (or its regex) and apply the same recoverable-retry behavior in contrib/react/boundary.tsx, so transient store races in contrib panes recover on the next consistent snapshot instead of showing "failed to render".

  15. added a commit that references this issue on Sep 3, 2026
    b6e673c
  16. added a commit that references this issue on Oct 6, 2026
    e995349
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havetype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions