Skip to content

fix: tolerate partial dashboard payloads#365

Open
NgoQuocViet2001 wants to merge 1 commit into
rohitg00:mainfrom
NgoQuocViet2001:fix/347-dashboard-shape
Open

fix: tolerate partial dashboard payloads#365
NgoQuocViet2001 wants to merge 1 commit into
rohitg00:mainfrom
NgoQuocViet2001:fix/347-dashboard-shape

Conversation

@NgoQuocViet2001
Copy link
Copy Markdown

@NgoQuocViet2001 NgoQuocViet2001 commented May 14, 2026

Summary

  • Normalize dashboard API collections before rendering so malformed or missing arrays fall back to empty lists.
  • Avoid crashing Recent Sessions when a session is missing both project and id; render unknown instead.
  • Add a viewer regression test for partial dashboard payloads.

Fixes #347.
Refs #340.

Why

Windows users reported the Dashboard tab failing to load with Cannot read properties of undefined (reading 'slice') after v0.9.12. The viewer assumed several dashboard payload fields were always arrays and that every session had an id, so one partial record could stop the whole dashboard from rendering.

Tests

  • npx vitest run test/viewer-dashboard.test.ts test/viewer-security.test.ts
  • npm run build with npm_config_script_shell="C:\\Program Files\\Git\\bin\\bash.exe" on Windows because the package build script uses POSIX shell commands
  • npm test was also attempted locally; the new viewer test passed, but the full suite still has unrelated local Windows failures in existing path/Python-dependent tests (compress-file, obsidian-export, integration-plaintext-http).

Summary by CodeRabbit

  • Bug Fixes

    • Improved dashboard stability by hardening data handling against missing or incorrectly formatted API responses.
  • Tests

    • Added comprehensive test coverage for dashboard rendering with malformed or incomplete data.

Review Change Stack

Signed-off-by: NgoQuocViet2001 <ngoquocviet2001@gmail.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

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

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c929c400-3abc-416a-85aa-f1cc5507a50b

📥 Commits

Reviewing files that changed from the base of the PR and between 8c3418c and 73ac45e.

📒 Files selected for processing (2)
  • src/viewer/index.html
  • test/viewer-dashboard.test.ts

📝 Walkthrough

Walkthrough

This PR hardens the viewer dashboard against null/undefined or unexpected API response shapes by introducing normalization helpers and refactoring data loading and rendering to use safe fallbacks. A new test suite validates resilience by running the dashboard script in a sandbox with intentionally malformed data.

Changes

Dashboard rendering resilience

Layer / File(s) Summary
Normalization utilities and dashboard state shape
src/viewer/index.html
Introduces asArray(), firstArray(), and asString() utility functions to safely normalize unknown API values into consistent forms. Dashboard state gains semantic, procedural, and relations collections to hold expanded data.
Safe data loading with normalized helpers
src/viewer/index.html
loadDashboard() replaces inline fallbacks (`
Resilient dashboard rendering with normalized data
src/viewer/index.html
All renderDashboard() UI sections (metrics, cards, alerts, notes, recent sessions, audit feed, semantic/procedural/relations panels, procedural steps) derive content from normalized arrays, eliminating direct truthiness checks and slice operations on potentially undefined values.
Sandbox test infrastructure and validation
test/viewer-dashboard.test.ts
New Vitest suite extracts and runs the viewer script in a mocked Node.js VM environment with a lightweight element store, seeds dashboard state with malformed payloads (missing fields, wrong types, undefined), and verifies renderDashboard() executes safely and produces expected UI text.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • rohitg00/agentmemory#172: Adds the REST GET endpoints that return { semantic, procedural, relations } array payloads, which this PR's viewer changes directly depend on for safe ingestion.
  • rohitg00/agentmemory#108: Prior hardening of viewer script/CSP wiring and data-action-based event delegation that establishes the foundation for dashboard rendering resilience patterns.

Poem

🐰 Fragments and nulls were breaking our view,
So we built safety nets in the rendering queue,
Arrays of helpers now catch every shape,
Dashboard stands firm—no more escape!
Tests in a sandbox prove it's all tight.

🚥 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 title 'fix: tolerate partial dashboard payloads' directly describes the main change—hardening dashboard rendering against missing/incorrect response shapes.
Linked Issues check ✅ Passed The PR successfully addresses issue #347 by normalizing dashboard API collections before rendering and preventing crashes from missing session fields, matching the objective to tolerate partial/invalid payloads.
Out of Scope Changes check ✅ Passed All changes—dashboard normalization logic, safe accessor helpers, UI rendering resilience, and viewer regression test—are directly scoped to fixing dashboard payload tolerance as defined in issue #347.

✏️ 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.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

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.

Dashboard failed to load: Cannot read properties of undefined (reading 'slice') — v0.9.12

1 participant