Skip to content

Finalizer deadlock controller clean - #873

Merged
Saadmrp1038 merged 9 commits into
SREGym:mainfrom
ermias19:finalizer_deadlock_controller_clean
Jun 12, 2026
Merged

Saadmrp1038 merged 9 commits into
SREGym:mainfrom
ermias19:finalizer_deadlock_controller_clean

Conversation

@ermias19

@ermias19 ermias19 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

[Problem] Add FinalizerDeadlock Stuck Finalizer Deadlock for Hotel Reservation

Summary

This replaces the earlier finalizer PR (#858) which got closed because agents could already solve it.

The old version was simple ConfigMap gets stuck, agent removes the finalizer, done. That worked as a Kubernetes exercise but not as a benchmark because the fix was too obvious.

This version keeps the same failure class but makes the root cause harder to reach. There is now a real controller running that owns the finalizer. The controller is broken its ClusterRole lost patch and update on configmaps/finalizers so it keeps hitting 403 and logging the error, but it cannot finish cleanup. The ConfigMap stays stuck.

The agent cannot just remove the finalizer directly. The oracle rejects that path. The agent has to find the controller logs, trace the 403 back to the ClusterRole, fix the missing rules, and let the controller do the cleanup itself.


What the failure looks like

ConfigMap/reservation-cleanup-token → stuck in Terminating
    → cleanup-controller is running but getting 403
    → ClusterRole is missing patch/update on configmaps/finalizers
    → controller cannot finish reconcile
    → ConfigMap never deleted

The cluster looks mostly healthy. The controller pod is Running. The only signal is in the controller logs — repeated 403 Forbidden on configmaps/finalizers. The agent has to find that.


Problem design

Field Value
Problem key finalizer_deadlock_controller_hotel_reservation
Target app Hotel Reservation
Stuck resource ConfigMap/reservation-cleanup-token
Namespace hotel-reservation
Controller Deployment/cleanup-controller
ServiceAccount cleanup-controller
ClusterRole configmap-cleanup-controller
Finalizer cleanup.reservations.io/pending-cleanup

What inject_fault does

  1. Creates ServiceAccount/cleanup-controller
  2. Creates ClusterRole/configmap-cleanup-controller with full patch/update rules
  3. Creates ClusterRoleBinding binding the SA to the role
  4. Creates ConfigMap/reservation-cleanup-token with the finalizer
  5. Starts Deployment/cleanup-controller — at this point it is healthy and could reconcile
  6. Triggers kubectl delete configmap ... --wait=false — ConfigMap enters Terminating
  7. Waits 3 seconds so the controller sees the deletionTimestamp
  8. Strips patch/update from the ClusterRole — controller now gets 403 on every retry
    The 3-second gap matters. The controller needs to register the deletion before RBAC is broken, otherwise it never starts trying and the logs are empty.

What the correct agent path looks like

  1. See ConfigMap/reservation-cleanup-token stuck in Terminating
  2. Check metadata — see cleanup.reservations.io/pending-cleanup finalizer
  3. Find Deployment/cleanup-controller
  4. Read controller logs — see repeated FORBIDDEN: ... configmaps/finalizers
  5. Inspect the ClusterRoleBinding → find configmap-cleanup-controller
  6. Inspect the ClusterRole → see only get/list/watch, no patch/update
  7. Restore the missing rules
  8. Controller reconciles on next cycle and removes the finalizer
  9. ConfigMap deletion completes automatically

Oracle

FinalizerDeadlockControllerMitigationOracle checks all of these:

  • ClusterRole/configmap-cleanup-controller exists and has patch + update on configmaps and configmaps/finalizers
  • ConfigMap/reservation-cleanup-token is fully deleted (404)
  • Deployment/cleanup-controller still exists and is healthy
  • All Hotel Reservation application pods are healthy
    Shortcut rejection — if the ConfigMap is gone but the ClusterRole is still broken, the oracle detects this and fails the run. That means the agent patched the finalizer directly instead of fixing the root cause. The oracle distinguishes the two paths by checking ClusterRole state against ConfigMap state together.

These are also rejected:

  • Deleting the controller Deployment
  • Deleting the ServiceAccount or RBAC objects instead of repairing them
  • Restarting unrelated pods

MCP RBAC change

The agent needs to be able to patch the ClusterRole to fix it. Added to mcp_server/k8s/clusterrole.yaml:

- apiGroups: ["rbac.authorization.k8s.io"]
  resources:
    - clusterroles
  verbs: ["get", "list", "watch", "patch", "update"]

Bindings stay read-only — the agent can read them to trace the ownership chain but cannot modify them:

- apiGroups: ["rbac.authorization.k8s.io"]
  resources:
    - clusterrolebindings
    - roles
    - rolebindings
  verbs: ["get", "list", "watch"]

This follows the same pattern as the admission webhook PR.


Files changed

File Purpose
sregym/conductor/problems/finalizer_deadlock_controller.py New problem
sregym/conductor/oracles/finalizer_deadlock_controller_mitigation.py New oracle
sregym/conductor/problems/registry.py Registers the problem
mcp_server/k8s/clusterrole.yaml Agent RBAC expansion
cleanup_controller_loop.py Reconcile loop script running inside the controller pod
Dockerfile.cleanup_controller Builds the controller image

Validation

uv run python tests/integration/validate_problem.py \
  --problem finalizer_deadlock_controller_hotel_reservation \
  --inject-timeout 180 \
  --recover-timeout 180
Resolve problem in registry:     PASSED
Deploy application:              PASSED
Inject fault:                    PASSED
Oracle fails after injection:    PASSED
Recover fault:                   PASSED
Oracle passes after recovery:    PASSED

Real-world reference

This failure class is documented in kubernetes/kubernetes issue #60807 — resources stuck in Terminating because a controller lost its ability to remove finalizers. That thread has hundreds of production reports going back to 2018 across Rook, Fission, Rancher, and others.


Note on agent trials

I will run multiple agent trials before treating this as final. The goal is to see the agent solve it inconsistently — not 0% and not 100%. Will drop the traces in a follow-up comment once I have them.

@Saadmrp1038
Saadmrp1038 self-requested a review June 5, 2026 22:53
@Saadmrp1038 Saadmrp1038 added the problem Adding a new problem to the benchmark label Jun 5, 2026

@Saadmrp1038 Saadmrp1038 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ermias19 Did a light review and dropped some nit comments.

Will drop the traces in a follow-up comment once I have them.

You mentioned a follow-up after doing agent runs. Please ping me when it's done.

Comment thread sregym/conductor/problems/registry.py Resolved
Comment thread sregym/conductor/problems/registry.py Resolved
Comment thread sregym/conductor/problems/registry.py Resolved
@ermias19

ermias19 commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@Saadmrp1038, here are the the agent run reports. i have attached these two report.
validation-summary.md
stratus_ALL_results.csv

@Saadmrp1038 Saadmrp1038 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ermias19 The fault works great! Left some minor comments. I will merge the PR when they are addressed.

It seems like this is quite a difficult fault for the agents, as from my testing too, the agent kept timing out.


On a side note, I appreciate the repo-wide ruff check ., but this might have been more suited to a separate PR. Makes reviewing a bit harder. :)

