Skip to content

OLS-3781: Give verification agent retry autonomy for convergence-dependent checks - #423

Open
blublinsky wants to merge 1 commit into
openshift:mainfrom
blublinsky:verification-prompt
Open

OLS-3781: Give verification agent retry autonomy for convergence-dependent checks#423
blublinsky wants to merge 1 commit into
openshift:mainfrom
blublinsky:verification-prompt

Conversation

@blublinsky

Copy link
Copy Markdown
Contributor

Prompt-only change to the verification query template.

The verification agent now has autonomy to handle convergence-dependent checks (alerts clearing, pods becoming ready, metrics stabilizing) by waiting and retrying within its sandbox session, bounded by the existing sandbox timeout.
No schema, API, or controller logic changes.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 6, 2026
@openshift-ci-robot

openshift-ci-robot commented Aug 6, 2026

Copy link
Copy Markdown

@blublinsky: This pull request references OLS-3781 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Prompt-only change to the verification query template.

The verification agent now has autonomy to handle convergence-dependent checks (alerts clearing, pods becoming ready, metrics stabilizing) by waiting and retrying within its sandbox session, bounded by the existing sandbox timeout.
No schema, API, or controller logic changes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a23d80f-4847-4754-ab2a-f55d8a676abd

📥 Commits

Reviewing files that changed from the base of the PR and between c4c48af and 1c2999a.

