Skip to content

fix: address review findings from 3-block system prompt PR#312

Merged
BYK merged 1 commit into
mainfrom
fix/review-issues
May 14, 2026
Merged

fix: address review findings from 3-block system prompt PR#312
BYK merged 1 commit into
mainfrom
fix/review-issues

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 14, 2026

Summary

Fixes all pre-existing and newly-identified issues from the code review of PR #311 (3-block system prompt).

Critical fixes

  • OpenAI/Responses API upstreams now receive LTM: Previously, LTM text was only passed via AnthropicCacheOptions, which only buildAnthropicRequest consumed. OpenAI Chat Completions and Responses API paths received req.system unmodified (no LTM). Fix: forwardToUpstream now concatenates stableLtmSystem + ltmSystem into req.system before calling OpenAI builders.

  • vectorSearch() now filters by category: Previously queried all knowledge entries with embeddings regardless of category. When excludeCategories: ["preference"] was passed to forSession(), the SQL filtered preferences out of the entry lists, but vectorSearch() still returned preference entries in its top-50 hits — crowding out relevant context-bound entries. Fix: add optional excludeCategories parameter to vectorSearch(), propagated from forSession().

Medium fixes

  • textDiffRatio rewritten: Old implementation only compared prefix + suffix characters, missing interior content changes entirely (e.g., entries added/removed in the middle). New implementation samples up to 1000 evenly-spaced positions across the full string length for O(1) cost, reliably detecting interior edits.

  • Context-bound LTM budget floor: Added a 50% minimum floor for context-bound entries. Previously, a project with many preferences could consume the entire LTM budget, starving gotchas/patterns/architecture entries that are more critical for correctness during active work.

Low fixes

  • KnowledgeCategory type alias: Exported from ltm.ts for autocomplete on well-known categories (decision, pattern, preference, architecture, gotcha). ForSessionOptions.categories and excludeCategories use (KnowledgeCategory | (string & {}))[] for type safety with escape hatch.

  • Cross-project excludeCategories test: Verifies the filter applies to cross-project entries too, not just project-local ones.

  • Empty excludeCategories array test: Confirms excludeCategories: [] has no filtering effect (falsy .length check).

Critical:
- OpenAI/Responses API upstreams now receive LTM in system prompt
  (previously silently dropped — only Anthropic path got LTM)
- vectorSearch() now accepts excludeCategories filter, preventing
  preference entries from consuming vector search slots when context-
  bound entries are requested separately

Medium:
- textDiffRatio rewritten to sample across full string length instead
  of only prefix+suffix — catches interior content changes that the
  old heuristic missed
- Context-bound LTM budget floor: guaranteed 50% of total LTM budget
  even when preferences are large, preventing preference starvation

Low:
- KnowledgeCategory type alias for well-known categories with autocomplete
- ForSessionOptions doc clarifies categories/excludeCategories mutual exclusion
- Tests for excludeCategories on cross-project entries and empty array edge case
@BYK BYK merged commit ce6e462 into main May 14, 2026
7 checks passed
@BYK BYK deleted the fix/review-issues branch May 14, 2026 16:50
@craft-deployer craft-deployer Bot mentioned this pull request May 14, 2026
6 tasks
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