Comment thread sregym/service/container_runner.py Resolved
@Saadmrp1038

Copy link
Copy Markdown
Collaborator

@ermias19 Thanks for addressing all my comments! Merging this now.

@Saadmrp1038
Saadmrp1038 merged commit c210b4a into SREGym:main Jun 12, 2026
5 of 6 checks passed
vsmart-06 pushed a commit to vsmart-06/SREGym that referenced this pull request Jul 12, 2026
* finalizzer code is reaoslve dadlock benchmark.

* yaml file corrected.

* reverting hte comments back to their place.

* read only rbac

* controller log is generalized and avoiding any sregym related name exposing.

* applied ruff linter formatter accordingly.

* replace metadata naming and includding all the oprations on mitigation side.

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Saadmrp1038 added a commit that referenced this pull request Jul 22, 2026
* Updated default mitigation oracle

* Stop timeout for 0 replicas

* TBC in CloudLab

* Pushing all attempts at the problem

* Enable idempotence

* Add mutating_webhook_resource_limits problem (#847)

* Add mutating_webhook_resource_limits problem

* Add mutating_webhook_resource_limits to Problem List

* mutating_webhook_resource_limits problem docstring fix

Removed incorrect information about mitigation options.

* Additions to mutating_webhook_limits_resource_limits problem

 - Memory limit/request patching before activating the webhook
 - Decoy pods for increased complexity

* More additions to mutating_webhook problem

 - Make decoys realisticly named
 - Similar minor changes

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Derive the default problem namespace from the application (#876)

* add the the probem redundency

* base.

* the fixed and dynamic app name are fixed. hte namespace are also fixed.

* unessessry formating is reverted.

* unessessry formating is reverted.

* formating correction.

* formating correction.

* formating correction.

* add fault injection decorator markers to test_problem_bsae.py

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Confluent kafka attempt

* Custom image attempt

* Threaded producer and added consumer

* Syntax error

* Added some imports

* fix edge cases

* run ruff check adn format

* New OOM attempt

* Force crash on OOM

* Add file_descriptor_exhaustion problem (#832)

* add file_descriptor_exhaustion problem

* Modify fault injection and recovery methods

* Fix fault recovery

* Change fault injection method
Add fault injection by flooding connections

* Update fault injection method and add custom oracle

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Finalizer deadlock controller clean (#873)

* finalizzer code is reaoslve dadlock benchmark.

* yaml file corrected.

* reverting hte comments back to their place.

* read only rbac

* controller log is generalized and avoiding any sregym related name exposing.

* applied ruff linter formatter accordingly.

* replace metadata naming and includding all the oprations on mitigation side.

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add: secret_rotation_stale_env_credentials_astronomy_shop problem (#851)

* Add secret rotation stale env credentials problem

* Simplify secret rotation mitigation oracle checks

* Require rotated PostgreSQL in oracle

* Fix stale DB credential rotation shortcuts

  - Remove old password from postgresql-init ConfigMap
  - Keep PostgreSQL password rotation durable after pod restart
  - Reject mitigations that revert otelu to the old password
  - Remove old password leaks from unrelated pods

* Fix fault recovery to satisfy the oracle

* Fix problem registry import ordering

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add cumulative_admission_webhook_timeout_hotel_reservation problem (#886)

* Add cumulative_admission_webhook_timeout_hotel_reservation problem

* Pin webhook backends to worker nodes via nodeAffinity

* Make webhook backends realistic admission services

Replace the dummy webhook backends with HTTPS admission servers that terminate TLS using Secret-mounted certificates, validate AdmissionReview

requests, and return proper admission responses. Certificates are signed by the same CA referenced in each webhook's `caBundle`, with SANs

covering the backend Service DNS names.

The admission logic enforces a trusted image registry allowlist and a

per-container CPU limit. All Hotel Reservation workloads satisfy these

policies, so the webhooks remain transparent during normal operation and

recovery.

Also:
* Vary webhook `timeoutSeconds` (12, 8, 11, 9) to make the cumulative
  timeout less obvious.

* Rename the CA CN from `sregym-webhook-ca` to
  `compliance-webhook-ca`.

* Remove a duplicate `rule.from_` check in the oracle.

* Fix create-or-replace handling for webhooks, NetworkPolicies,
  Deployments, and Services so re-injection updates existing resources
  instead of failing or silently skipping changes.

* Model the fault as a missing apiserver NetworkPolicy allow

* Model the fault as a missing apiserver allow with a near-miss policy

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add psa_restricted_blocks_recreation problem (#891)

Labelling a namespace pod-security.kubernetes.io/enforce=restricted leaves
running pods untouched but makes the apiserver reject recreated pods that run
as root / set no seccomp profile, so a deployment silently goes
under-replicated. Unlike the existing webhook problems, the policy is enforced
by the apiserver via a namespace label, not a webhook config.

* Add copilot cli agent (#893)

* add copilot cli agent

* remove -s flag

* Fix MCP retry error handling and CRLF parsing in CI (#896)

* fix(mcp): broaden MCP retry exceptions and return error instead of raising

* fix(ci): strip CRLF from PR description before parsing problem ID

* Fix kind cluster detection (#897)

* Fix custom kind cluster detection

* Handle failed kind detection output

* fix edge cases

* run ruff check adn format

* Shell state persistence (#903)

* Include shell persistence

* Include shell persistence

* Isolate problem IDs from agent runtime artifacts

* update SREGym-applications (18620ed) (#910)

* Add Calico route-reflector label drift problem (#828)

* Add Calico route-reflector label drift problem

* Address Calico route-reflector review comments

* Harden Calico cleanup ownership tracking

* Fix Codex agent install verification

* Tighten Codex platform package detection

* Restore kubelet eviction reset cleanup

* Neutralize Calico ownership metadata

---------

Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Fail alert oracle on Prometheus query errors (#912)

* Decouple failure configmaps from mongo pods in `hotel-reservation` (#899)

* decouple failure configmaps from mongo pods

* remove empty failure configmaps creation

* Support local LLM endpoints for Stratus and OpenCode (#917)

* Support local LLM endpoints for Stratus

* Prefer env vars for local LLM endpoints

* Support local LLM endpoints for OpenCode

* Route local endpoints into agent containers

* Normalize OpenCode local judge models

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Preflight check the judge model (#924)

* Add support for uniform agent trajectory (ATIF format) (#918)

* add support for ATIF trajectory conversion and normalization, add claudecode adapter

* fix: make _finish_problem idempotent

* isolate .codex mount in container runner

* better temp dir cleanup

* add codex adapter

* add opencode adapter

* add copilot adapter

* add stratus adapter

* fix antropic caching for stratus

* add gemini adapter

* store normalized ATIF trajectories in SQLite indexed by problem type

* edge tests

* bump litellm, tikoken

* update docker lib versions

* Add node_clock_drift Problem  (#894)

* adding clock drift problem

* fixing race condition causing sidecar log delay

* fixing recover_fault to reverse time sync removal applied, improve cleanup

* global cleanup added + fixed restoration for node_clock_drift problem

* fixing mitigation oracle to ensure correct node checked

* adding problem to non emulated cluster problems list

* extending wait

* indentation error fix

* fixing time restoration in global cleanup

* adding in check to make sure it picks worker node

* adding another control plane filter, fixing clock step-back in global recovery

* increase sidecar rollout timeout, make podnames/labels generic, idempotancy check

* formatting fixes

* format fix

* fix

* fix ruff check/format issues

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Minimum viable python version

* Changed diagnosis oracle

* Cleaned up fault recovery

* Edit tasklist.yml

* Removed old Java artifacts

* Updated mitigation oracle to be more robust

* Added polling

* Fail Kafka producer leak injection on timeout

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Co-authored-by: Kerem Akcalioglu <[email protected]>
Co-authored-by: ermias mulugeta <[email protected]>
Co-authored-by: Tejas Shukla <[email protected]>
Co-authored-by: Petr Myagkov <[email protected]>
Co-authored-by: Omar Faruqe Riyad <[email protected]>
Co-authored-by: Mohammad Tamimul Ehsan <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Om Kumar <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Tanzim Hossain Romel <[email protected]>
Co-authored-by: haani-maybe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

problem Adding a new problem to the benchmark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants