Skip to content

fix(desktop): handle string display_metadata in async_delegation_complete - #70780

Closed
JonthanaHanh wants to merge 2 commits into
NousResearch:mainfrom
JonthanaHanh:fix/desktop-delegation-complete-string-metadata
Closed

JonthanaHanh wants to merge 2 commits into
NousResearch:mainfrom
JonthanaHanh:fix/desktop-delegation-complete-string-metadata

Conversation

@JonthanaHanh

Copy link
Copy Markdown
Contributor

Problem

When resuming a session containing async_delegation_complete messages, the desktop app crashes with:

TypeError: Cannot use 'in' operator to search for 'task_count' in {"delegation_id":"deleg_9b840674","task_count":1,...}

The root cause: display_metadata arrives from the gateway/database as a JSON string rather than a parsed object. The 'task_count' in message.display_metadata operator throws when applied to a string.

Fix

Parse display_metadata to an object before using in, with a try/catch fallback for malformed JSON:

const meta =
  typeof message.display_metadata === 'string'
    ? (() => { try { return JSON.parse(message.display_metadata) } catch { return undefined } })()
    : message.display_metadata

Tests

  • handles async_delegation_complete with string display_metadata from database — verifies JSON string is parsed and task_count extracted
  • handles async_delegation_complete with object display_metadata — verifies existing object path still works

Closes #70635.

When an optional-mcps manifest declares transport.type=http with
auth.type=api_key, install_entry() correctly prompts for the key and
saves it to .env, but _build_server_config() only handled the oauth
case — the api_key case produced a bare url entry with no headers,
so every request to the server was unauthenticated (→ 401).

Import and call _bearer_auth_headers(entry.name) from mcp_config.py
to produce the same Authorization: Bearer ${MCP_<NAME>_API_KEY}
template used by the manual 'hermes mcp add --url' path.

Closes NousResearch#70632.
…lete

When resuming a session that contains async_delegation_complete
messages, display_metadata may arrive from the gateway/database as
a JSON string rather than a parsed object. The 'in' operator on a
string throws TypeError, crashing session resume.

Parse the string to an object before using 'in', with a try/catch
fallback for malformed JSON.

Closes NousResearch#70635.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/desktop Electron desktop app (apps/desktop/*) comp/cli CLI entry point, hermes_cli/, setup wizard tool/mcp MCP client and OAuth sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists labels Jul 24, 2026
@alt-glitch

Copy link
Copy Markdown

This was generated by AI during triage.

Duplicate of #70369 for the Desktop serialized display_metadata repair; #70369 fixes the persistence boundary and includes broader coverage. This PR also bundles an unrelated MCP catalog API-key header change that should be separated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/desktop Electron desktop app (apps/desktop/*) duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TypeError on session resume: 'in' operator on string display_metadata for async_delegation_complete

2 participants