[PR #194] [MERGED] fix: atomically claim expired sandboxes #242

Closed
opened 2026-10-29 14:21:23 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/kvcache-ai/AgentENV/pull/194
Author: @ztting01
Created: 8/19/2026
Status: ✅ Merged
Merged: 8/25/2026
Merged by: @LSX-s-Software

Base: main ← Head: fix/atomic-auto-eviction-expiry


📝 Commits (4)

  • 40abd67 fix: atomically claim expired sandboxes
  • 850de83 refactor: simplify sandbox helper names
  • 2e001cd test: make auto-eviction claim gate one-shot
  • 2c15c9e refactor: inline auto-eviction actions

📊 Changes

2 files changed (+421 additions, -11 deletions)

View changed files

📝 src/orchestrator/service.rs (+77 -9)
📝 src/orchestrator/tests.rs (+344 -2)

📄 Description

Summary

  • revalidate sandbox expiry atomically while claiming it for auto-eviction
  • ensure a successful keep-alive and an auto-eviction claim cannot both win
  • apply the same arbitration to both Pause and Delete timeout actions
  • preserve the existing pause/delete execution and rollback behavior
  • add deterministic regression coverage for both arbitration orders and stale batched snapshots

Fixes #165

Root cause

evict_expired_sandboxes acted on metadata returned by an earlier list_expired snapshot. A keep-alive could update expires_at and return success while the eviction loop later transitioned the still-Running sandbox to Pausing or Killing based on that stale snapshot.

The fix evaluates the expiry predicate and performs the state transition in the same update_if_state critical section. If renewal wins, eviction observes the new deadline and skips the sandbox. If eviction wins, keep-alive observes the transitional state and cannot report a successful renewal.

Red/green verification

The same test selection was run against the parent commit and the fix:

cargo test -q -p agentenv --lib auto_evict
  • before the fix (547c1a8, tests-only patch): 3 passed, 4 failed
  • after the fix: 7 passed, 0 failed

The four pre-fix failures cover both Pause and Delete, including the key invalid outcome where keep-alive reports success and stale auto-eviction still proceeds.

Test coverage

New deterministic cases cover:

  • renewal after expiry listing but before the eviction claim
  • successful in-flight keep-alive winning against auto-eviction
  • revalidation of a later candidate after an earlier candidate is claimed
  • eviction claim winning first and preventing a later keep-alive success

Validation

  • make fmt
  • cargo clippy -p agentenv --lib --tests -- -D warnings
  • cargo test -q -p agentenv --lib orchestrator::service::tests:: — 91 passed
  • cargo test -q -p agentenv --lib auto_evict — 7 passed
  • auto-eviction suite repeated 10 times — 70 passed
  • full library suite excluding the known environment capability assertion — 748 passed, 4 ignored, 1 filtered

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/kvcache-ai/AgentENV/pull/194 **Author:** [@ztting01](https://github.com/ztting01) **Created:** 8/19/2026 **Status:** ✅ Merged **Merged:** 8/25/2026 **Merged by:** [@LSX-s-Software](https://github.com/LSX-s-Software) **Base:** `main` ← **Head:** `fix/atomic-auto-eviction-expiry` --- ### 📝 Commits (4) - [`40abd67`](https://github.com/kvcache-ai/AgentENV/commit/40abd6745e0488fc8a4eae57ebc1381d7236f5ac) fix: atomically claim expired sandboxes - [`850de83`](https://github.com/kvcache-ai/AgentENV/commit/850de831ff0c92f53ede94c1c56fbd54c31e851c) refactor: simplify sandbox helper names - [`2e001cd`](https://github.com/kvcache-ai/AgentENV/commit/2e001cd216b81071e4426a24218ee302ee738517) test: make auto-eviction claim gate one-shot - [`2c15c9e`](https://github.com/kvcache-ai/AgentENV/commit/2c15c9e1f75b25c313e9041e9e651ddd73750fe1) refactor: inline auto-eviction actions ### 📊 Changes **2 files changed** (+421 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `src/orchestrator/service.rs` (+77 -9) 📝 `src/orchestrator/tests.rs` (+344 -2) </details> ### 📄 Description ## Summary - revalidate sandbox expiry atomically while claiming it for auto-eviction - ensure a successful keep-alive and an auto-eviction claim cannot both win - apply the same arbitration to both `Pause` and `Delete` timeout actions - preserve the existing pause/delete execution and rollback behavior - add deterministic regression coverage for both arbitration orders and stale batched snapshots Fixes #165 ## Root cause `evict_expired_sandboxes` acted on metadata returned by an earlier `list_expired` snapshot. A keep-alive could update `expires_at` and return success while the eviction loop later transitioned the still-`Running` sandbox to `Pausing` or `Killing` based on that stale snapshot. The fix evaluates the expiry predicate and performs the state transition in the same `update_if_state` critical section. If renewal wins, eviction observes the new deadline and skips the sandbox. If eviction wins, keep-alive observes the transitional state and cannot report a successful renewal. ## Red/green verification The same test selection was run against the parent commit and the fix: ```text cargo test -q -p agentenv --lib auto_evict ``` - before the fix (`547c1a8`, tests-only patch): 3 passed, 4 failed - after the fix: 7 passed, 0 failed The four pre-fix failures cover both `Pause` and `Delete`, including the key invalid outcome where keep-alive reports success and stale auto-eviction still proceeds. ## Test coverage New deterministic cases cover: - renewal after expiry listing but before the eviction claim - successful in-flight keep-alive winning against auto-eviction - revalidation of a later candidate after an earlier candidate is claimed - eviction claim winning first and preventing a later keep-alive success ## Validation - `make fmt` - `cargo clippy -p agentenv --lib --tests -- -D warnings` - `cargo test -q -p agentenv --lib orchestrator::service::tests::` — 91 passed - `cargo test -q -p agentenv --lib auto_evict` — 7 passed - auto-eviction suite repeated 10 times — 70 passed - full library suite excluding the known environment capability assertion — 748 passed, 4 ignored, 1 filtered --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 14:21:23 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/AgentENV#242
No description provided.