Skip to content

fix: preserve Hermes runtime chat session state#1927

Merged
gsxdsm merged 3 commits into
Runfusion:mainfrom
plarson:fix/hermes-runtime-chat-state
Jul 6, 2026
Merged

fix: preserve Hermes runtime chat session state#1927
gsxdsm merged 3 commits into
Runfusion:mainfrom
plarson:fix/hermes-runtime-chat-state

Conversation

@plarson

@plarson plarson commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Use the project-scoped plugin runner for project chat routes so runtime hints resolve plugin runtimes correctly.
  • Expose the runtime plugin runner through ProjectEngine/InProcessRuntime.
  • Preserve Hermes runtime session message state and accept session_id emitted on stderr without mixing stderr into the assistant body.

Test Plan

  • corepack pnpm --filter @fusion-plugin-examples/hermes-runtime test
  • corepack pnpm --filter @fusion-plugin-examples/hermes-runtime typecheck
  • corepack pnpm --filter @fusion/engine typecheck
  • corepack pnpm --filter @fusion/dashboard typecheck

Summary by CodeRabbit

  • New Features
    • Improved project-scoped chat routing so plugins resolve more consistently with the engine’s runtime.
    • Hermes chat sessions now refresh cached plugin-runner usage when needed and preserve conversation history (user and assistant messages).
  • Bug Fixes
    • More robust Hermes output parsing: session IDs are extracted reliably even when emitted on stderr, and stderr is no longer treated as assistant text.
    • Hermes session state now retains an error message when the CLI fails, improving troubleshooting.

Copilot AI review requested due to automatic review settings July 6, 2026 00:53
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 898bd1d6-50e6-47c5-8df9-40ca75384a2f

📥 Commits

Reviewing files that changed from the base of the PR and between 22f921c and a734d9f.

📒 Files selected for processing (8)
  • .changeset/proud-horses-chat.md
  • packages/dashboard/src/chat-project-services.ts
  • packages/dashboard/src/chat.ts
  • packages/dashboard/src/routes/register-chat-routes.ts
  • plugins/fusion-plugin-hermes-runtime/src/__tests__/cli-spawn.test.ts
  • plugins/fusion-plugin-hermes-runtime/src/__tests__/runtime-adapter.test.ts
  • plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts
  • plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/proud-horses-chat.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/dashboard/src/routes/register-chat-routes.ts
  • packages/dashboard/src/chat.ts
  • plugins/fusion-plugin-hermes-runtime/src/tests/runtime-adapter.test.ts
  • plugins/fusion-plugin-hermes-runtime/src/tests/cli-spawn.test.ts
  • packages/dashboard/src/chat-project-services.ts
  • plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts

📝 Walkthrough

Walkthrough

This PR exposes project-scoped plugin runner lookup to dashboard chat routing and updates Hermes runtime handling so CLI output parsing, session transcript recording, and session error state are tracked consistently.

Changes

Plugin runner and Hermes runtime fixes

Layer / File(s) Summary
Engine getPluginRunner accessor
packages/engine/src/runtimes/in-process-runtime.ts, packages/engine/src/project-engine.ts
Adds public getPluginRunner() methods to expose the project-scoped PluginRunner.
Dashboard chat route wiring
packages/dashboard/src/routes/register-chat-routes.ts, packages/dashboard/src/chat-project-services.ts, packages/dashboard/src/chat.ts
Resolves per-project pluginRunner via the project engine and refreshes cached ChatManager instances on reuse.
Hermes output parsing
plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts, plugins/fusion-plugin-hermes-runtime/src/__tests__/cli-spawn.test.ts
Separates stdout and stderr handling when extracting session_id and assistant body text, with tests for stderr-sourced session IDs and empty-body markers.
Hermes session transcript and error state
plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts, plugins/fusion-plugin-hermes-runtime/src/types.ts, plugins/fusion-plugin-hermes-runtime/src/__tests__/runtime-adapter.test.ts, .changeset/proud-horses-chat.md
Shares session message arrays, records user/assistant turns with error rollback, extends session state with errorMessage, and updates tests and release notes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant registerChatRoutes
  participant EngineManager
  participant ProjectEngine
  participant ChatProjectServices
  participant ChatManager

  registerChatRoutes->>EngineManager: getEngine(projectId)
  EngineManager-->>registerChatRoutes: engine
  registerChatRoutes->>ProjectEngine: getPluginRunner()
  ProjectEngine-->>registerChatRoutes: pluginRunner
  registerChatRoutes->>ChatProjectServices: getOrCreateScopedChatManager(..., pluginRunner, refreshPluginRunner)
  ChatProjectServices->>ChatManager: setPluginRunner(pluginRunner) on cache hit
