Reuse parent prompt cache for asynchronous token-budget summaries - #321
Reuse parent prompt cache for asynchronous token-budget summaries#321furgalep wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. 📝 WalkthroughWalkthroughThe change adds asynchronous provider-request forking for token-budget summarization. It preserves parent requests, validates fork results, supports standalone fallback, exposes runtime context fields, adds shutdown handling, improves summary recovery instructions, and provides provider probes and tests. ChangesForked summarization
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~60 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant Agent
participant Summarizer
participant Middleware
participant Provider
Agent->>Summarizer: schedule token-budget summary
Summarizer->>Middleware: run isolated fork request
Middleware->>Provider: send parent-prefix request
Provider-->>Middleware: return summary response
Middleware-->>Summarizer: return validated summary or fallback signal
Summarizer-->>Agent: apply summary if source events are unchanged
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The summary recovery guidance is covered by regression tests and does not leave an actionable merge risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
|
Added deterministic archive-recovery instructions to Summary.doc (96a74d8): search including archived events with a bounded result count, read an original event by tag, and expand this summary or nested summaries. The LLM does not generate these instructions. Four new regression cases failed before the change; 88 targeted tests pass afterward, including rendered hints and collapse/resume coverage. Ruff and formatting pass. Sent the delta to Wren for re-review. |
d26bbe6 to
b926359
Compare
96a74d8 to
44873c7
Compare
Signed-off-by: Paul Furgale <pfurgale@nvidia.com>
Signed-off-by: Paul Furgale <pfurgale@nvidia.com>
Signed-off-by: Paul Furgale <pfurgale@nvidia.com>
Signed-off-by: Paul Furgale <pfurgale@nvidia.com>
b926359 to
c990906
Compare
44873c7 to
432913f
Compare
Published head:
44873c71. Rebased on the updated #319/#318. Summarizer changes are unchanged. Agents/runtime/UnifiedLLM regression suite: 2,098 passed, 3 skipped.Summary
Make token-budget summarization an asynchronous branch of the parent's completed LLM request. It reuses the same rendered messages, tools, client, sampling settings and cache-routing key, then appends a short summary instruction.
This is a conversation fork, not a clone of the Python agent. No new UnifiedLLM abstraction or provider-name rules are added.
Stack: based on #319 (which depends on #318); parallel to #320.
Why
The standalone summarizer renders history again as Markdown under a different prompt. That history cannot reuse the parent's cached prefix. The middleware boundary already has the request that was sent, so it provides the smallest reuse point without another renderer pass or a stored-request interface.
The parent keeps running. The fork sees only events present before that request; the new response and tool work remain active. A completed summary is applied at the existing BeforeTurn boundary, and only if its source event IDs still match.
Code walkthrough — what changed and why
agents/summarization.py: TokenBudgetSummarizer installs an LLM middleware handler. Provider usage triggers one background fork; a task-local guard prevents recursive forks. A small container-copy helper detaches only dicts/lists and borrows tools, clients, response objects and cache boundaries. This protects asynchronous inputs without cloning tool owners or opaque state.return_resultwhose result is a nonempty string, decoded as data. An unusable model reply gets one standalone attempt; provider/policy exceptions leave history untouched rather than taking that fallback.runtime/actor.pyandruntime/middleware.py: expose the effective client and filtered-history flag on LLMCallContext; retain the effective cache key in its params after dispatch. This includes method-specific model overrides without inspecting strategy/provider internals in the summarizer. Tests verify installing the summarizer does not change the parent request.TokenBudgetConfig.reuse_parent_prefix=Trueis the default. False, an explicitly different summarizer client, filtered history, or structured output uses standalone summarization. Model-limit updates preserve that setting. MethodSummarizer remains standalone.SummarizationAgent.aclose()unsubscribes and awaits task cancellation. CodingAgent closes summarizers before their shared client, so shutdown cannot leave a background call using a closed pool.Live evidence
One run per variant, NVIDIA Inference Hub, 2026-09-13:
Both installed summaries preserved the test decision, budget and owner and were applied successfully. An initial installed probe correctly rejected a CodeAct return_result reply; that led to the data-only decoding regression and fix.
Total live spend: 12 calls, 95,472 input tokens (including cached tokens), 786 output tokens. No additional paid rerun after the ownership/fallback/shutdown review fixes; their request shape is unchanged and checked offline.
Limits
Validation
Wren accepted source head
23ac4824after independent review and 2,473 scoped tests. Regressions were observed failing before fixes. Parent-request parity, actual SDK wire prefixes, bound-tool ownership and nested-container isolation are covered. Ruff and whitespace checks pass.Full offline rerun on
23ac4824: 7,699 passed, 6 skipped, 311 deselected, 3 expected failures, in 266 seconds. Published head1f7023dbadds only the final validation paragraph to the experiment README.Design, reproduction commands, and results.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation