Skip to content

feat(release): cache-aware compaction, LLM extract, and production hardening#14

Merged
OsherElhadad merged 3 commits into
mainfrom
release/cache-aware-v2
Jul 25, 2026
Merged

feat(release): cache-aware compaction, LLM extract, and production hardening#14
OsherElhadad merged 3 commits into
mainfrom
release/cache-aware-v2

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

Next release: cache-aware compaction, LLM extract, and production hardening

This is the release cut. It ships the cache-aware compaction redesign and the cheap-model
relevance-trimmer, then hardens the whole request path for production based on a
multi-agent review (security, generalizability, correctness, dead-code, tests, docs).

Highlights

Presets & defaults

  • New default presets from the SWE-bench study: codesmart (the default — cache-aware
    [format, dedup, failed_run, cmdfilter, extract_llm, extract, cacheinject]) and
    codesafe (deterministic-only, zero model calls by policy). Presets can now carry
    tuned per-component config. extract_llm engages only when a cheap model is configured
    (CHEAP_MODEL*) and safely no-ops to deterministic otherwise.
  • Removed the phi_evict component (superseded by mask).

Cache stability (core invariant)

  • mask freezes and replays its decision byte-identically every turn, so a masked output
    that slides into the cached prefix no longer reverts to full and churns the KV cache.
  • All offloaders uniformly honor kept-verbatim / existing-marker skips — content the agent
    just expanded is never re-compacted into an expand loop.
  • GET /expand is scoped to the owning session, closing a cross-session/tenant disclosure
    of stashed originals.

Correctness

  • stripTerminalNoise no longer blanks CRLF-terminated tool output.
  • AggregateSSE preserves extended-thinking blocks (+signature) so the expand
    continuation builds a valid assistant turn.
  • UTF-8-safe truncation (headPeek, dump trace); resolveCacheAware detects a real
    breakpoint structurally instead of substring-scanning the body.

Reliability / security

  • Top-level fail-open recover (apply.BodyFull, proxy pre-forward, emitters) — a panic
    outside a component forwards the original request instead of 500-ing.
  • Bounded request bodies (MaxBytesReader); Starlark sandbox input-cap + heap-growth
    watchdog; skeleton tree-walk depth bound (uncatchable stack-overflow crash); modelinfo
    window resolution is now a single-flighted, non-blocking background fetch with negative
    caching; debug/dump files created 0600.

Cleanup, tests & docs

  • Removed dead code (internal/extract/cache.go, RunExtractionBatch/buildBatchPrompt,
    lastUserText, overlap, writeBuffered, modelinfo.Default) and internal-only docs
    (docs/superpowers/).
  • New regression tests for every fix above. Full suite + -race green; mkdocs --strict clean.
  • README + docs overhaul with the three-way SWE-bench results (cheapest arm; beats headroom
    on cost/cache/steps/reward) and live-captured per-component before/after examples.

Verification

  • CGO_ENABLED=1 go build -tags cg_skeleton ./... and go test -tags cg_skeleton ./... — green.
  • go test -race on the concurrency-touched packages — green.
  • Proxy boots on the codesmart default and round-trips a real Anthropic request
    (3605 → 93 tokens on a repeated-output transcript); mkdocs build --strict clean.

…rdening

The next-release cut of context-guru. Ships the cache-aware compaction redesign
and the LLM relevance-trimmer, then hardens the whole path for production based on
a multi-agent review (security, generalizability, bugs, dead code, tests, docs).

Presets & defaults
- New default presets shipping the SWE-bench-winning config: `codesmart`
  (cache-aware `[format, dedup, failed_run, cmdfilter, extract_llm, extract,
  cacheinject]`, extract_llm routed to CHEAP_MODEL and gated so most turns make no
  model call) and `codesafe` (deterministic-only, zero model calls by policy).
  Presets can now carry tuned per-component config (presetConfigs); the proxy
  default is `codesmart`. Without a cheap model, extract_llm safely no-ops.
- Removed the `phi_evict` component (superseded by `mask`).

Cache stability (the release's core invariant)
- `mask` now freezes its decision and replays it byte-identically every turn, so a
  masked output that slides into the cached prefix no longer reverts to full and
  churns the provider KV cache (previously only `failed_run` did this).
- Every offloader now honors kept-verbatim + existing-marker skips uniformly, so
  content the agent just expanded is never re-compacted into an expand-loop.
- GET /expand is scoped to the owning session (per-(session,key) ownership record),
  closing a cross-session/tenant disclosure of stashed originals.

Correctness fixes
- stripTerminalNoise no longer blanks CRLF-terminated tool output (the trailing CR
  is the line separator, not an in-line progress redraw).
- AggregateSSE reconstructs extended-thinking blocks (thinking_delta +
  signature_delta), so the expand continuation builds a valid assistant turn.
- UTF-8-safe truncation in headPeek and the dump trace (no split runes).
- resolveCacheAware detects a real cache_control/cachePoint breakpoint structurally
  instead of substring-scanning the whole body (no false positives from tool text).

Reliability / security hardening
- Top-level fail-open recover around apply.BodyFull, the proxy pre-forward path, and
  emitter callbacks — a panic outside a component now forwards the original request.
- Request bodies are bounded (http.MaxBytesReader) to prevent memory-exhaustion DoS.
- Starlark sandbox gains an input-size cap and a heap-growth watchdog (the step/time
  limits can't preempt a native op); skeleton's tree walk gains a depth bound
  (an unbounded recursion is an uncatchable stack-overflow crash).
- modelinfo resolves the model window via a single-flighted, non-blocking background
  fetch with negative caching (was a synchronous hot-path GitHub GET, refetch-on-fail).
- Debug/dump files created 0600 (they persist raw payloads).

Cleanup
- Removed dead code (internal/extract/cache.go, RunExtractionBatch/buildBatchPrompt,
  lastUserText, overlap, writeBuffered, modelinfo.Default + unused `once`) and
  internal-only docs (docs/superpowers/). Retired stale phi_evict references and
  visualizations.

Tests & docs
- New regression tests: mask byte-stability across turns, kept-verbatim skip,
  CRLF preservation + interior-CR redraw, headPeek UTF-8, AggregateSSE thinking-block
  preservation, modelinfo single-flight/non-blocking, /expand session scoping, and
  rich-preset config resolution. Full suite + race detector green; mkdocs --strict clean.
- README + docs overhaul with the three-way SWE-bench results (cheapest arm, beats
  headroom on cost/cache/steps/reward), per-component live-captured before/after
  examples, and corrected build/quickstart.

Assisted-By: Claude (Anthropic)
Signed-off-by: Osher Elhadad <osher.elhadad@live.biu.ac.il>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The build-test job failed on the gofmt check: three files edited in the release
commit (p4_test.go, common.go, proxy.go) were left unformatted after the phi_evict
removal and inline edits. gofmt -w applied.

Adds a `make cover` target (race + cross-package coverage → coverage.out, prints the
statement-weighted total; currently 74.0%) so coverage can be surfaced in CI.

Assisted-By: Claude (Anthropic)
Signed-off-by: Osher Elhadad <osher.elhadad@live.biu.ac.il>
The Test step now runs `make cover` and writes the statement-weighted total
coverage to the run's job summary (visible on every PR), plus per-package coverage
in the log.

Assisted-By: Claude (Anthropic)
Signed-off-by: Osher Elhadad <osher.elhadad@live.biu.ac.il>
@OsherElhadad
OsherElhadad merged commit 37ffbac into main Jul 25, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants