Repository navigation
🐛 fix(taskmcp): knowledge answers multi-word queries and serves full bodies - #16919
Conversation
…bodies The task MCP knowledge tool kept a fact only when the whole query was one unbroken piece of its title, 200-character snippet or tags, so several words, or a word later in the page, found nothing although the store's own search had found the fact. It served that snippet as the body. repo_conventions used the same filter and missed facts typed conventions. Search hits are now kept under the scope rules alone: approved, tagged for exactly the task's repo, before the limit. Literal matches stay. knowledge serves full bodies, cut at 16 KiB with a marker. A body read by slug is used only when the page read passes the same rules; repo_conventions served a same-slug draft or another repo's page before. FullFact now carries the lifecycle state of the page it read. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. Review findings from Read One small inconsistency (low): CI note for the maintainer: the red stage 080-awaiting-merge-admission → 072-returned-to-contributor: check-failure Review findings from Read the diff against the v6 tree and the callers in
One note, not a defect: |
There was a problem hiding this comment.
Verified the mechanism against the v6 tree rather than the diff alone.
The defect is real. At the base, scopedKnowledgeFacts appends the store's search hits to the unfiltered listing (task_mcp_phase3.go:120-126) and then runs every element through factMatchesQuery (:133), which is a single strings.Contains of the whole query against title + body + tags (:283-290). So a hit the store found by term scoring was discarded unless the literal phrase also appeared in the listed snippet — exactly the "rebase at character 303" case in the table. The new i < listed split keeps that literal filter for listed facts only and trusts the store's hits; the append order those indices depend on is unchanged.
Conventions. At the base isRepoConventionFact ran in repoConventionItems after scopedKnowledgeFacts had already applied limit with the literal word "conventions" as the query (:62-66), so a typed fact with no such wording never arrived, and non-convention facts consumed the limit. Passing it as keep before the limit fixes both.
Lifecycle on re-read. FullFact is called from exactly one place in the tree (task_mcp_phase3.go:69 at base — confirmed by grepping src/ for .FullFact(), so copying State/Supersedes/SupersededBy from the page in mergeFullFact and clearing them on the wiki path cannot change any other caller's filtering. With them cleared, resolveLifecycleState (knowledge/lifecycle.go:64-78) derives the state from the page's Status, and fullKnowledgeFact re-applies knowledgeFactInScope/keep on the result — a cross-store slug collision now falls back to the listed snippet instead of serving another repo's or a draft page.
capKnowledgeBody. taskmcp.MaxTextBytes is 16 KiB (crux/taskmcp/taskmcp.go:38); the marker is well under 100 bytes, so cut stays positive and the utf8.RuneStart walk-back is safe.
Looks correct to me. Test list in the body matches the tests in the diff; I did not wait on the still-running CI shards.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
@Danathar this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (12 waiting): fixes are handed out before new work as soon as you have capacity. |
|
Check report (hive scanner, read-only — fork branch, nothing pushed) for head The red This PR changes nothing under 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
…query Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
There was a problem hiding this comment.
Read the new scopedKnowledgeFacts path and FullFact against the v6 tree; the change looks correct to me.
- The
listedboundary (src/pkg/dashboard/task_mcp_phase3.go:128,146) is what fixes the multi-word case:factMatchesQueryis applied only to indices belowlisted(the unqueried listing), while search hits appended at:134pass throughknowledgeFactInScopeonly.seenis set only when a fact is kept, so a listing row dropped by the text filter does not shadow the same slug arriving as a search hit. - The scope rule (
approved && factForRepo) runs before thelimitbreak, soTestContributeMCPKnowledgeRequiresExactRepoTagBeforeLimitsemantics survive. fullKnowledgeFact(task_mcp_phase3.go:166-175) falls back to the listed fact when the by-slug read lands on an out-of-scope copy; that only works becausemergeFullFact(src/pkg/knowledge/api.go:964-966) and the wiki branch (:945) now carry the read page's lifecycle. Previously a draft copy read by slug kept the listing'sapprovedstate, sorepo_conventionscould serve it. Good catch and the pairing is necessary.capKnowledgeBodycuts on a rune boundary and the marker is included in the budget; withMaxTextBytes= 16 KiB and an ~80-byte markercutstays positive.
Suggestion, not a defect: repo_conventions still serves uncapped bodies (task_mcp_phase3.go:72). The design doc section says only knowledge caps, so this is consistent and pre-existing, but a follow-up could apply capKnowledgeBody there too.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
Summary
Worker agents look up the hive's knowledge for their task with the task MCP
knowledgetool, and most lookups came back empty. A fact that was found had its body cut off after 200 characters. The tool now returns what the knowledge store's own search finds for the task's repository, with each fact's complete body.repo_conventionsnow returns facts typedconventionswhatever their text says. Both tools now check the page they read for a body against the repository and approval rules, whichrepo_conventionsdid not do.What went wrong
The tool kept a fact only when the whole query was one unbroken piece of the fact's title, its first 200 characters or its tags. The knowledge store's own search had already found the fact. The tool threw it away.
Example: one approved fact for the task's repository, titled "Git workflow". Its body is 380 characters and first says "rebase" at character 303.
Git workflowrebasegit rebase workflowhow changes reach mainThe one fact that did come back carried 203 of its 380 body bytes and ended in "…". No tool returned the rest. It now comes back whole.
What changes
knowledgereads each returned fact in full, asrepo_conventionsalready did. A body over 16 KiB is cut on a character boundary and ends with[... truncated by hive: knowledge body is N bytes, cap is 16384 ...]. The result shape does not change.repo_conventionspicks facts by type orkind:conventionstag, before its limit. The word "conventions" no longer has to appear in the text.repo_conventions, still a convention. Otherwise the listed fact is served with its snippet. Before,repo_conventionsserved whatever page the slug reached, including a draft or another repository's page.Files
src/pkg/dashboard/task_mcp_phase3.go:scopedKnowledgeFactsno longer applies the text filter to search hits and takes akeeprule that runs before the limit;repoConventionItemspassesisRepoConventionFact; newfullKnowledgeFact,knowledgeFactInScopeandcapKnowledgeBody.src/pkg/knowledge/api.go:FullFactandmergeFullFactcarry the lifecycle fields of the page that was read.src/pkg/dashboard/task_mcp_knowledge_query_test.go: new tests for both tools.src/pkg/knowledge/full_fact_test.go: new tests for the full-fact read.src/docs/design/task-mcp.md: new section "Knowledge matching and bodies"; the two table rows point to it.changelog.d/fixed-task-mcp-knowledge-query.md: changelog entry.Tests
Run with
-run 'ContributeMCP|TaskMCP|Knowledge'inpkg/dashboard, and all ofpkg/knowledge.These fail without the change:
TestTaskMCPKnowledgeFindsMultiWordQueryTestTaskMCPKnowledgeFindsWordPastTheSnippetTestTaskMCPKnowledgeServesFullBodyTestTaskMCPKnowledgeCutsOversizedBodyWithMarkerTestTaskMCPKnowledgeRepoRuleRunsBeforeLimitOnSearchHitsTestTaskMCPRepoConventionsFindsTypedFactTestTaskMCPRepoConventionsLimitCountsConventionsOnlyTestTaskMCPRepoConventionsRereadStaysInScope: another repository's copy, a draft copy, a copy that is not a conventionTestFullFactCarriesLifecycleOfThePageItReadandTestFullFactFromWikiLayerFollowsThePageStatusThese pass with and without the change. They guard rules that must hold on the new code paths:
TestTaskMCPKnowledgeQueryNeverServesOtherRepoFact: a matching fact of another repository is not served.TestTaskMCPKnowledgeNeverServesUnapprovedFact: draft, deprecated and superseded facts are not served.TestTaskMCPKnowledgeRereadStaysInScope: a re-read that lands on another repository's copy, or on a draft copy, is not served.TestTaskMCPKnowledgeKeepsLiteralMatchStoreSearchMisses: a lookup the store's search cannot answer still works.The existing
TestContributeMCPKnowledgeRequiresExactRepoTagBeforeLimitstill passes.🤖 Generated with Claude Code