📒 Files selected for processing (1)
  • controller/agenticrun/templates/verification_query.tmpl
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/lightspeed-agentic-sandbox (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/agenticrun/templates/verification_query.tmpl

📝 Walkthrough

Summary by CodeRabbit

  • Improvements
    • Verification results now report each planned check in order with clear Passed/Failed status and supporting evidence.
    • Added guidance for read-only alternatives and limited syntax-only corrections without changing command scope.
    • Convergence checks now include appropriate wait intervals, bounded retries, and final observations.
    • Immediate state checks are not retried, and unrelated checks are excluded.
    • Updated agent guidance for broader cluster environments while preserving inspection and remediation behavior.

Walkthrough

Agent prompts now use cluster-generic roles. Verification requires read-only commands, evidence for each planned check, syntax-only corrections, and bounded retries for convergence-dependent checks. Tests assert the read-only and retry guidance.

Changes

AgenticRun prompt updates

Layer / File(s) Summary
Prompt roles and verification contracts
controller/agenticrun/templates/analysis_query.tmpl, controller/agenticrun/templates/execution_query.tmpl, controller/agenticrun/templates/verification_query.tmpl
Analysis and execution prompts use cluster-generic roles. Verification follows approved-plan order, reports status and evidence, permits syntax-only corrections, prohibits extra checks, and restricts commands to read-only access.
Convergence retries and test coverage
controller/agenticrun/templates/verification_query.tmpl, controller/agenticrun/revision_test.go, controller/agenticrun/sandbox_agent_test.go
Verification adds category-specific waits and ten-retry limits for convergence-dependent checks. Immediate state checks are not retried. Tests assert read-only access and retry guidance.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: enabling verification-agent retries for convergence-dependent checks.
Description check ✅ Passed The description accurately explains the prompt-only retry changes and confirms that no schema, API, or controller logic changes are included.
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.

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.

@openshift-ci
openshift-ci Bot requested review from JoaoFula and xrajesh August 6, 2026 11:27
@openshift-ci

openshift-ci Bot commented Aug 6, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign blublinsky for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 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 `@controller/agenticrun/sandbox_agent_test.go`:
- Around line 543-548: Strengthen the verification-query assertions in the
relevant sandbox agent test by checking each required convergence retry wait
interval, the maximum of five retries, and the rule excluding instant state
checks from retries. Keep the existing heading and generic retry assertions, and
ensure the test validates the complete bounded retry guidance.

In `@controller/agenticrun/templates/verification_query.tmpl`:
- Around line 3-16: Rewrite the verification template so every sentence contains
no more than 20 words. Replace “e.g.” with plain examples, remove “should,” and
preserve all verification, retry, evidence, and reporting requirements.
- Around line 7-16: Update the verification retry logic in the verification
query template to enforce a total deadline based on the remaining sandbox time,
not just per-check retry counts. Before each delayed retry, verify enough time
remains for another attempt; stop when it does not, and report failure with the
last observed value. Preserve later-pass reporting as Passed and keep all
retries within the existing sandbox timeout.
🪄 Autofix

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: CHILL

Plan: Pro Plus

Run ID: 5569ca39-c710-498c-babc-945713653717

📥 Commits

Reviewing files that changed from the base of the PR and between 303f265 and 5fc0273.

📒 Files selected for processing (2)
  • controller/agenticrun/sandbox_agent_test.go
  • controller/agenticrun/templates/verification_query.tmpl
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/lightspeed-agentic-sandbox (manual)

Comment on lines +543 to +548
if !strings.Contains(httpClient.lastQuery, "Convergence-dependent checks") {
t.Error("verification query should contain convergence retry guidance")
}
if !strings.Contains(httpClient.lastQuery, "wait an appropriate interval and retry") {
t.Error("verification query should instruct agent to retry convergence checks")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert the bounded retry rules.

These assertions only require a heading and a generic retry phrase.
They pass if the wait ranges, five-retry cap, or instant-check exclusion are removed.
Assert each retry interval, the retry cap, and the no-retry rule for instant state checks.

Based on the PR summary, tests must assert retry guidance and the required wait interval.

🤖 Prompt for 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.

In `@controller/agenticrun/sandbox_agent_test.go` around lines 543 - 548,
Strengthen the verification-query assertions in the relevant sandbox agent test
by checking each required convergence retry wait interval, the maximum of five
retries, and the rule excluding instant state checks from retries. Keep the
existing heading and generic retry assertions, and ensure the test validates the
complete bounded retry guidance.

Comment thread controller/agenticrun/templates/verification_query.tmpl Outdated
Comment on lines +7 to +16
Some checks depend on cluster state that takes time to converge after a remediation (e.g., alerts clearing, pods becoming ready, metrics dropping below a threshold, conditions stabilizing). For these checks:

- If the check fails on the first attempt, **wait an appropriate interval and retry** before reporting failure.
- Use your judgment on wait duration and retry count based on the check type:
- **Alerts** (e.g., alert stopped firing): wait 30–60 seconds between retries, up to 5 retries.
- **Pod readiness / rollout**: wait 10–20 seconds between retries, up to 5 retries.
- **Metrics** (e.g., error rate below threshold): wait 30–60 seconds between retries, up to 5 retries.
- **Instant state checks** (e.g., image tag matches, config value set): no retry needed — these reflect immediately.
- A check that **passes on a later retry** should be reported as **Passed**, not Failed.
- Do not retry indefinitely — if the check still fails after retries, report it as Failed with the last observed value.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Set a total retry deadline.

The per-check limits do not limit total wait time across the verification plan.
With several convergence-dependent checks, the agent can exceed the sandbox timeout before it reports results.
Set a deadline from the remaining sandbox time. Stop retries when the remaining time cannot support another attempt.

Based on PR objectives, retries must stay within the existing sandbox timeout.

🤖 Prompt for 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.

In `@controller/agenticrun/templates/verification_query.tmpl` around lines 7 - 16,
Update the verification retry logic in the verification query template to
enforce a total deadline based on the remaining sandbox time, not just per-check
retry counts. Before each delayed retry, verify enough time remains for another
attempt; stop when it does not, and report failure with the last observed value.
Preserve later-pass reporting as Passed and keep all retries within the existing
sandbox timeout.

@blublinsky
blublinsky force-pushed the verification-prompt branch from 5fc0273 to 6468a8e Compare August 6, 2026 12:24
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 6, 2026
@blublinsky
blublinsky force-pushed the verification-prompt branch from 6468a8e to 5f815f4 Compare August 6, 2026 12:33
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@blublinsky
blublinsky force-pushed the verification-prompt branch from 5f815f4 to 75b182a Compare August 6, 2026 15:39
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@blublinsky
blublinsky force-pushed the verification-prompt branch 2 times, most recently from eee47ba to 9e7484c Compare August 6, 2026 16:31
@@ -1,10 +1,10 @@
You are an analysis agent for OpenShift clusters. Diagnose the problem. Determine the root cause. Produce a remediation plan. A human will review and approve this plan before execution. Do NOT run commands that change the cluster state. You can only read. Write remediation commands for an execution agent to run after human approval.

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.

why delete for OpenShift clusters ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cause we are running on Openshift cluster. It does not seem to add any useful info

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.

how does the agent know this without encountering oc/kubectl in the prompt. isnt it better to be explicit?

@blublinsky
blublinsky force-pushed the verification-prompt branch from 9e7484c to c4c48af Compare August 6, 2026 16:39
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@vimalk78 vimalk78 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.

Code Review

2 finding(s) posted as inline comments on the diff.

🚨 Critical: VerificationStep schema missing retryCount and retryIntervalSeconds fields (AC1 unmet)

api/v1alpha1/agenticrun_analysis_types.go:159

Detail

AC1 requires VerificationStep to gain retryCount and retryIntervalSeconds fields so retry behaviour is configurable per check. The struct at line 159 is unchanged — it still has only Name, Command, Expected, and Type. Without these fields, ACs 2 and 3 also cannot be fully met (the analysis agent cannot populate them, and the verification agent cannot read them). The schema must be extended and make manifests re-run to regenerate CRD YAML.

🚨 Critical: No E2E test for convergence-delayed verification (AC6 unmet)

test/e2e/verification_test.go:1

Detail

AC6 explicitly requires an E2E test that demonstrates alert-based (or convergence-dependent) verification passing after a delay. The diff adds only unit tests (string-contains assertions in sandbox_agent_test.go and revision_test.go). The test/e2e/verification_test.go file is untouched and has no convergence/delay coverage. An E2E test is needed to validate the fix for the field-reported bug (PaymentErrorRateHigh rollback marked failed before alert cleared).


Reviewed by adversarial code review system (4 findings survived verification)

{{- if .HasVerification}}

- **Verification plan** — checks to confirm the fix worked.
- **Verification plan** — checks to confirm the fix worked. The verification agent has **read-only cluster access** (get, list, watch only). Do NOT propose `exec`, `port-forward`, `cp`, `attach`, or `proxy` commands. These require escalated permissions the agent lacks. Use `oc get`, `oc describe`, `oc logs`, `oc get events`, or JSONPath queries.

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.

🚨 CRITICAL: Analysis prompt does not instruct LLM to populate retry hints (AC2 unmet)

AC2 requires the analysis prompt to tell the LLM to fill in retryCount and retryIntervalSeconds based on check type (e.g., metric checks get retryCount=5/retryIntervalSeconds=30, instant-state checks get retryCount=0). The only change to analysis_query.tmpl is adding a read-only access constraint to the verification plan bullet. No retry classification guidance was added. Without this, the analysis agent produces VerificationSteps with no retry metadata, leaving the verification agent to guess convergence type from free-form descriptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adding retryCount/retryIntervalSeconds to VerificationStep means the analysis agent has to predict convergence behavior before execution even happens. The verification agent runs after execution — it sees the actual command output ("0/1 Ready", "alert still firing") and is in a far better position to judge whether to wait. Structured retry metadata would be the analysis agent guessing at something the verification agent can observe.


**Fix syntax errors only.** If a command fails due to a syntax error (malformed flag, wrong argument order), fix the syntax and retry. Do not change the intent, target, or resource of the command. Do not add checks beyond the verification plan.

### Convergence-dependent checks

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.

⚠️ Warning: Retry tier labels not anchored to VerificationStep.type field — agent must guess from free text

The template defines retry tiers by descriptive labels (Alerts, Pod readiness/rollout, Metrics, Instant state checks), but the VerificationStep.Type field arriving in .OptionJSON is a free-form string whose example values in the schema comment are 'command', 'metric', 'condition'. Neither the analysis prompt nor this template establishes a mapping between those type values and the retry categories. A convergence-dependent check with type='command' will likely be classified as 'Instant state' by the verification agent and not retried. Fix: either enumerate allowed type values in the schema (e.g., 'alert', 'pod-readiness', 'metric', 'instant') and reference them explicitly in both templates, or add a boolean convergence: true field to VerificationStep so the analysis agent can tag checks unambiguously.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The verification agent doesn't need to classify by VerificationStep.type to decide whether to retry. It runs the command, sees the output, and reasons about it. If oc get pods returns "0/1 Ready" after a rollout restart, the agent knows to wait regardless of whether type says command or pod-readiness. That's the whole value of having an LLM do verification — it reasons per-case, not by category.

@vimalk78

vimalk78 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Code Review

2 finding(s) posted as inline comments on the diff.

🚨 Critical: VerificationStep schema missing retryCount and retryIntervalSeconds fields (AC1 unmet)

api/v1alpha1/agenticrun_analysis_types.go:159

Detail

AC1 requires VerificationStep to gain retryCount and retryIntervalSeconds fields so retry behaviour is configurable per check. The struct at line 159 is unchanged — it still has only Name, Command, Expected, and Type. Without these fields, ACs 2 and 3 also cannot be fully met (the analysis agent cannot populate them, and the verification agent cannot read them). The schema must be extended and make manifests re-run to regenerate CRD YAML.

🚨 Critical: No E2E test for convergence-delayed verification (AC6 unmet)

test/e2e/verification_test.go:1

Detail

AC6 explicitly requires an E2E test that demonstrates alert-based (or convergence-dependent) verification passing after a delay. The diff adds only unit tests (string-contains assertions in sandbox_agent_test.go and revision_test.go). The test/e2e/verification_test.go file is untouched and has no convergence/delay coverage. An E2E test is needed to validate the fix for the field-reported bug (PaymentErrorRateHigh rollback marked failed before alert cleared).


Reviewed by adversarial code review system (4 findings survived verification)

@blublinsky

Copy link
Copy Markdown
Contributor Author

Analysis knows what and how to verify, but it does not have the state of the cluster during verification. The verification agent has up-to-date information about the cluster and is in a much better position to decide when and where to do retries.

@blublinsky

Copy link
Copy Markdown
Contributor Author

Re: E2E test for convergence-delayed verification — this is a prompt-only change. Convergence retry behavior happens inside the LLM's reasoning within the sandbox — there's no controller logic to E2E test. The sandbox timeout is the existing E2E-testable boundary. You could theoretically set up a slow-converging fixture, but that would be testing the LLM's compliance with the prompt, not the operator.

@vimalk78

vimalk78 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 7, 2026
@blublinsky
blublinsky force-pushed the verification-prompt branch from c4c48af to 1c2999a Compare August 7, 2026 13:58
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 7, 2026
@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown

@blublinsky: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants