Repository navigation
fix: stop returning learnings past their ttl_days, and say why learnings need a workspace - #46
Merged
Conversation
…ngs need a workspace record_learning documents ttl_days as "Auto-expire after N days", but nothing ever removed or filtered an expired learning: expire_stale() is only called from a test, and none of the three searches checked expires_at. relevant_learnings kept returning a 1-day blocker after it expired. The searches now skip rows whose expires_at has passed. In single-repo mode the four learnings tools failed with only "Error executing tool <name>": MCPServer forwards the text of a ToolError but masks a RuntimeError. _get_learnings_db now raises ToolError, so the client sees that learnings need 'srclight serve --workspace NAME'.
Member
|
🔍 Conductor reviewer dispatched (pid 2072382) |
tofutim
approved these changes
Oct 14, 2026
tofutim
left a comment
Member
There was a problem hiding this comment.
Code review
No issues found. Checked for bugs and CLAUDE.md compliance.
The fix is correct: expires_at > ? filters are added in the same position/style as the existing include_superseded clause in all three searches, _now_iso() matches the %Y-%m-%dT%H:%M:%S.%fZ format used when expires_at is written (so the lexicographic comparison is valid), and SQL param order matches placeholder order. The RuntimeError→ToolError swap correctly surfaces the "workspace mode" reason to the client. Full test suite passes (900 passed, 1 skipped) including the two new tests.
🤖 Generated with Claude Code
- If this code review was useful, please react with 👍. Otherwise, react with 👎.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
1.
ttl_dayslearnings never expire.record_learningdocumentsttl_daysas "Auto-expire after N days", and it setsexpires_at, but nothing reads it. An expired learning keeps coming back:record_learning {"kind":"blocker","content":"staging deploy frozen until the zebra migration lands","ttl_days":1}expires_atto yesterday).relevant_learnings {"query":"zebra"}still returns the blocker.2. In single-repo mode the learnings tools don't say why they fail.
record_learning,relevant_learnings,learning_statsandconversation_summaryanswer onlyError executing tool learning_stats(etc.). The reason, "Learnings require workspace mode", only shows up in the server log.Cause
LearningsDB.expire_stale()(src/srclight/learnings.py:358) is only called fromtests/test_learnings.py.search_fts,_search_likeandsearch_embeddingshave noexpires_atcondition._get_learnings_db()(src/srclight/server.py:316) raisesRuntimeError. Under mcp 2.x,MCPServerforwards the text of aToolErrorbut replaces any other exception with the bare "Error executing tool ".Fix
expires_athas passed:AND (expires_at IS NULL OR expires_at > ?)with_now_iso(). Both sides use the same%Y-%m-%dT%H:%M:%S.%fZformat, so the text comparison is safe. Nothing is deleted.expire_stale()is left as it is._get_learnings_db()raisesToolError("Learnings require workspace mode: start the server with 'srclight serve --workspace NAME'"). Thesrclight toolCLI path already catches exceptions frommcp.call_tool, so it now prints the same reason.Tests
Added to
tests/test_learnings.py:test_search_skips_expired_learnings: records attl_days=1learning and a permanent one, expires the first, and checks that the FTS, LIKE-fallback and embedding searches return only the permanent one.test_learnings_tools_explain_workspace_mode: callslearning_statsthroughmcp.call_toolwith no workspace and expects aToolErrorthat mentions "workspace mode".Both fail on
develop(assert [1, 2] == [2], andActual message: 'Error executing tool learning_stats') and pass with the fix.Full suite on macOS / Python 3.12: 875 passed, 17 skipped, 9 failed. The same 9 tests fail on
developwithout this change (test_hook_still_runs_on_linux,test_index_dart, and 7test_read_only_uri_survives_metacharacterscases; they look macOS-specific).ruff checkreports the same results before and after.