fix: preserve Hermes runtime chat session state#1927
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughThis 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. ChangesPlugin runner and Hermes runtime fixes
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR fixes Hermes-backed project chat routing and session handling. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (5): Last reviewed commit: "Merge branch 'main' into fix/hermes-runt..." | Re-trigger Greptile |
There was a problem hiding this comment.
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_idemitted on stderr while keeping stderr out of assistant text. - Expose the project-scoped
PluginRunnerviaInProcessRuntime/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.
There was a problem hiding this comment.
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 liftCached project chat managers need a way to pick up the project runner.
getOrCreateScopedChatManager()returns the firstChatManagerfor a project and never rebindspluginRunner, 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 winSet
session.state.errorMessagein the Hermes failure path.invokeHermesClican reject here, but this runtime never writes the field, so downstream UI that readssession.state.errorMessagewon’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
📒 Files selected for processing (7)
packages/dashboard/src/routes/register-chat-routes.tspackages/engine/src/project-engine.tspackages/engine/src/runtimes/in-process-runtime.tsplugins/fusion-plugin-hermes-runtime/src/__tests__/cli-spawn.test.tsplugins/fusion-plugin-hermes-runtime/src/cli-spawn.tsplugins/fusion-plugin-hermes-runtime/src/runtime-adapter.tsplugins/fusion-plugin-hermes-runtime/src/types.ts
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
.changeset/proud-horses-chat.mdpackages/dashboard/src/chat-project-services.tspackages/dashboard/src/chat.tsplugins/fusion-plugin-hermes-runtime/src/__tests__/cli-spawn.test.tsplugins/fusion-plugin-hermes-runtime/src/__tests__/runtime-adapter.test.tsplugins/fusion-plugin-hermes-runtime/src/cli-spawn.tsplugins/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
61e8a11 to
22f921c
Compare
22f921c to
a734d9f
Compare
Summary
Test Plan
Summary by CodeRabbit