mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[GH-ISSUE #228] cpu-bind wanted #68
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#68
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?
Originally created by @emailcannotbeblank on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/kvcache-ai/AgentENV/issues/228
Affected component
Select:
Problem statement
AgentENV does not provide a supported way to change the host CPU affinity of a running sandbox. This is needed for performance analysis and hardware characterization, where reproducible placement of Firecracker vCPU threads is important.
Today, an operator has to identify the compute node that owns the sandbox, correlate the sandbox with an internal Firecracker process, enumerate its threads through host process information or
/proc, and invoketasksetorsched_setaffinitymanually. This is unreliable and depends on internal implementation details. It also requires shell access to the exact compute node, so it cannot be used reliably through the AgentENV gateway in a multi-node deployment.The requested capability is a sandbox-level API and CLI operation that binds selected Firecracker threads to specified host logical CPU IDs while keeping the Firecracker PID and TIDs internal to the compute node.
Use case
I am a hardware architect evaluating processor designs for agent workloads. We use AgentENV sandboxes for microbenchmarking and workload characterization on hosts with more than 100 logical CPUs. A typical session runs dozens of sandboxes and may change affinity before every benchmark run, often dozens of times per day.
The main use cases are:
Current behavior and workarounds
There is currently no AgentENV API or CLI operation for changing CPU affinity after a sandbox has started.
The manual workaround is to:
psor/proc/<pid>/task.tasksetorsched_setaffinityto individual TIDs.For example, a Firecracker process can contain threads such as:
This workaround is insufficient because:
Desired behavior
AgentENV should provide an authenticated sandbox operation that changes CPU affinity on the compute node currently running the sandbox.
Acceptance criteria:
0,0-3, or0-10:2.*, targets every thread currently belonging to the Firecracker process, including non-vCPU helper threads.Proposed approach
Add a sandbox API operation such as:
Add a corresponding CLI command:
The orchestrator should perform lifecycle validation and serialize the operation with other sandbox lifecycle operations. The compute-node sandbox backend should obtain the PID from the Firecracker child process it already owns. A low-level affinity module should enumerate threads, select targets, validate CPU lists, apply and verify affinity, and perform best-effort rollback on failure.
The PID is an internal implementation detail and should not be added to the public API, CLI, metadata, or persistent sandbox records.
I have implemented a working prototype in the following branch and can adapt it based on maintainer feedback:
https://github.com/emailcannotbeblank/AgentENV/tree/feature/bind-cpu
Compatibility and operational impact
API/config changes:
aenv cpu-bindCLI command and SDK client method.sandbox.cpu_affinity_enabledas a node-level switch:1enables CPU binding, while0disables it and causes the compute node to reject the operation immediately. The current default is1.Snapshot or storage format changes:
New host/runtime requirements:
0-1023, matching the fixed-sizecpu_set_tused by the implementation.Upgrade and rollback considerations:
404.Documentation status:
Alternatives considered
taskset. Rejected because it leaks an unstable implementation detail, requires access to the exact compute node, is difficult to route through the gateway, and creates PID/TID reuse races.Non-goals
Contribution
Select:
I have a working implementation in my fork and can update the code, tests, generated API files, and documentation after the API and scope are agreed upon.
Pre-submission checklist
@yingdi-shan commented on GitHub (Sep 1, 2026):
Thanks! CPU-binding is valuable, but it can interfere with load balancing and other sandboxes, so it should be used with caution. Since we currently only support single-tenant deployments, this is acceptable. That said, because this feature requires knowledge of the host CPU, I'd suggest moving the API into the admin interface.
@emailcannotbeblank commented on GitHub (Sep 6, 2026):
The operation has already been moved into the admin interface (
src/api/impls/admin.rs) to reflect its privileged nature. AgentENV’s admin authentication flow is not yet fully implemented end-to-end across the CLI, gateway, and runtime server. Completing that authorization design is orthogonal to CPU affinity, so I propose addressing it in a separate PR while keeping this PR focused on the binding functionality.