Loading

Possibly related PRs

  • Runfusion/Fusion#1073: Modifies the same resolveScopedChatManager/getOrCreateScopedChatManager dashboard chat flow and related plugin runner wiring.

Suggested reviewers: gsxdsm

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main Hermes runtime session-state fix in this changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Hermes-backed project chat routing and session handling. The main changes are:

  • Project chat now refreshes cached managers with the project runtime plugin runner.
  • Engine runtimes now expose the project-scoped plugin runner to dashboard routes.
  • Hermes chat sessions now keep shared message state and roll back failed prompts.
  • Hermes output parsing now accepts session_id from stderr without adding stderr to the reply body.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
packages/dashboard/src/chat-project-services.ts Adds a guarded cache refresh path for scoped chat managers.
packages/dashboard/src/routes/register-chat-routes.ts Uses the project engine runner when one is available for project chat.
packages/dashboard/src/chat.ts Adds a setter used to refresh a chat manager's plugin runner.
packages/engine/src/project-engine.ts Exposes the runtime plugin runner through the project engine.
packages/engine/src/runtimes/in-process-runtime.ts Returns the initialized in-process plugin runner for project-scoped callers.
plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts Preserves Hermes session messages, records errors, and handles empty assistant replies.
plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts Parses Hermes session IDs from stdout or stderr while keeping stderr out of the assistant body.
plugins/fusion-plugin-hermes-runtime/src/types.ts Adds the Hermes session state shape used by chat consumers.

Reviews (5): Last reviewed commit: "Merge branch 'main' into fix/hermes-runt..." | Re-trigger Greptile

Comment thread packages/dashboard/src/routes/register-chat-routes.ts Outdated
Comment thread plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts Outdated
Comment thread plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Hermes-runtime-backed chat session continuity by preserving per-session message history, correctly extracting session_id even when emitted on stderr, and ensuring dashboard project chat routes use the project-scoped plugin runner so runtime hints (e.g. hermes) resolve against the right plugin scope.

Changes:

  • Persist Hermes session message history by appending user/assistant turns onto the session’s message state.
  • Update Hermes CLI output parsing to accept session_id emitted on stderr while keeping stderr out of assistant text.
  • Expose the project-scoped PluginRunner via InProcessRuntime/ProjectEngine, and wire dashboard chat routes to prefer it for per-project chat.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
plugins/fusion-plugin-hermes-runtime/src/types.ts Extends Hermes session shape to include a persisted state payload.
plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts Preserves Hermes session message history across prompts.
plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts Accepts session_id from stderr without polluting assistant body text.
plugins/fusion-plugin-hermes-runtime/src/tests/cli-spawn.test.ts Adds coverage for stderr-emitted session_id parsing behavior.
packages/engine/src/runtimes/in-process-runtime.ts Exposes the project-scoped plugin runner from the runtime.
packages/engine/src/project-engine.ts Plumbs plugin runner access through ProjectEngine.
packages/dashboard/src/routes/register-chat-routes.ts Prefers per-project plugin runner for chat manager creation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts
Comment thread plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/dashboard/src/routes/register-chat-routes.ts (1)

