feat(intelligence): add Knowledge Gaps#2956
Conversation
|
Warning Review limit reached
More reviews will be available in 4 minutes and 10 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a Knowledge Gaps intelligence feature: computes graph sparsity, exposes a read-only API, adds a namespaced Intelligence tab and presentational panel, integrates translations, and includes unit and UI tests. ChangesKnowledge Gaps Intelligence Feature
Sequence Diagram(s)sequenceDiagram
participant User
participant KnowledgeGapsTab
participant KnowledgeGapsAPI
participant memoryGraphQuery
participant computeKnowledgeGaps
participant KnowledgeGapsPanel
User->>KnowledgeGapsTab: open tab / select namespace
KnowledgeGapsTab->>KnowledgeGapsAPI: loadKnowledgeGaps(namespace)
KnowledgeGapsAPI->>memoryGraphQuery: memoryGraphQuery(namespace?)
memoryGraphQuery-->>KnowledgeGapsAPI: GraphRelation[]
KnowledgeGapsAPI->>computeKnowledgeGaps: computeKnowledgeGaps(relations)
computeKnowledgeGaps-->>KnowledgeGapsAPI: KnowledgeGapsReport
KnowledgeGapsAPI-->>KnowledgeGapsTab: KnowledgeGapsReport
KnowledgeGapsTab->>KnowledgeGapsPanel: render(report, loading, error, onRetry)
KnowledgeGapsPanel-->>User: UI (skeleton / error / empty / gaps list)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
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 `@app/src/components/intelligence/KnowledgeGapsTab.test.tsx`:
- Around line 41-44: The test currently asserts mockLoad was called immediately
after render which can race because loadKnowledgeGaps is invoked in an effect;
change the assertion to be async by awaiting a waitFor that checks mockLoad was
called with undefined (e.g., await waitFor(() =>
expect(mockLoad).toHaveBeenCalledWith(undefined))); keep the subsequent waitFor
for the rendered text and reference KnowledgeGapsTab, mockLoad, and
loadKnowledgeGaps when locating the code to update.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c1717efa-31fb-4cfb-9230-dbe999980b90
📒 Files selected for processing (23)
app/src/components/intelligence/KnowledgeGapsPanel.test.tsxapp/src/components/intelligence/KnowledgeGapsPanel.tsxapp/src/components/intelligence/KnowledgeGapsTab.test.tsxapp/src/components/intelligence/KnowledgeGapsTab.tsxapp/src/lib/i18n/chunks/ar-1.tsapp/src/lib/i18n/chunks/bn-1.tsapp/src/lib/i18n/chunks/de-1.tsapp/src/lib/i18n/chunks/en-1.tsapp/src/lib/i18n/chunks/es-1.tsapp/src/lib/i18n/chunks/fr-1.tsapp/src/lib/i18n/chunks/hi-1.tsapp/src/lib/i18n/chunks/id-1.tsapp/src/lib/i18n/chunks/it-1.tsapp/src/lib/i18n/chunks/ko-1.tsapp/src/lib/i18n/chunks/pt-1.tsapp/src/lib/i18n/chunks/ru-1.tsapp/src/lib/i18n/chunks/zh-CN-1.tsapp/src/lib/i18n/en.tsapp/src/lib/memory/knowledgeGaps.test.tsapp/src/lib/memory/knowledgeGaps.tsapp/src/pages/Intelligence.tsxapp/src/services/api/knowledgeGapsApi.test.tsapp/src/services/api/knowledgeGapsApi.ts
| it('loads on mount and renders the gap list', async () => { | ||
| render(<KnowledgeGapsTab />); | ||
| expect(mockLoad).toHaveBeenCalledWith(undefined); | ||
| await waitFor(() => expect(screen.getByText('Sparse entities')).toBeInTheDocument()); |
There was a problem hiding this comment.
Make the mount-call assertion async to avoid timing flakes.
loadKnowledgeGaps is triggered from an effect, so asserting it immediately after render can race in some runs. Wrap it in waitFor.
Suggested fix
it('loads on mount and renders the gap list', async () => {
render(<KnowledgeGapsTab />);
- expect(mockLoad).toHaveBeenCalledWith(undefined);
+ await waitFor(() => expect(mockLoad).toHaveBeenCalledWith(undefined));
await waitFor(() => expect(screen.getByText('Sparse entities')).toBeInTheDocument());
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('loads on mount and renders the gap list', async () => { | |
| render(<KnowledgeGapsTab />); | |
| expect(mockLoad).toHaveBeenCalledWith(undefined); | |
| await waitFor(() => expect(screen.getByText('Sparse entities')).toBeInTheDocument()); | |
| it('loads on mount and renders the gap list', async () => { | |
| render(<KnowledgeGapsTab />); | |
| await waitFor(() => expect(mockLoad).toHaveBeenCalledWith(undefined)); | |
| await waitFor(() => expect(screen.getByText('Sparse entities')).toBeInTheDocument()); | |
| }); |
🤖 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 `@app/src/components/intelligence/KnowledgeGapsTab.test.tsx` around lines 41 -
44, The test currently asserts mockLoad was called immediately after render
which can race because loadKnowledgeGaps is invoked in an effect; change the
assertion to be async by awaiting a waitFor that checks mockLoad was called with
undefined (e.g., await waitFor(() =>
expect(mockLoad).toHaveBeenCalledWith(undefined))); keep the subsequent waitFor
for the rendered text and reference KnowledgeGapsTab, mockLoad, and
loadKnowledgeGaps when locating the code to update.
|
Thanks @coderabbitai — addressed: the mount-call assertion now runs after the |
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
A new read-only "Gaps" tab — the inverse of the centrality lens. Instead of the
hubs the assistant knows most about, it surfaces the THIN spots: orphan
(0-connection) and leaf (1-connection) entities the assistant has barely
recorded anything about, the best candidates to enrich. Each gap also flags
entities that appear only as an object ("mentioned, never described").
- Pure deterministic engine (lib/memory/knowledgeGaps.ts): classifies every
entity by distinct undirected neighbour count (orphan/leaf/connected; self-
loops don't count), tracks object-only entities, and reports counts + gap
ratio. No clock, no RNG; gaps sorted orphan-before-leaf then id-asc.
- Zero new core surface: reuses memoryGraphQuery + memoryListNamespaces.
Read-only, recomputed from the live graph.
- Container guards the load with a request token; namespace selector; summary
tiles + gap-ratio caption + the sparse-entity list with kind badges and an
"all connected" state, capped with a truncation note. i18n across 13 locales.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
KnowledgeGapsTab references knowledgeGaps.namespaceLabel / namespaceAll but they were never defined, so the namespace selector would render the raw keys. Add both to en.ts + the locale chunks. (The selector only renders when namespaces exist, which is why the empty-namespace tests didn't surface it.) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
660b9a2 to
6cdf509
Compare
Address CodeRabbit: assert loadKnowledgeGaps was called with undefined only after the rendered result settles, avoiding any effect-timing flakiness. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
6cdf509 to
665f934
Compare
Summary
Adds a new read-only "Gaps" tab — the inverse of the Knowledge Graph Centrality lens. Instead of the hubs the assistant knows the most about, it surfaces the thin spots: orphan (0-connection) and leaf (1-connection) entities it has barely recorded anything about — the best candidates for the assistant to enrich. Each gap also flags entities that appear only as an object ("mentioned, never described"), an even stronger stub signal.
Design
lib/memory/knowledgeGaps.ts): classifies every entity by its distinct undirected neighbour count — orphan (0), leaf (1), connected (2+); self-loops don't count as a connection. Tracks object-only entities and reports orphan/leaf/connected counts plus a gap ratio. No clock, no RNG; gaps sorted orphan-before-leaf then id-asc (stable, relation-order-invariant).memoryGraphQueryandmemoryListNamespaceswrappers. Read-only — recomputed from the live graph on mount.Edge cases (tested)
Empty graph, the orphan/leaf/connected classification, self-loop-only entities (orphan, degree 0), object-only detection, well-connected exclusion, order-invariance, and malformed rows dropped.
Test plan
vitest— 20 tests (engine classification + object-only + self-loop + order-invariance; api facade; panel states incl. all-connected; container load + selector + error)tsc --noEmit— cleaneslint— 0 errorsprettier --check— cleanknowledgeGaps.*keys🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
API
Tests
Internationalization