agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

fix(viewer): show explicit error banner when dashboard endpoints fail

Open jonathanzhan1975 opened this issue 6 months ago β€’ 4 comments

ο»Ώ## Summary

Dashboard silently shows 0 memories when worker is down.

This fix refactors loadDashboard() to detect endpoint failures and show an explicit error banner instead of presenting an empty-memory state.

Complementary to PR-A. Related to #303.

Summary by CodeRabbit

  • Bug Fixes

    • Improved dashboard error handling to track/report failing endpoints; shows a styled "Dashboard data unavailable" banner when all endpoints fail.
  • New Features

    • Added a config helper to control dropping stale indexes.
    • Memory tool calls now accept format and token budget parameters.
  • Chores

    • Hook command entries updated to ensure script paths are quoted.
  • Tests

    • Added/updated tests for hooks, env loading, and memory-call proxy behavior.

Review Change Stack

jonathanzhan1975 avatar May 19 '26 08:05 jonathanzhan1975

@jonathanzhan1975 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 19 '26 08:05 vercel[bot]

πŸ“ Walkthrough

Walkthrough

This PR quotes plugin hook script paths, adds a config helper for AGENTMEMORY_DROP_STALE_INDEX and wires it into startup, extends MCP memory_recall argument parsing and proxy routing, improves the viewer with safe HTML escaping and a dashboard error banner for failed endpoints, and updates/adds tests for these behaviors.

Changes

Plugin hook command quoting

Layer / File(s) Summary
Codex hook manifest updates
plugin/hooks/hooks.codex.json
Quote script paths in specific codex hook command entries.
Generic hook manifest updates
plugin/hooks/hooks.json
Quote ${CLAUDE_PLUGIN_ROOT} path segments in many hook command entries so node invocations preserve paths with spaces.

Config helper and startup wiring

Layer / File(s) Summary
Add config helper
src/config.ts
Export isDropStaleIndexEnabled() that returns true only when merged env AGENTMEMORY_DROP_STALE_INDEX === "true".
Use config helper in startup
src/index.ts
Import and call isDropStaleIndexEnabled() when initializing dropStale for persisted-index handling.

MCP standalone: proxy and arg parsing

Layer / File(s) Summary
Tool-arg types and validation
src/mcp/standalone.ts
Extend Validated args with optional format and tokenBudget; parse/normalize format and numeric token_budget in validate().
Proxy dispatch for memory_recall vs smart_search
src/mcp/standalone.ts
Implement memory_recall proxy to POST /agentmemory/search (default format: "full", optional token_budget) and keep memory_smart_search calling /agentmemory/smart-search with optional format/token_budget.

Viewer: dashboard error banner & safe HTML

Layer / File(s) Summary
Escape and banner utilities
src/viewer/index.html
Add escapeHtml(value) and dashboardErrorBanner(error) to safely render endpoint names inside a styled error banner.
Dashboard loading with failure tracking
src/viewer/index.html
Refactor loadDashboard() to fetch an endpoints array, collect failed endpoint names into state.dashboard.loadError, and early-return with an error banner when all endpoints fail.
Include error banner in render path
src/viewer/index.html
Initialize renderDashboard() HTML with the error banner output so error UI appears at the top of dashboard content.

Tests and validation

Layer / File(s) Summary
Hook manifest tests
test/codex-plugin.test.ts
Add types/helper and test asserting hook command strings use quoted node "${CLAUDE_PLUGIN_ROOT}/scripts/....mjs" invocations; tighten script-path extraction regex.
Env loader tests
test/env-loader.test.ts
Clear AGENTMEMORY_DROP_STALE_INDEX in beforeEach and add test that reads the var from .env enabling isDropStaleIndexEnabled().
MCP proxy tests
test/mcp-standalone-proxy.test.ts
Add tests verifying memory_recall proxies to /agentmemory/search, forwards format/token_budget, defaults format: "full", and does not call /agentmemory/smart-search.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through code to mend a seam,
Quoted paths and envs and dashboard gleam,
If memory calls or endpoints fail,
A banner shows the honest taleβ€”
Safe HTML keeps rabbits calm and keen.

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The PR title directly and clearly summarizes the main objective: showing an explicit error banner when dashboard endpoints fail, which aligns with the primary change detailed in the raw summary.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

πŸ”§ ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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 and usage tips.

coderabbitai[bot] avatar May 19 '26 08:05 coderabbitai[bot]

Thanks @jonathanzhan1975 β€” the viewer error-banner part of this is exactly what #466 needs. The PR bundles a few unrelated changes that overlap with other in-flight work though, and that's going to cause merge friction:

  • dropStaleIndex refactor (src/config.ts, src/index.ts) β€” collides with #575 which I just opened to fully fix #469/#455 (better error message + one-shot drop persistence).
  • memory_recall format / token_budget (src/mcp/standalone.ts) β€” this is #440's surface and is being addressed in #532 (currently CONFLICTING).
  • Hook manifest reshuffle (plugin/hooks/hooks.json, plugin/hooks/hooks.codex.json) β€” touches all 12 hook entries; would like to understand the motivation separately since it's not load-bearing for the banner fix.
  • Viewer banner (src/viewer/index.html) β€” the headline fix, lands cleanly on its own.

Would you be willing to split? A focused PR that only touches src/viewer/index.html (plus a banner-only test) would close #466 and land immediately. The other three pieces would each fit naturally into the PRs already in flight.

rohitg00 avatar May 20 '26 16:05 rohitg00

Thanks. Just to make sure I'm splitting the right PR β€” I checked all three of my open PRs against the file list:

#529 (fix/viewer-dashboard-diagnostic):

src/viewer/index.html | 62 ++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 49 insertions(+), 13 deletions(-)

#528 (fix/cli-iii-lifecycle) and #538 (fix/graph-backfill) also don't touch src/config.ts, src/index.ts, src/mcp/standalone.ts, plugin/hooks/hooks.json, or plugin/hooks/hooks.codex.json.

So #529 already seems isolated to the viewer banner, and the dropStaleIndex / memory_recall / hook reshuffle changes don't appear in any of my open PRs. Was the split request meant for someone else's PR, or am I reading the wrong branch state?

Separate question on the banner-only test: I don't see an existing JSDOM / happy-dom test pattern under test/. Would you prefer I (a) introduce JSDOM for this one test, (b) do a lighter file-content assertion against src/viewer/index.html, or (c) leave the PR test-less for now?

jonathanzhan1975 avatar May 20 '26 23:05 jonathanzhan1975