111-121: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Cached project chat managers need a way to pick up the project runner. getOrCreateScopedChatManager() returns the first ChatManager for a project and never rebinds pluginRunner, so an early request can lock that project onto the fallback/undefined runner for the rest of its lifecycle. Invalidate this cache or refresh the manager once the engine is ready.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/dashboard/src/routes/register-chat-routes.ts` around lines 111 -
121, The project-scoped chat manager cache in resolveScopedChatManager() is
binding a ChatManager to whatever pluginRunner is available on the first
request, so later engine initialization never updates it. Adjust
getOrCreateScopedChatManager() usage so the manager is invalidated or refreshed
when a project’s engine runner becomes available, and make
resolveScopedChatManager() prefer the project-specific runner from
engine?.getPluginRunner() over the fallback options?.pluginRunner before
returning a cached manager.
plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts (1)

78-97: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Set session.state.errorMessage in the Hermes failure path. invokeHermesCli can reject here, but this runtime never writes the field, so downstream UI that reads session.state.errorMessage won’t surface Hermes errors.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts` around lines 78
- 97, The Hermes fallback path in promptWithFallback currently awaits
invokeHermesCli without storing any failure details, so set
session.state.errorMessage when that call rejects and clear or update it on
success. Wrap the invokeHermesCli call in error handling within
runtime-adapter.ts’s promptWithFallback method, and make sure the assigned
message comes from the thrown error so downstream UI reading
session.state.errorMessage can display the Hermes failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts`:
- Around line 320-324: The body extraction in cli-spawn.ts incorrectly re-finds
the session marker with lastIndexOf("\nsession_id:"), so it misses cases where
SESSION_ID_RE matches session_id at the start of stdout. Update the logic around
sessionId, sessionIdLineStart, and bodyRaw to use the actual stdout match
position from the exec result (or equivalent match index) instead of re-deriving
it from cleanedStdout. Keep stripping the session_id line from the assistant
body even when the marker is at index 0.

---

Outside diff comments:
In `@packages/dashboard/src/routes/register-chat-routes.ts`:
- Around line 111-121: The project-scoped chat manager cache in
resolveScopedChatManager() is binding a ChatManager to whatever pluginRunner is
available on the first request, so later engine initialization never updates it.
Adjust getOrCreateScopedChatManager() usage so the manager is invalidated or
refreshed when a project’s engine runner becomes available, and make
resolveScopedChatManager() prefer the project-specific runner from
engine?.getPluginRunner() over the fallback options?.pluginRunner before
returning a cached manager.

In `@plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts`:
- Around line 78-97: The Hermes fallback path in promptWithFallback currently
awaits invokeHermesCli without storing any failure details, so set
session.state.errorMessage when that call rejects and clear or update it on
success. Wrap the invokeHermesCli call in error handling within
runtime-adapter.ts’s promptWithFallback method, and make sure the assigned
message comes from the thrown error so downstream UI reading
session.state.errorMessage can display the Hermes failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 58202a4e-6f3f-49b2-914b-2152cac85e59

📥 Commits

Reviewing files that changed from the base of the PR and between 2025f9d and 8d6c92a.

📒 Files selected for processing (7)
  • packages/dashboard/src/routes/register-chat-routes.ts
  • packages/engine/src/project-engine.ts
  • packages/engine/src/runtimes/in-process-runtime.ts
  • plugins/fusion-plugin-hermes-runtime/src/__tests__/cli-spawn.test.ts
  • plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts
  • plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts
  • plugins/fusion-plugin-hermes-runtime/src/types.ts

Comment thread plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts Outdated
Comment thread packages/dashboard/src/chat-project-services.ts Outdated
Comment thread plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/dashboard/src/chat-project-services.ts`:
- Around line 94-99: The cache-hit path in chat-project-services should not
overwrite an existing plugin runner with undefined. In the cached branch that
returns the result of scopedChatManagerCache.get(key), only call
cached.setPluginRunner(pluginRunner) when pluginRunner is available; otherwise
leave the cached manager unchanged and return it as-is. Use the cache-hit logic
around scopedChatManagerCache, cached.setPluginRunner, and getFusionDir to
locate the fix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e817c419-3bf5-48cf-981c-04b8b64f95c9

📥 Commits

Reviewing files that changed from the base of the PR and between 8d6c92a and 61e8a11.

📒 Files selected for processing (7)
  • .changeset/proud-horses-chat.md
  • packages/dashboard/src/chat-project-services.ts
  • packages/dashboard/src/chat.ts
  • plugins/fusion-plugin-hermes-runtime/src/__tests__/cli-spawn.test.ts
  • plugins/fusion-plugin-hermes-runtime/src/__tests__/runtime-adapter.test.ts
  • plugins/fusion-plugin-hermes-runtime/src/cli-spawn.ts
  • plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/proud-horses-chat.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/fusion-plugin-hermes-runtime/src/runtime-adapter.ts

Comment thread packages/dashboard/src/chat-project-services.ts
@plarson plarson force-pushed the fix/hermes-runtime-chat-state branch from 61e8a11 to 22f921c Compare July 6, 2026 01:23
@plarson plarson force-pushed the fix/hermes-runtime-chat-state branch from 22f921c to a734d9f Compare July 6, 2026 01:26
@gsxdsm gsxdsm merged commit 210a442 into Runfusion:main Jul 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants