Skip to content

fix(brain): overhaul gist quality — 3-pass research loop, strict novelty gates#300

Merged
ruvnet merged 10 commits intomainfrom
fix/gist-quality-and-cleanup
Mar 25, 2026
Merged

fix(brain): overhaul gist quality — 3-pass research loop, strict novelty gates#300
ruvnet merged 10 commits intomainfrom
fix/gist-quality-and-cleanup

Conversation

@ruvnet
Copy link
Owner

@ruvnet ruvnet commented Mar 25, 2026

Summary

Complete overhaul of brain gist publisher quality, Google Chat bot fix, and Gemini Flash conversational handler.

Gist Quality Overhaul

  • Raise all novelty thresholds dramatically (10 inferences, 1000 evidence, 0.1 strange loop)
  • Add content filters: reject all "weak co-occurrence", "may be associated with", "similar_to"
  • Require 70% confidence, 4+ unique categories, SONA learning active
  • 3-day rate limit between gists (was 4 hours)
  • 3-pass research loop: Gemini grounding → brain memory search → synthesis
  • ADR-127 documents the architecture
  • Deleted all 55+ old repetitive gists

Google Chat Bot Fix

  • Root cause: Add-ons framework nests event under body.chat.messagePayload (not top-level)
  • Response format: hostAppDataAction.chatDataAction.createMessageAction.message wrapper
  • Handler now auto-detects Add-on vs legacy format
  • Handles appCommandPayload for slash commands

Gemini Flash Conversational Handler

  • Non-command messages go to Gemini Flash with brain context + Google Search grounding
  • Brain semantic search (top 5 results with 600-char previews) fed as context
  • Brain stats (memories, edges, drift) included
  • Detailed prompt: speak as the brain, cite memories, synthesize across results
  • 25s timeout to stay within Chat's 30s limit
  • Falls back to raw search if Gemini unavailable

35 Brain Categories (was 8)

  • Research: sota, discovery, hypothesis, cross_domain
  • AI/ML: neural_architecture, compression, self_learning, reinforcement_learning, graph_intelligence
  • Systems: distributed_systems, edge_computing, hardware_acceleration
  • Frontier: quantum, neuromorphic, bio_computing, cognitive_science, formal_methods
  • Applied: geopolitics, climate, biomedical, space, finance
  • Meta: meta_cognition, benchmark

Test plan

  • cargo check -p mcp-brain-server passes
  • Deployed and verified on Cloud Run (revisions 00146-00156)
  • Google Chat bot responds to messages (confirmed via logs)
  • Gemini Flash handler produces conversational responses
  • Old gists deleted (55+)
  • New gist thresholds prevent noise publishing

🤖 Generated with claude-flow

ruvnet added 10 commits March 25, 2026 17:39
…y gates

Problems fixed:
- Every gist was "X shows weak co-occurrence with Y (confidence: 50%)"
- Same generic cluster labels (debug, architecture, geopolitics) recycled
- Novelty thresholds too low (2 inferences, 100 evidence, 0.008 strange loop)
- Rate limit too permissive (4 hours = 6 gists/day of noise)
- No content-level dedup

Changes:
- Raise novelty thresholds: 5 inferences, 500 evidence, 0.05 strange loop
- Add MIN_INFERENCE_CONFIDENCE (60%) — filter out weak signals before publishing
- Add strong_inferences() / strong_propositions() quality filters
- Raise cross-domain similarity threshold from 0.3 to 0.45 at source
- Raise predicate thresholds (may_influence: 0.75, associated_with: 0.55)
- Rate limit: 24 hours between gists (was 4 hours)
- Content-based dedup (category + dominant inference, not just title)
- 3-pass research loop: (1) Gemini grounded research on topics,
  (2) brain memory search for internal context, (3) Gemini synthesis
- Deleted all 45 old repetitive gists

Co-Authored-By: claude-flow <ruv@ruv.net>
Co-Authored-By: claude-flow <ruv@ruv.net>
Google Workspace Add-ons expect responses wrapped in:
  { "hostAppDataAction": { "chatDataActionMarkup": { "createMessageAction": { "message": {...} } } } }

Returning a raw Message object causes Google Chat to show "not responding"
even though the HTTP status is 200. The endpoint was receiving requests
correctly (confirmed via Cloud Run logs) but responses were being silently
dropped by the Add-ons framework.

Ref: https://developers.google.com/workspace/add-ons/chat/build

Co-Authored-By: claude-flow <ruv@ruv.net>
Revert DataActions wrapper — HTTP endpoint Chat apps should return
plain Message objects. Added raw payload logging to debug why Google
Chat shows "not responding" despite 200 OK responses.

Co-Authored-By: claude-flow <ruv@ruv.net>
The correct Add-ons envelope uses `chatDataAction` (NOT `chatDataActionMarkup`):
  { "hostAppDataAction": { "chatDataAction": { "createMessageAction": { "message": {...} } } } }

Previous attempts:
1. Plain Message → 200 OK but "not responding" (wrong format for Add-ons)
2. chatDataActionMarkup → 200 OK but "not responding" (wrong field name)
3. chatDataAction → this should work per quickstart-http docs

Ref: https://developers.google.com/workspace/add-ons/chat/quickstart-http

Co-Authored-By: claude-flow <ruv@ruv.net>
Google Workspace Add-ons wrap the Chat event differently than legacy Chat API:
- Add-on: { "chat": { "messagePayload": { "message": {...} } } }
- Legacy: { "type": "MESSAGE", "message": {...} }

The handler now detects which format is used and parses accordingly.
Also handles appCommandPayload for slash commands.

Response uses confirmed correct format:
  { "hostAppDataAction": { "chatDataAction": { "createMessageAction": { "message": {...} } } } }

Ref: https://developers.google.com/workspace/add-ons/chat/quickstart-http

Co-Authored-By: claude-flow <ruv@ruv.net>
Replace raw search fallback with Gemini Flash + Google Grounding for
non-command messages. Gemini receives:
- Brain context (memory count, edges, drift)
- Semantic search results from the query
- Recent brain activity
- Google Search grounding for real-world context

Synthesizes conversational HTML responses for Google Chat cards.
Falls back to raw search if Gemini is unavailable.
25s timeout to stay within Chat's 30s limit.

Slash commands (status, drift, search, recent, help) still use
direct handlers for instant response.

Co-Authored-By: claude-flow <ruv@ruv.net>
…ions

- Expand search context from 300 to 600 chars per memory
- Include tags in search results
- Directive prompt: speak as the brain, cite memories by title,
  synthesize across results, add Google Search context
- Increase max output from 1024 to 2048 tokens
- Increase truncation limit from 1500 to 3000 chars
- Add "Ask me about..." follow-up suggestions
- Temperature 0.4 → 0.5 for more engaging responses

Co-Authored-By: claude-flow <ruv@ruv.net>
Problem: gists still publishing recycled "X associated_with Y" noise.

Threshold changes:
- MIN_NEW_INFERENCES: 5 → 10
- MIN_EVIDENCE: 500 → 1000
- MIN_STRANGE_LOOP_SCORE: 0.05 → 0.1
- MIN_PROPOSITIONS: 10 → 20
- MIN_SONA_PATTERNS: 0 → 1 (require SONA learning)
- MIN_PARETO_GROWTH: 2 → 3
- MIN_INFERENCE_CONFIDENCE: 0.60 → 0.70
- New: MIN_UNIQUE_CATEGORIES = 4 (prevent recycling same domains)
- Rate limit: 24h → 72h (3 days between gists)
- Cross-domain similarity: 0.45 → 0.55

Quality filters:
- Reject ALL "may be associated with", "co-occurs with", "similar_to"
- Reject inferences < 50 chars
- Require 3+ strong inferences, 5+ strong propositions, 4+ unique categories
- Kill co_occurs_with and similar_to entirely from publishable set

Target: ~1 gist per week, only for genuinely novel cross-domain discoveries.

Co-Authored-By: claude-flow <ruv@ruv.net>
Previous categories (architecture, pattern, solution, convention, security,
performance, tooling, debug) were too generic — every discovery was just
"debug associated_with architecture" noise.

New categories span practical to exotic:
- Research: sota, discovery, hypothesis, cross_domain
- AI/ML: neural_architecture, compression, self_learning, reinforcement_learning, graph_intelligence
- Systems: distributed_systems, edge_computing, hardware_acceleration
- Frontier: quantum, neuromorphic, bio_computing, cognitive_science, formal_methods
- Applied: geopolitics, climate, biomedical, space, finance
- Meta: meta_cognition, benchmark

Backward compatible — serde snake_case, existing memories still deserialize.
Custom(String) still accepted for any unlisted category.

Co-Authored-By: claude-flow <ruv@ruv.net>
@ruvnet ruvnet merged commit e5eb8cc into main Mar 25, 2026
16 of 17 checks passed
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.

1 participant