Phase 3 — Efficiency: close P3-3/P3-4/P3-5/P3-6 #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/phase3-efficiency"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes the remaining Phase 3 — Efficiency findings (P3-3, P3-4, P3-5, P3-6). With this, all 6 Phase 3 findings are resolved (P3-1/P3-2 already merged to
main).Findings closed
time/datecontext queries now carryLIMIT $N(maxContextMessages, default 100) instead of fetching every row in the window and truncating in JS. The(channel_id, timestamp DESC)index returns newest-first, so the cap keeps exactly the rowsContextManagerwould have kept.setCacheBreakpointhelper places one movingcache_control: {type:"ephemeral"}breakpoint on the last message before each tool-loop request, so rounds 2+ read the prior round's prefix (tools + system + prior turns) at ~0.1× input price. Added only when tools are enabled; stale breakpoints are stripped first so there is never more than one (the API's 4-breakpoint cap is never at risk).timestampindex left as-is by decision — a standalone index would tax the hot INSERT path to speed a once-a-day purge on a small table; (b) purge uses the driverrowCountvia a newdatabase.execute()instead ofRETURNING idjust to count; (c)RETENTION_DAYSis now wired toconfig.storage.retentionDaysinstead of a hardcoded 30; (d) deadgetStorageStats()+StorageStatstype + test mocks deleted (also closes P4-4b).D2EMU_POLL_INTERVAL_MS. No code change.Commits
P3-4/P3-6: LIMIT context queries; wire RETENTION_DAYS; drop dead statsP3-3: prompt-cache breakpoint for the admin tool loopLog Phase 3 fixes in FINDINGS.md — Phase 3 closedVerification
ClaudeClient.cache.test.tspinning the cache-breakpoint invariantsNotes / deviations (documented in FINDINGS.md)
StorageStatstype went out withgetStorageStats()).🤖 Generated with Claude Code
The tool loop re-sends the entire growing conversation each round at full input price; worst-case admin commands run to ~100-150K uncached input tokens. A new setCacheBreakpoint helper places a single moving cache_control: {type: "ephemeral"} breakpoint on the last content block of the last message before each request, so rounds 2+ read the prefix (tools + system + prior turns) the previous round wrote at ~0.1x input price. The breakpoint is added only when tools are enabled — plain chat requests never reuse the prefix, so caching would just pay the write premium. The helper strips any stale breakpoint before setting the new one, so there is never more than one and the API's 4-breakpoint cap is never at risk. New ClaudeClient.cache.test.ts pins both invariants: exactly one breakpoint per request always on the last block, and none on non-admin requests. Done standalone rather than bundled with P4-2's ClaudeClient decomposition — the helper is self-contained and did not need the split. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>