Skip to content

fix: pass agent reasoning to suggestion extractor#577

Open
beng360 wants to merge 2 commits into
mainfrom
bengervais/dev-1256-improve-next-steps
Open

fix: pass agent reasoning to suggestion extractor#577
beng360 wants to merge 2 commits into
mainfrom
bengervais/dev-1256-improve-next-steps

Conversation

@beng360

@beng360 beng360 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Pass agent_reasoning from the summarization pipeline into SuggestionExtractor.extract_suggestions() — previously only the summary and 500-char truncated citations were sent, so the extractor had no idea what the agent actually concluded
  • Rewrite the suggestions prompt: allow 0 suggestions (correct when incident is transient/self-resolved), recognize existing PRs as the primary action, stop generating padding suggestions
  • Increase citation output caps (600/1200 chars for older/recent) so context about existing PRs and commands isn't lost

Tested against staging incident 4127c547 (the 4th firing of the error log spike alert). Before: 4 irrelevant generic infra commands. After: 2 suggestions — "merge PR #67" (correct) and "monitor Weaviate" (reasonable).

Closes DEV-1256

Test plan

  • Deploy to staging, trigger a new RCA on an incident with an existing fix PR — verify suggestion is "merge the PR"
  • Trigger a transient/self-resolved incident — verify 0 suggestions returned
  • Verify no regression on incidents that genuinely need diagnostic commands

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Improved suggestion generation by using more context from recent activity and prior reasoning, leading to more relevant recommendations.
  • Bug Fixes
    • Reduced overly long or repetitive suggestion output.
    • Improved handling of structured suggestions so fewer invalid or duplicate actions are proposed.

…teps

The SuggestionExtractor was generating irrelevant suggestions because it
only received the summary and truncated citations (500 chars), never the
agent's reasoning stream. This caused it to produce generic infra commands
even when the correct action was "merge existing PR" or "no action needed."

Changes:
- Pass agent_reasoning from summarization pipeline to extract_suggestions()
- Rewrite prompt: allow 0 suggestions, recognize existing PRs, no padding
- Increase citation output caps (600/1200 chars) so PR context isn't lost

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@beng360 beng360 requested a review from a team as a code owner July 3, 2026 15:10
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

SuggestionExtractor.extract_suggestions and _build_suggestions_prompt now accept an agent_reasoning parameter, which is injected into the LLM prompt as an "INVESTIGATOR REASONING" block. Citation truncation logic now varies caps by recency. The JSON output contract and rules were revised. The summarization caller now passes agent_reasoning.

Changes

Suggestion extraction reasoning input

Layer / File(s) Summary
Extractor entry point accepts agent_reasoning
server/chat/background/suggestion_extractor.py
extract_suggestions gains an agent_reasoning: str = "" parameter, documented and forwarded to prompt construction.
Prompt construction and citation truncation updates
server/chat/background/suggestion_extractor.py
_build_citation_context applies different output caps for recent vs older citations with ellipsis truncation; _build_suggestions_prompt adds an "INVESTIGATOR REASONING" block (trimmed to ~8000 chars) and revises the JSON contract (0–5 suggestions, nullable command, updated type/risk values, and updated RULES against redundant/padded suggestions).
Caller passes agent_reasoning
server/chat/background/summarization.py
generate_incident_summary_from_chat passes agent_reasoning=agent_reasoning or "" into extract_suggestions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Summarization as generate_incident_summary_from_chat
  participant Extractor as SuggestionExtractor
  participant Prompt as _build_suggestions_prompt
  participant LLM

  Summarization->>Extractor: extract_suggestions(agent_reasoning)
  Extractor->>Prompt: _build_suggestions_prompt(agent_reasoning, citations)
  Prompt->>Prompt: build INVESTIGATOR REASONING block
  Prompt->>Prompt: apply recency-based citation truncation
  Prompt-->>Extractor: prompt text
  Extractor->>LLM: send prompt
  LLM-->>Extractor: JSON suggestions (0-5)
Loading

