Skip to content

feat: improve meta-request detection to prevent distilling title/summary conversations#253

Merged
BYK merged 1 commit into
mainfrom
feat/detect-meta-requests
May 12, 2026
Merged

feat: improve meta-request detection to prevent distilling title/summary conversations#253
BYK merged 1 commit into
mainfrom
feat/detect-meta-requests

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 12, 2026

Summary

  • Replace isTitleOrSummaryRequest() with isMetaRequest() using a two-layer detection approach to prevent meta conversations (title generation, summaries, categorization) from being stored and distilled
  • Add chat.headers hook to OpenCode plugin injecting x-lore-agent header for authoritative agent identification
  • Improve heuristic scoring with maxTokens and keyword signals alongside existing structural checks

Details

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 the chat.headers hook. We now inject it as x-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:

Signal Score Rationale
tools ≤ 2 +3 Real agents have 5+ tools
messages ≤ 2 +3 Meta requests are single-shot
system < 500 chars +2 Real prompts are 2K–50K
maxTokens ≤ 300 +3 Title gen uses tiny output budgets
Meta keywords in short system prompt +2 Bonus only, never standalone

Threshold: ≥ 8 (preserves backward compat — the old 3-check AND scored 3+3+2 = 8).

Files changed:

  • packages/opencode/src/index.tschat.headers hook
  • packages/gateway/src/compaction.tsisMetaRequest() with scoring
  • packages/gateway/src/pipeline.ts — updated import, call site, observability log
  • Tests and comments updated across 6 files

…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
@BYK BYK merged commit 9d690d7 into main May 12, 2026
7 checks passed
@BYK BYK deleted the feat/detect-meta-requests branch May 12, 2026 14:04
This was referenced May 13, 2026
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