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

@Ovaculos Ovaculos commented May 18, 2026

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(fingerprint) serves a stored briefing only while that fingerprint still matches.

Composes with stale-while-revalidate

This branch was rebased onto the stale-while-revalidate (SWR) flow that landed after it was first opened. The two fit together cleanly:

  • A data change now misses get() even within the TTL (fingerprint mismatch), instead of waiting out the TTL.
  • The dashboard serves the prior briefing instantly via getStale() while a fresh one regenerates in the background — no synchronous wait on the model.
  • getStale() is intentionally fingerprint-agnostic: serving a briefly-stale briefing during the regen window is the whole point of that path. The fingerprint check lives in get().

Net effect: a todo added in-app shows up on the next dashboard load, and the load is still instant.

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. This is the same path entity facets read, so the fingerprint signatures exactly the data those facets summarize.
  • 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.

Test plan

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

Ovaculos added 2 commits May 30, 2026 08: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(fingerprint)` 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.

This composes with the existing stale-while-revalidate flow: a data
change now misses `get()` even within the TTL, so the dashboard serves
the prior briefing instantly via `getStale()` while a fresh one
regenerates in the background — no synchronous wait on the model.

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.
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.
@mgoldsborough mgoldsborough force-pushed the fix/briefing-cache-invalidation branch from 10ca057 to 6900db0 Compare May 30, 2026 18:06
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