fix(memory): enforce auto-inject budget and correct search schema - #1487
fix(memory): enforce auto-inject budget and correct search schema#1487longlonggo wants to merge 1 commit into
Conversation
clark-cant
left a comment
There was a problem hiding this comment.
LGTM — clean, focused fix with proper test coverage. The budget enforcement logic is sound, and removing the unsupported depth parameter aligns the schema with actual behavior. Safe to merge.
clark-cant
left a comment
There was a problem hiding this comment.
Maintainer review — github-maintain
Summary: Well-scoped fix enforcing the auto-inject memory budget (MaxTokens) and removing the unsupported depth parameter from memory_search schema. Two concrete bugs addressed: (1) auto-injector ignored MaxTokens allowing unbounded prompt growth, (2) schema advertised a depth param that was never consumed.
Risk level: Low — changes are isolated to memory auto-injection and tool schema, no store/schema migrations.
Mandatory gates:
- Duplicate/prior implementation: clear — no overlapping PRs found
- Project standards: consistent with existing patterns (tokencount usage, table-driven tests)
- Strategic necessity: clear value — prevents prompt budget blowout and removes misleading tool schema
Findings:
- Suggestion:
auto_injector_impl.gocallscounter.Count("", sb.String()+line)on each loop iteration, rebuilding the full string each time. With small budgets (200 tokens default) this is fine, but a running total (currentTokens += counter.Count("", line)) would be O(n) instead of O(n²). Minor — not blocking.
Verdict: Comment — clean fix, safe to merge once CI checks run and pass. Awaiting CI on the dev base branch.
Posted by github-maintain at 2026-07-31T18:28:30Z
clark-cant
left a comment
There was a problem hiding this comment.
Review — github-maintain
Summary: Enforces auto-inject MaxTokens budget (previously only entry-count limited) and removes the unsupported depth schema parameter from memory_search.
Risk level: Low — targeted, well-scoped change (+103/-10, 4 files) with regression tests.
Mandatory gates:
- Duplicate / prior implementation: clear — no overlapping PRs or issues found.
- Project standards: aligned with existing patterns (uses
tokencount.NewFallbackCounter(), follows existing auto-injector structure). - Strategic necessity: clear value — prevents unbounded prompt budget consumption and removes misleading tool schema.
Findings: None at Critical or Important level.
Verdict: Approve — clean implementation, good test coverage, no security or breaking-change concerns.
Posted by /ck:review-pr at 2026-08-01T00:00:00Z
clark-cant
left a comment
There was a problem hiding this comment.
Review: fix(memory): enforce auto-inject budget and correct search schema
Summary: Fixes two memory tool contract issues: (1) auto-injector now respects MaxTokens budget across the full injected section (was only limiting entry count), applying the documented 200-token default; (2) removes the unsupported depth parameter from memory_search schema and directs callers to memory_expand for full episodic content.
Risk level: Low — focused bugfix in two packages with clean test coverage.
Mandatory gates:
- Duplicate / prior implementation: clear — no overlapping PR or prior fix found
- Project standards: docs found — aligns with existing memory tool contract
- Strategic necessity: clear value — prevents unbounded prompt token growth from memory injection and removes misleading schema
Findings:
- No Critical or Important issues
- Suggestion:
counter.Count("", sb.String()+line)re-counts the entire accumulated section per entry; for large budgets this is O(n²) in token counting calls. Acceptable for the 200-token default ceiling, but worth noting if the budget is ever raised significantly.
Verdict: Approve
Local tests noted in PR body (go test ./internal/memory ./internal/tools ./internal/agent) cover both changes. Merge deferred: no GitHub checks reported and mergeStateStatus is UNSTABLE.
Posted by github-maintain at 2026-08-08T18:00Z
Summary
InjectParams.MaxTokensacross the complete auto-injected memory sectionMaxTokensunsetmemory_search.depthschema parametermemory_expandwhen they need full episodic contentRoot cause
pgAutoInjector.Injectlimited only the number of L0 entries. It never readMaxTokens, so long abstracts could exceed the documented prompt budget.memory_searchadvertiseddepthvalues (l0,l1, andl2), but itsexecution path never consumed that argument. Episodic search already returns L0
previews and exposes
memory_expandas the explicit full-content operation.Behavior after this change
conservative fallback token counter
depthremain tolerated because tool executionignores unknown arguments; the unsupported option is simply no longer advertised
Validation
go test ./internal/memory ./internal/tools ./internal/agentgo build ./...go build -tags sqliteonly ./...go vet ./...go test -race -tags integration ./tests/integration/The full
go test ./...run reached one unrelated environment-specific failure:TestProvidersHandlerCreateAllows1536EmbeddingDimensionsresolvedgenerativelanguage.googleapis.comto reserved address198.18.28.90, so theprovider URL guard returned HTTP 400 instead of the test's expected 201. The
memory, tools, and agent packages passed.
Surface parity
depthschema removed;memory_expandguidance added.