Possibly related PRs

  • Arvo-AI/aurora#414: Both PRs thread agent reasoning ("incident_thoughts"/"agent_reasoning") into LLM-facing prompt inputs within the incident-summary generation flow.
  • Arvo-AI/aurora#516: Both PRs modify the suggestion prompt and JSON structure in server/chat/background/suggestion_extractor.py.

Suggested labels: bug

Suggested reviewers: damianloch

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: passing agent reasoning into the suggestion extractor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bengervais/dev-1256-improve-next-steps
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch bengervais/dev-1256-improve-next-steps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@beng360

beng360 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Validated against staging incident

Before (old extractor, no reasoning):

  • "Check pod health in aurora namespace"
  • "Review error logs for aurora-oss-server"
  • "Scale aurora-oss-chatbot replicas"
  • "Restart aurora-oss-server deployment"

All generic, none actionable. The extractor had no idea PR #67 existed or that the incident was transient.

After (with agent reasoning + new prompt):

[
  {
    "title": "Merge PR #67 and run terraform import to fix alert noise",
    "description": "This is the 4th identical firing of this alert. PR #67 changes the alert duration from 0s to 300s, eliminating false positives caused by pod restart windows during rolling deploys. A terraform import is required before merge to avoid state conflicts.",
    "type": "remediate",
    "risk": "low",
    "command": "gh pr merge 67 --repo arvo-ai/aurora-saas-prod --squash"
  },
  {
    "title": "Monitor Weaviate integration after second deploy completes",
    "description": "Weaviate is a new stateful component introduced in sha-259b4f7. Verify it is healthy and correctly integrated with aurora-oss-t2v-transformers once the rolling update finishes, as StatefulSet issues may not surface immediately.",
    "type": "diagnostic",
    "risk": "safe",
    "command": "kubectl get pods -n aurora -l app.kubernetes.io/name=aurora-oss-weaviate -o wide && kubectl logs aurora-oss-weaviate-0 -n aurora --tail=50"
  }
]

Root cause was simple: agent_reasoning (33k chars, 82 thought entries) was fetched by the summarizer but never passed to the extractor. The extractor was flying blind on a 500-char citation snippet.

arvo-ai-staging[bot]
arvo-ai-staging Bot previously approved these changes Jul 3, 2026

@arvo-ai-staging arvo-ai-staging Bot 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.

Aurora Risk Review

Verdict: SAFE

No risks identified. This change looks safe to ship.


Aurora reviews PRs for incident prevention.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/chat/background/suggestion_extractor.py`:
- Around line 157-166: The recent-citation cap logic in suggestion_extractor.py
is using the wrong base index for the sliced citations, so items in
citations[-15:] can be misclassified when there are fewer than 15 total
citations. Update the index calculation in the citation loop so it is based on
the actual slice start (for example, the enumerated position within the recent
subset) rather than len(citations) - 15, and use that corrected index to decide
between the 1200 and 600 character caps in the suggestion formatting logic.
- Line 200: The parsed suggestions list in _parse_suggestions_response() is not
enforcing the documented 0–5 limit, so all returned items are still being turned
into Suggestion objects. Update the parsing flow in SuggestionExtractor to clamp
the post-parse list to at most five entries before constructing Suggestion
instances, and keep the existing contract in sync with the return handling so
extra suggestions are discarded consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ffa82a57-34b0-4baf-a274-2bbadb4efc69

📥 Commits

Reviewing files that changed from the base of the PR and between 48d9489 and b664355.

📒 Files selected for processing (2)
  • server/chat/background/suggestion_extractor.py
  • server/chat/background/summarization.py

Comment thread server/chat/background/suggestion_extractor.py Outdated
Comment thread server/chat/background/suggestion_extractor.py Outdated
Resolve conflicts: suggestion_extractor.py and summarization.py.
The old SuggestionExtractor class is superseded by generate_recommendations()
in recommender.py (merged from main). Keep main's version which already passes
agent_reasoning through the new recommender pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

@arvo-ai-staging arvo-ai-staging Bot 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.

Aurora Risk Review — Latest changes

Verdict: SAFE

No new incident risk in the latest changes.


Aurora reviews PRs for incident prevention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant