Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
93 lines
2.8 KiB
Rust
93 lines
2.8 KiB
Rust
//! Tracks local running capacity and releases reservations through the shared guard.
|
|
//! The local permit owns the running count; root and MAv1 turns remain unrestricted.
|
|
|
|
use super::LocalAgentControl;
|
|
use crate::agent::types::AgentExecutionGuard;
|
|
use akode_protocol::error::AgentErrorContext;
|
|
use akode_protocol::error::CodexErr;
|
|
use akode_protocol::error::CodexErrorDetails;
|
|
use akode_protocol::error::Result as CodexResult;
|
|
use akode_protocol::protocol::MultiAgentVersion;
|
|
use akode_protocol::protocol::SessionSource;
|
|
use std::sync::Arc;
|
|
use std::sync::OnceLock;
|
|
use std::sync::atomic::AtomicUsize;
|
|
use std::sync::atomic::Ordering;
|
|
|
|
#[derive(Default)]
|
|
pub(super) struct AgentExecutionLimiter {
|
|
active: AtomicUsize,
|
|
max_threads: OnceLock<usize>,
|
|
}
|
|
|
|
struct LocalExecutionPermit {
|
|
limiter: Arc<AgentExecutionLimiter>,
|
|
}
|
|
|
|
impl Drop for LocalExecutionPermit {
|
|
fn drop(&mut self) {
|
|
self.limiter.active.fetch_sub(1, Ordering::AcqRel);
|
|
}
|
|
}
|
|
|
|
impl LocalAgentControl {
|
|
pub(crate) fn ensure_execution_capacity(
|
|
&self,
|
|
multi_agent_version: MultiAgentVersion,
|
|
session_source: &SessionSource,
|
|
) -> CodexResult<()> {
|
|
if !is_execution_limited(multi_agent_version, session_source) {
|
|
return Ok(());
|
|
}
|
|
let max_threads = self.runtime.agent_execution_limiter.max_threads();
|
|
if self.runtime.agent_execution_limiter.has_capacity() {
|
|
Ok(())
|
|
} else {
|
|
Err(
|
|
CodexErr::new(CodexErrorDetails::AgentLimitReached { max_threads })
|
|
.with_agent_context(AgentErrorContext::ExecutionCapacity),
|
|
)
|
|
}
|
|
}
|
|
|
|
pub(crate) fn execution_guard(
|
|
&self,
|
|
multi_agent_version: MultiAgentVersion,
|
|
session_source: &SessionSource,
|
|
) -> Option<AgentExecutionGuard> {
|
|
is_execution_limited(multi_agent_version, session_source)
|
|
.then(|| Arc::clone(&self.runtime.agent_execution_limiter).guard())
|
|
}
|
|
}
|
|
|
|
impl AgentExecutionLimiter {
|
|
pub(super) fn initialize(&self, max_threads: usize) {
|
|
self.max_threads.get_or_init(|| max_threads);
|
|
}
|
|
|
|
fn max_threads(&self) -> usize {
|
|
self.max_threads.get().copied().unwrap_or(usize::MAX)
|
|
}
|
|
|
|
fn has_capacity(&self) -> bool {
|
|
self.active.load(Ordering::Acquire) < self.max_threads()
|
|
}
|
|
|
|
fn guard(self: Arc<Self>) -> AgentExecutionGuard {
|
|
self.active.fetch_add(1, Ordering::AcqRel);
|
|
AgentExecutionGuard::new(LocalExecutionPermit { limiter: self })
|
|
}
|
|
}
|
|
|
|
fn is_execution_limited(
|
|
multi_agent_version: MultiAgentVersion,
|
|
session_source: &SessionSource,
|
|
) -> bool {
|
|
multi_agent_version == MultiAgentVersion::V2
|
|
&& matches!(session_source, SessionSource::SubAgent(_))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "execution_tests.rs"]
|
|
mod tests;
|