Skip to content

fix: handle NotFound and add ownerReferences in BarePodManager#322

Open
tremes wants to merge 1 commit into
openshift:mainfrom
tremes:issue-301
Open

fix: handle NotFound and add ownerReferences in BarePodManager#322
tremes wants to merge 1 commit into
openshift:mainfrom
tremes:issue-301

Conversation

@tremes

@tremes tremes commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

WaitReady now treats NotFound as a terminal error instead of polling until timeout. It also checks DeletionTimestamp after a successful Get to fail fast on terminating pods.

Sandbox pods created by Claim now carry ownerReferences back to the AgenticRun via the new SandboxOwnerSetter optional interface, enabling garbage collection on AgenticRun deletion.

Closes: #301

Assisted-by: Claude Code:claude-opus-4-6

WaitReady now treats NotFound as a terminal error instead of
polling until timeout. It also checks DeletionTimestamp after a
successful Get to fail fast on terminating pods.

Sandbox pods created by Claim now carry ownerReferences back to
the AgenticRun via the new SandboxOwnerSetter optional interface,
enabling garbage collection on AgenticRun deletion.

Closes: openshift#301

Signed-off-by: Tomáš Remeš <tremes@redhat.com>
Assisted-by: Claude Code:claude-opus-4-6
@openshift-ci openshift-ci Bot requested review from raptorsun and xrajesh July 13, 2026 08:44
@openshift-ci

openshift-ci Bot commented Jul 13, 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 xrajesh 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 commented Jul 13, 2026

Copy link
Copy Markdown
📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Sandbox pods are now automatically linked to their owning run and cleaned up when the run is deleted.
  • Bug Fixes
    • Pod readiness now fails promptly when a pod is missing or terminating, avoiding unnecessary retries.
    • Pod recreation behavior correctly accounts for deleted and terminating pods.
  • Documentation
    • Updated sandbox lifecycle and ownership documentation.

Walkthrough

Changes

Bare-pod sandbox lifecycle

Layer / File(s) Summary
Ownership contract and call wiring
controller/agenticrun/sandbox.go, controller/agenticrun/sandbox_agent.go, .ai/spec/how/reconciler.md
Adds optional SandboxOwnerSetter support and invokes SetOwner before sandbox claiming when available.
Pod ownership and readiness handling
controller/agenticrun/bare_pod_manager.go, .ai/spec/what/sandbox-execution.md, .ai/spec/how/reconciler.md
Stores the AgenticRun, adds controller owner references to claimed Pods, and treats missing or terminating Pods as terminal readiness errors.
Lifecycle behavior validation
controller/agenticrun/bare_pod_manager_test.go
Tests owner references, missing Pods, and terminating Pods during readiness and claiming.

Sequence Diagram(s)

sequenceDiagram
  participant SandboxAgentCaller
  participant BarePodManager
  participant KubernetesAPI
  SandboxAgentCaller->>BarePodManager: SetOwner(run)
  SandboxAgentCaller->>BarePodManager: Claim()
  BarePodManager->>KubernetesAPI: Create Pod with ownerReference
  SandboxAgentCaller->>BarePodManager: WaitReady()
  BarePodManager->>KubernetesAPI: Get Pod
  KubernetesAPI-->>BarePodManager: Ready or terminal lifecycle state
  BarePodManager-->>SandboxAgentCaller: Ready or error
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: NotFound handling and ownerReferences in BarePodManager.
Description check ✅ Passed The description accurately summarizes the WaitReady and ownerReference changes in the patch.
Linked Issues check ✅ Passed The patch addresses the three lifecycle defects in #301: terminating-pod handling, NotFound terminal errors, and ownerReferences.
Out of Scope Changes check ✅ Passed The changes are all tied to the linked sandbox-lifecycle fix and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@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: 1

🤖 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/bare_pod_manager.go`:
- Around line 63-67: Remove mutable owner state from BarePodManager by
eliminating SetOwner and the m.run dependency; change Claim to accept the owning
AgenticRun explicitly and use that argument when constructing the pod
ownerReference. Update all Claim callers, including SandboxAgentCaller, to pass
the reconcile-specific run so concurrent reconciles cannot attach pods to the
wrong owner.
🪄 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: CHILL

Plan: Enterprise

Run ID: 439a5b81-0f6a-4beb-8a84-4643f83f599a

📥 Commits

Reviewing files that changed from the base of the PR and between 3ebecc6 and 983e009.

📒 Files selected for processing (6)
  • .ai/spec/how/reconciler.md
  • .ai/spec/what/sandbox-execution.md
  • controller/agenticrun/bare_pod_manager.go
  • controller/agenticrun/bare_pod_manager_test.go
  • controller/agenticrun/sandbox.go
  • controller/agenticrun/sandbox_agent.go
🔗 Linked repositories identified

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

  • openshift/lightspeed-agentic-sandbox (manual)

Comment on lines +63 to +67
// SetOwner stores the AgenticRun so that pods created by Claim carry an
// ownerReference back to the run, enabling garbage collection.
func (m *BarePodManager) SetOwner(run *agenticv1alpha1.AgenticRun) {
m.run = run
}

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how SandboxAgentCaller and its SandboxProvider are constructed and whether
# the BarePodManager instance is shared across reconciles.

# 1. Find where SandboxAgentCaller is constructed
rg -nC5 'NewSandboxAgentCaller' --type=go controller/

# 2. Find where BarePodManager is constructed
rg -nC5 'NewBarePodManager' --type=go controller/

# 3. Check if the reconciler holds a shared AgentCaller (and thus shared Sandbox)
rg -nC5 'Agent\s+AgentCaller' --type=go controller/

Repository: openshift/lightspeed-agentic-operator

Length of output: 16961


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Project overview and reading order
sed -n '1,220p' .ai/spec/README.md

# Relevant implementation files
echo '--- controller/setup.go ---'
cat -n controller/setup.go | sed -n '1,220p'

echo '--- controller/agenticrun/reconciler.go ---'
cat -n controller/agenticrun/reconciler.go | sed -n '1,260p'

echo '--- controller/agenticrun/sandbox_agent.go ---'
cat -n controller/agenticrun/sandbox_agent.go | sed -n '1,260p'

echo '--- controller/agenticrun/bare_pod_manager.go ---'
cat -n controller/agenticrun/bare_pod_manager.go | sed -n '1,260p'

Repository: openshift/lightspeed-agentic-operator

Length of output: 37103


Avoid mutable owner state on BarePodManager
Setup builds one BarePodManager and shares it through a single SandboxAgentCaller instance across reconciles, while the controller can run more than one reconcile at a time. SetOwner/Claim can race and attach a pod to the wrong AgenticRun, which can trigger incorrect garbage collection. Pass the owner into Claim or make the provider stateless.

🤖 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/bare_pod_manager.go` around lines 63 - 67, Remove
mutable owner state from BarePodManager by eliminating SetOwner and the m.run
dependency; change Claim to accept the owning AgenticRun explicitly and use that
argument when constructing the pod ownerReference. Update all Claim callers,
including SandboxAgentCaller, to pass the reconcile-specific run so concurrent
reconciles cannot attach pods to the wrong owner.

@openshift-ci

openshift-ci Bot commented Jul 13, 2026

Copy link
Copy Markdown

@tremes: 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bare-pod sandbox lifecycle: Terminating pods adopted on create, WaitReady spins on NotFound, and pods lack ownerReferences (leaks)

1 participant