feat: improve meta-request detection to prevent distilling title/summary conversations#253
Merged
Conversation
…ary conversations Replace isTitleOrSummaryRequest() with isMetaRequest() using a two-layer approach: an explicit x-lore-agent header from the OpenCode plugin for authoritative agent identification, plus improved heuristic scoring (structural signals + maxTokens + keyword bonus) for all clients. - Add chat.headers hook to OpenCode plugin injecting x-lore-agent header - Replace rigid boolean gate with weighted scoring system (threshold 8) - Add maxTokens <= 300 as a strong signal for title generation requests - Add keyword matching on short system prompts as a bonus signal - Add observability logging when meta requests are detected - Expand test suite with header, maxTokens, and keyword coverage
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.
Summary
isTitleOrSummaryRequest()withisMetaRequest()using a two-layer detection approach to prevent meta conversations (title generation, summaries, categorization) from being stored and distilledchat.headershook to OpenCode plugin injectingx-lore-agentheader for authoritative agent identificationmaxTokensand keyword signals alongside existing structural checksDetails
Problem: The gateway's meta-request filter used a narrow structural heuristic (tools ≤ 2, messages ≤ 2, system < 500 chars) that could miss title/summary requests with slightly different shapes, causing them to be stored in temporal and distilled into session history.
Layer 1 — Explicit header: The OpenCode plugin SDK provides the agent name (e.g.,
"coder","title") via thechat.headershook. We now inject it asx-lore-agent, giving the gateway an authoritative signal. Known meta agents (title,summary,categorize, etc.) are always passthrough; known primary agents (coder,code) are never meta.Layer 2 — Improved heuristics: For non-OpenCode clients (Claude Code, Pi, generic), we replace the rigid boolean gate with weighted scoring:
Threshold: ≥ 8 (preserves backward compat — the old 3-check AND scored 3+3+2 = 8).
Files changed:
packages/opencode/src/index.ts—chat.headershookpackages/gateway/src/compaction.ts—isMetaRequest()with scoringpackages/gateway/src/pipeline.ts— updated import, call site, observability log