ADORSYS-GIS / ADORSYS-GIS/lightbridge-code-intelligence
[Ticket]: Investigate summary-first context expansion for review runs
- Lingua principale
- Rust
- Stelle
- 0
- Fork
- 0
- Merge medio
- 14h 13m
- PR unite (30g)
- 16
Descrizione
## Type
Spike / Investigation
## Summary
We need to investigate summary-first context expansion because large review-context blocks can consume the model context budget before the agent knows which information is relevant.
Expected result:
> Determine whether Lightbridge should provide concise summaries for context blocks and expose a mediated expansion tool that retrieves the full block only when needed, while preserving explicit truncation disclosures, budgets, provenance, and validation.
## Intent
Improve review efficiency without weakening review quality. The initial review request should contain enough information for orientation, while deeper repository instructions, prior reviews, feedback memory, and other context should remain available through a controlled, auditable expansion path.
## Source of truth (links)
- PR #632: https://github.com/ADORSYS-GIS/lightbridge-code-intelligence/pull/632
- Current context block budgeting: https://github.com/ADORSYS-GIS/lightbridge-code-intelligence/blob/main/services/review-agent/src/prompt.rs
- Current retrieval and empty-result semantics: https://github.com/ADORSYS-GIS/lightbridge-code-intelligence/blob/main/services/review-agent/src/tools.rs
- Existing retrieval architecture: https://github.com/ADORSYS-GIS/lightbridge-code-intelligence/blob/main/docs/indexing-and-storage.md
## Current Behavior
Lightbridge assembles bounded context blocks into the review prompt. When a block exceeds its budget, it is truncated and an explicit marker reports what was shown versus the original size. Prompt-budget metrics record input, rendered, and budget sizes. Empty retrieval results are explicitly described as inconclusive and the agent is directed to inspect the source directly.
The system does not currently provide a summary-first context-block abstraction or a tool to expand a previously summarized block.
## Expected Behavior
The investigation should establish whether a context block can expose:
- a concise summary;
- block identity, source, freshness, and provenance;
- an indication that full content is available;
- a mediated, budget-aware expansion operation.
If viable, the implementation should allow the agent to request full content selectively and should preserve the current behavior when summaries are unavailable or expansion is not requested.
## Acceptance Criteria
- [ ] A written design compares the current bounded-block approach with summary-first progressive disclosure.
- [ ] The design defines block identity, provenance, freshness, summary generation, full-content retrieval, and token/character accounting.
- [ ] The design explains how the model is told that content is omitted because of budget rather than absent from the repository.
- [ ] The design specifies allowlist, authorization, audit logging, and failure behavior for context expansion.
- [ ] The design evaluates whether summaries are generated at indexing time, review time, or both.
- [ ] The design identifies stale-summary, incomplete-summary, expansion-loop, and budget-exhaustion risks with mitigations.
- [ ] A prototype or focused tests demonstrate that an agent can receive a summary and request the corresponding full block without exceeding the configured context budget.
- [ ] Existing truncation disclosures, retrieval semantics, review termination, and current image/documentation behavior are not regressed.
- [ ] Verification evidence is provided for the selected recommendation and its limitations.
## Out of Scope
- Replacing the existing context-budget implementation without an evaluated design.
- Changing the review tool allowlist enforcement delivered in PR #632.
- Changing the embedding model, vector-search strategy, or repository indexing schema.
- Claiming that a summary improves precision or recall before a model evaluation is available.
## Technical Context
The current prompt builder applies proportional and absolute budgets to diff, prior-review, feedback-memory, project-instruction, and repository-config blocks. Oversized blocks receive an explicit truncation marker, and per-block byte accounting is logged.
Relevant implementation:
- `services/review-agent/src/prompt.rs` — prompt blocks, budgets, truncation markers, and metrics.
- `services/review-agent/src/tools.rs` — explicit empty-retrieval response and source-verification guidance.
- `services/control-plane/src/db/code_chunks.rs` — snapshot-scoped semantic retrieval.
- `services/review-agent/src/opencode/` — mediated review host and review-cycle control.
## Risks
- A summary may omit the detail needed for a correct finding. Mitigation: preserve full content behind an explicit expansion operation and require provenance.
- A summary may become stale when repository instructions or feedback changes. Mitigation: attach freshness/version metadata and invalidate summaries with their source.
- The agent may repeatedly expand blocks and increase cost. Mitigation: enforce per-run expansion budgets and log every expansion.
- Summary generation may add indexing or review latency. Mitigation: compare precomputed and on-demand generation and measure both paths.
- Expansion may create a second context path that bypasses existing tool policy. Mitigation: route it through the same allowlist and context-budget controls.
## Test Plan
- Unit-test summary metadata and block-expansion budget accounting.
- Test missing, stale, malformed, and oversized blocks.
- Test that an expansion request is refused when the tool is not offered or the budget is exhausted.
- Test that truncation and empty-retrieval disclosures remain explicit.
- Run the existing review-agent and agent-loop test suites.
- Prototype against a small curated set of review contexts and compare prompt size, expansion count, latency, and review outcomes.
## Verification evidence
Not implemented yet; this ticket is the investigation and design entry point. Evidence will include the design decision, focused tests or prototype output, and measured prompt/latency trade-offs.
## Human accountable owner
@AssahBismarkabah
## AI Usage Declaration
- [x] Drafting the ticket
- [x] Understanding code
- [x] Proposing implementation
- [ ] Generating code
- [ ] Generating tests
- [ ] Reviewing the diff
- [ ] Not used
## Human verification completed
- [ ] I understood the intent
- [ ] I checked the source of truth
- [ ] I reviewed all AI-generated text/code
- [ ] I verified the implementation manually
- [ ] I verified the tests
- [ ] I checked for hallucinated assumptions
- [ ] I documented remaining risks
- [ ] I am the accountable owner and accept responsibility for this ticket.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.