Skip to content

feat: session-level enrichment — decisions, corrections, learnings#16

Merged
EtanHey merged 2 commits into
mainfrom
feature/phase-7-session-enrichment
Feb 20, 2026
Merged

feat: session-level enrichment — decisions, corrections, learnings#16
EtanHey merged 2 commits into
mainfrom
feature/phase-7-session-enrichment

Conversation

@EtanHey
Copy link
Copy Markdown
Owner

@EtanHey EtanHey commented Feb 20, 2026

Summary

  • Session-level enrichment pipeline: Analyze full conversations (not just chunks) through local LLM to extract decisions, corrections, learnings, mistakes, patterns, and quality scores
  • Conversation reconstruction: Reassemble ordered chunks into coherent conversation text with role prefixes, message counts, and timing
  • Hybrid schema: Flat columns for filterable fields (intent, outcome, scores) + JSON columns for variable-length arrays (decisions, corrections, learnings)
  • FTS5 search: Full-text search on session narratives (summary + what_worked + what_failed)
  • CLI command: brainlayer enrich-sessions with Rich progress bar, project/date filters, and --stats mode
  • MCP tool: brainlayer_session_summary (tool feat: MLX auto-detection, stall detection, current_context fix #14) returns formatted session analysis + session context enrichment in search results
  • 33 TDD tests covering schema, CRUD, reconstruction, parsing, and full pipeline

What Changed

File Change
src/brainlayer/vector_store.py session_enrichments table + FTS5 + CRUD methods
src/brainlayer/pipeline/session_enrichment.py NEW — reconstruction, LLM prompt, parsing, enrichment pipeline
src/brainlayer/cli/__init__.py enrich-sessions command with Rich progress
src/brainlayer/mcp/__init__.py brainlayer_session_summary tool + session context in search
tests/test_session_enrichment.py NEW — 33 tests across 7 classes
tests/test_think_recall_integration.py Tool count assertion 13→14
CLAUDE.md Docs for new CLI/MCP/file structure

Test plan

  • 33 unit tests pass (schema, CRUD, reconstruction, parsing, full pipeline)
  • Tool count test updated (14 tools)
  • Lint clean (ruff check)
  • CodeRabbit review
  • Bugbot review

🤖 Generated with Claude Code


Note

Medium Risk
Adds new DB schema (new tables + indexes + FTS5) and integrates it into search/CLI/MCP paths, which can impact runtime behavior and persistence despite being largely additive.

Overview
Adds session-level enrichment (Phase 7) that reconstructs full conversations, runs an LLM once per session, and persists structured outputs (summary/intent/outcome/scores plus decisions/corrections/learnings/etc.) in a new session_enrichments SQLite table with FTS5 support.

Introduces a new brainlayer enrich-sessions CLI command (including --project/--since/--max filters and --stats) and extends the MCP server with brainlayer_session_summary; search results are now optionally annotated with session-level summary/outcome/quality when available. Docs and tests are updated/added to cover the new pipeline, DB CRUD/stats, and MCP tool count wiring.

Written by Cursor Bugbot for commit 2e7f653. This will update automatically on new commits. Configure here.

…om full conversations

Upgrade enrichment from chunk-level to session-level analysis:
- Conversation reconstruction from ordered chunks with role prefixes
- Single-pass LLM analysis extracting 12 structured fields (summary, intent,
  outcome, decisions, corrections, learnings, mistakes, patterns, tags, etc.)
- Hybrid schema: flat columns for filterable fields + JSON for variable arrays
- FTS5 full-text search on session narratives
- CLI: `brainlayer enrich-sessions` with Rich progress bar and --stats mode
- MCP: `brainlayer_session_summary` tool (#14) + session context in search results
- 33 TDD tests covering schema, CRUD, reconstruction, parsing, and full pipeline

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 20, 2026

Warning

Rate limit exceeded

@EtanHey has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0a5f86c and 4d9f306.

📒 Files selected for processing (7)
  • CLAUDE.md
  • src/brainlayer/cli/__init__.py
  • src/brainlayer/mcp/__init__.py
  • src/brainlayer/pipeline/session_enrichment.py
  • src/brainlayer/vector_store.py
  • tests/test_session_enrichment.py
  • tests/test_think_recall_integration.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/phase-7-session-enrichment

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.

@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented Feb 20, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread src/brainlayer/pipeline/session_enrichment.py
Comment thread src/brainlayer/pipeline/session_enrichment.py Outdated
Comment thread src/brainlayer/vector_store.py
Comment thread src/brainlayer/cli/__init__.py Outdated
- Apply `since` filter to session_context discovery path (Method 1)
- Remove unused `projects` variable in enrich_session
- Copy dict before JSON serialization to avoid mutating caller's input
- Remove unused `batch_size` CLI parameter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@EtanHey EtanHey merged commit 042bd84 into main Feb 20, 2026
4 of 5 checks passed
@EtanHey EtanHey deleted the feature/phase-7-session-enrichment branch February 20, 2026 18:33
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 4 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

if total_chars > MAX_CONVERSATION_CHARS:
conversation_parts.append(
f"\n[... {len(chunks) - len(conversation_parts)} more chunks truncated]"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truncation count miscalculates remaining chunks

Low Severity

The truncation message formula len(chunks) - len(conversation_parts) is incorrect. conversation_parts only counts non-noise chunks (those not skipped by the continue at line 107), while len(chunks) includes all chunks. This inflates the reported count by the number of noise chunks already processed, and also includes the just-appended truncation message in the count. The resulting message sent to the LLM overstates how much content remains.

Fix in Cursor Fix in Web

)
""")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_session_enrichments_session ON session_enrichments(session_id)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_session_enrichments_project ON session_enrichments(primary_intent)")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Index named "project" actually indexes primary_intent column

Low Severity

The index idx_session_enrichments_project is created on the primary_intent column, not on any project column (which doesn't exist in session_enrichments). The name is misleading and could cause confusion when inspecting the schema or when someone assumes project-based lookups on this table are already indexed.

Fix in Cursor Fix in Web

if rows:
session_cache[session_id] = {
"session_summary": rows[0][0],
"session_intent": rows[0][1],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Session intent enrichment data fetched but never consumed

Low Severity

enrich_results_with_session_context fetches primary_intent from the database and adds it to metadata as session_intent, but the _search function in the MCP layer never reads meta.get("session_intent"). The other three enrichment fields (session_summary, session_outcome, session_quality) are all consumed — this one is silently dropped. Either the field is missing from the search output or it's dead code.

Additional Locations (1)

Fix in Cursor Fix in Web


except Exception as e:
rprint(f"[bold red]Error:[/] {e}")
raise typer.Exit(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store connection leaked when exceptions escape enrichment loop

Low Severity

The VectorStore created at line 954 is closed manually at lines 967, 976, and 1015, but if an exception occurs in list_sessions_for_enrichment (line 970), during Progress initialization (line 984), or from any unhandled error path, the outer except at line 1019 catches it without calling store.close(). A try/finally or context manager would ensure cleanup on all paths.

Fix in Cursor Fix in Web

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