Skip to content

fix(briefing): invalidate cached briefing on workspace data change#237

Draft
Ovaculos wants to merge 2 commits into
NimbleBrainInc:mainfrom
Ovaculos:fix/briefing-cache-invalidation
Draft

fix(briefing): invalidate cached briefing on workspace data change#237
Ovaculos wants to merge 2 commits into
NimbleBrainInc:mainfrom
Ovaculos:fix/briefing-cache-invalidation

Conversation

@Ovaculos
Copy link
Copy Markdown
Contributor

Summary

The home-dashboard briefing cache was purely TTL-based — adding entities to bundle apps (todos, CRM rows, notes) left the dashboard showing the pre-update briefing for up to the full TTL window. Closes #225.

Invalidation is now content-based. computeBriefingFingerprint signatures the data a briefing is built from — activity logs and each running bundle's entity data (file count, newest mtime, total size) — and BriefingCache.get() serves a stored briefing only while that fingerprint still matches.

Why a fingerprint, not events

#225 suggested subscribing to data.changed. Event-based invalidation doesn't work here:

  • Emitting data.changed from /mcp loops — the iframe widget bridge calls tools over /mcp, so a broadcast triggers a useDataSync refresh, which is another /mcp call, which broadcasts again.
  • An in-process notifier avoids the loop but fires on every tool call, including reads. Apps read constantly, so the briefing regenerated on every interaction.

A tool call can't distinguish a read from a write. A content fingerprint invalidates if and only if the underlying data actually changed — no heuristic, no event plumbing.

Coverage

The fingerprint watches data, not the write path, so it is vector-agnostic — agent, iframe widget, external MCP client, and bundle install are all caught. Coverage is by data source:

  • Bundle entity data (entityDataRoot) — the issue's core case
  • Activity logs ({wsDir}/logs)
  • Bundle install / uninstall (running-bundle set)
  • Facets sourced from live MCP resource/tool calls instead of entity files are not fingerprinted; they fall back to the TTL. Documented on computeBriefingFingerprint.

dirSignature uses lstatSync (a dangling symlink is sized, not thrown) and skips entries that vanish mid-walk, so a concurrently-mutating tree cannot crash a briefing.

Context

#225 was surfaced during testing of #219 (now merged); this completes the cache-invalidation design that #219 deferred.

Test plan

  • bun run verify — static, unit, web, integration green
  • briefing-cache unit tests: fingerprint matching + computeBriefingFingerprint (file add/edit, entity data, non-running exclusion, missing dirs, symlinks)
  • Manual: add a todo in-app, reload home — briefing reflects it
  • Manual: revisit home repeatedly with no change — served from cache, not regenerated

🤖 Generated with Claude Code

Ovaculos and others added 2 commits May 18, 2026 17:06
The briefing cache was purely TTL-based, so adding entities to bundle
apps (todos, CRM rows, notes) left the home dashboard showing the
pre-update briefing for up to the full TTL window.

Invalidate by content fingerprint instead. `computeBriefingFingerprint`
signatures the data a briefing is built from — activity logs and each
running bundle's entity data (file count, newest mtime, total size) —
and `BriefingCache.get()` serves a stored briefing only while that
fingerprint still matches. A fingerprint is vector-agnostic: any path
that mutates the underlying files (agent, iframe widget, external MCP
client, bundle install) is caught, with no read/write guessing and no
SSE-driven refresh loop.

Facets sourced from live MCP resource/tool calls rather than entity
files are not fingerprinted and still fall back to the TTL; this is
documented on `computeBriefingFingerprint`.

Refs NimbleBrainInc#225.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dirSignature used statSync, which follows symlinks and throws ENOENT on
a dangling link — crashing computeBriefingFingerprint and erroring the
briefing tool. Switch to lstatSync (never follows, never throws on a
dangling link, counts a symlink as a leaf) and skip entries that vanish
between readdir and lstat (concurrent entity-file delete).

Refs NimbleBrainInc#225.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

BriefingCache invalidation is incomplete (activityHash dead, no facet-aware invalidation)

1 participant