mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #189] fix(server): reap orphaned runtime processes and retry RocksDB lock on startup #238
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#238
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/AgentENV/pull/189
Author: @epicvinny
Created: 8/18/2026
Status: 🔄 Open
Base:
main← Head:upstream/orphan-process-reap📝 Commits (1)
da5215bfix(server): reap orphaned runtime processes and retry RocksDB lock on startup📊 Changes
4 files changed (+414 additions, -8 deletions)
View changed files
📝
src/bin/server.rs(+6 -0)📝
src/local_store.rs(+136 -8)📝
src/setup/mod.rs(+8 -0)➕
src/setup/orphans.rs(+264 -0)📄 Description
What
Makes node-agent startup resilient to leftover runtime processes and held RocksDB locks from a previous server incarnation:
src/setup/orphans.rs, wired insrc/bin/server.rs): early in startup — before the ublk daemon is spawned and before any store is opened — the server scans/procfor processes whose executable is the configured Firecracker binary oruvm-ublk-daemonbinary. Any match necessarily belongs to a previous incarnation (nothing has been spawned yet), so they are terminated: SIGTERM, 5s grace, then SIGKILL. Zombie entries are ignored (they hold no resources).src/local_store.rs):LocalKvStore::opennow retries lock-contention errors (No locks available/Resource temporarily unavailableon theLOCKfile) with exponential backoff for up to 120s instead of failing immediately. This covers the case where the lock holder lives in a different PID namespace (e.g. a previous container still terminating on the same hostPath) and therefore cannot be seen or killed by the reaper.Why
Observed in staging: after a pod was terminated (force-deleted after the preStop hang addressed in #187),
firecrackeranduvm-ublk-daemonprocesses from the old container were still alive on the host, and the replacement pod CrashLoopBackOffed trying to open the persisted-sandbox store at/var/lib/aenv/env/persisted-sandboxes/records.db— the RocksDBLOCKwas still held. Recovery requiredkubectl debug node/... -- chroot /hostand manually killing the leaked PIDs.Two contributing gaps in the current code:
src/sandbox/firecracker/instance.rs) and the ublk daemon (storage/ublk-daemon/src/client.rs) are spawned in their own process groups (process_group(0)). Graceful teardown (orchestrator pause-all, pool shutdown, daemon shutdown) only runs on SIGTERM/Ctrl+C; on SIGKILL/OOM/force-delete nothing runs and the children persist with their resources (ublk devices, open image files, inherited fds).LocalKvStore::openmade a singleDB::openattempt, so a still-terminating previous holder turned startup into an immediate fatal error → CrashLoopBackOff.Scope and non-goals
LocalKvStore::open(benefits all three callers: persisted-sandbox records, image cache graph, P2P catalog), unit tests for both.Compatibility and operations
Validation
cargo test -p agentenv --lib local_store(3 passed, incl. retry-until-release and budget-exhaustion cases with a real held RocksDB lock)cargo test -p agentenv --lib setup::orphans(4 passed: exe matching,(deleted)binary suffix, non-numeric/missing exe entries, zombie state parsing)cargo clippy -p agentenv --lib --bins -- -D warningscargo fmt --checkon touched files🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.