Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub(super) struct ArtifactRefs {
pub(super) optimizer_diagnosis: Value,
}

#[hotpath::measure(label = "automation_runtime.artifact_payloads.build_traces")]
pub(super) fn traces_payload(ctx: &ArtifactPayloadContext<'_>) -> Value {
let curation_result = (ctx.task == AgentTaskKind::MemoryCurator)
.then(|| curation::memory_curation_trace_summary(ctx.record));
Expand Down Expand Up @@ -118,6 +119,7 @@ fn session_reflection_summary(record: &AutomationRunLedgerRecord) -> Value {
})
}

#[hotpath::measure(label = "automation_runtime.artifact_payloads.build_feedback")]
pub(super) fn feedback_payload(ctx: &ArtifactPayloadContext<'_>, trace_ref: &Value) -> Value {
json!({
"schema_version": 1,
Expand All @@ -140,6 +142,7 @@ pub(super) fn feedback_payload(ctx: &ArtifactPayloadContext<'_>, trace_ref: &Val
})
}

#[hotpath::measure(label = "automation_runtime.artifact_payloads.derive_generated_evals")]
pub(super) fn generated_eval_payloads(ctx: &ArtifactPayloadContext<'_>) -> GeneratedEvalPayloads {
let definitions = generated_eval_definitions(ctx.record, ctx.task, ctx.policy);
let count = definitions.len();
Expand All @@ -155,6 +158,7 @@ pub(super) fn generated_eval_payloads(ctx: &ArtifactPayloadContext<'_>) -> Gener
}
}

#[hotpath::measure(label = "automation_runtime.artifact_payloads.build_generated_evals")]
pub(super) fn generated_evals_payload(
ctx: &ArtifactPayloadContext<'_>,
refs: (&Value, &Value),
Expand Down Expand Up @@ -224,6 +228,7 @@ pub(super) fn improvement_gate_payload(
}
}

#[hotpath::measure(label = "automation_runtime.artifact_payloads.build_validation_gate")]
pub(super) fn validation_gate_payload(
ctx: &ArtifactPayloadContext<'_>,
refs: (&Value, &Value, &Value),
Expand Down Expand Up @@ -288,6 +293,7 @@ pub(super) fn validation_gate_payload(
})
}

#[hotpath::measure(label = "automation_runtime.artifact_payloads.build_optimizer_diagnosis")]
pub(super) fn optimizer_diagnosis_payload(
ctx: &ArtifactPayloadContext<'_>,
refs: (&Value, &Value, &Value, &Value),
Expand Down Expand Up @@ -334,6 +340,7 @@ pub(super) fn optimizer_diagnosis_payload(
})
}

#[hotpath::measure(label = "automation_runtime.artifact_payloads.build_codex_handoff")]
pub(super) fn codex_handoff_payload(
ctx: &ArtifactPayloadContext<'_>,
refs: &ArtifactRefs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl<'a> ImprovementArtifactWriter<'a> {
}
}

#[hotpath::measure(label = "automation_runtime.artifacts.prepare_artifact", future = true)]
async fn write(
&mut self,
kind: AutomationRunArtifactKind,
Expand All @@ -61,6 +62,10 @@ impl<'a> ImprovementArtifactWriter<'a> {
}
}

#[hotpath::measure(
label = "automation_runtime.artifacts.write_improvement_chain",
future = true
)]
pub(crate) async fn write_improvement_artifacts(
dashboard_root: &Path,
run_id: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn executable_digest_cache() -> &'static Mutex<HashMap<ExecutableDigestCacheKey,
/// port itself honours, so the identity tracks the binary that would actually
/// be spawned rather than a nominal default. Envelope hashing stays
/// [`canonical_sha256`]; hasher failures are `config_error` results.
#[hotpath::measure(label = "automation_runtime.backend_identity.derive")]
pub fn backend_identity(config: &AutomationConfig) -> Result<String> {
// `canonical_sha256` is the crate's one identity primitive: key-ordered,
// whitespace-free, and already used to derive the configuration identity
Expand Down Expand Up @@ -129,6 +130,7 @@ fn backend_executable_identity(config: &AutomationConfig) -> Option<Value> {
}
}

#[hotpath::measure(label = "automation_runtime.backend_identity.resolve_executable")]
fn codex_executable_identity(spec: &str) -> Value {
match locate_backend_executable(spec) {
Ok(Some(path)) => opened_executable_identity(spec, &path)
Expand Down Expand Up @@ -246,6 +248,7 @@ fn opened_file_revision(_file: &File, _metadata: &Metadata) -> Option<OpenedFile
None
}

#[hotpath::measure(label = "automation_runtime.backend_identity.digest_executable")]
fn cached_executable_content_digest(
revision: &OpenedFileRevision,
path: &Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ fn reservation_claim_is_live(path: &Path) -> bool {
.is_some()
}

#[hotpath::measure(label = "automation_runtime.effect_journal.read_source_bindings")]
pub fn retained_source_bindings(
path: &Path,
) -> Result<(Option<RetirementBinding>, Option<String>)> {
Expand Down Expand Up @@ -504,10 +505,12 @@ fn reserve_or_replay_with_index_and_writer(
}
}

#[hotpath::measure(label = "automation_runtime.effect_journal.read_record")]
pub fn read_indexed_record_blocking(path: &Path) -> Result<Option<DurableAutomationRecord>> {
with_journal_lock(path, || read_stabilized_record(path))
}

#[hotpath::measure(label = "automation_runtime.effect_journal.read_terminal")]
pub fn read_indexed_terminal_blocking(path: &Path) -> Result<Option<AutomationSettledTerminal>> {
with_journal_lock(path, || {
let Some(record) = read_stabilized_record(path)? else {
Expand Down Expand Up @@ -544,6 +547,7 @@ impl DurableSettlementClassification {
}

/// Revalidates the exact intended settlement without changing journal state.
#[hotpath::measure(label = "automation_runtime.effect_journal.classify_settlement")]
pub fn classify_durable_settlement_blocking(
path: &Path,
requested: &DurableAutomationAdmission,
Expand Down Expand Up @@ -620,6 +624,7 @@ fn classify_durable_settlement_with_stabilizer(
/// order used by binding and makes the state check atomic with subsequent
/// cleanup: a writer cannot stage and bind `Prepared` between this check and
/// deletion.
#[hotpath::measure(label = "automation_runtime.effect_journal.check_unbound_cleanup")]
pub fn unbound_reserved_cleanup_is_safe_blocking(
path: &Path,
expected: &DurableAutomationAdmission,
Expand Down Expand Up @@ -774,6 +779,7 @@ pub fn persist_prepared_terminal_blocking(
/// matching `Prepared` (or already promoted `Terminal`) proves the binding was
/// durable despite the surfaced I/O/readback error; `Reserved` proves no
/// journal binding and leaves the spool for recovery cleanup.
#[hotpath::measure(label = "automation_runtime.effect_journal.replay_exact_binding")]
pub fn replay_exact_binding_after_error_blocking(
path: &Path,
requested: &DurableAutomationAdmission,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ pub async fn append_run_record(
Ok(())
}

#[hotpath::measure(label = "automation_runtime.run_ledger.append_locked")]
fn append_jsonl_line_locked(path: &Path, line: &str) -> std::io::Result<()> {
use std::io::Write;

Expand Down Expand Up @@ -895,6 +896,7 @@ impl AutomationRunLedgerTaskSummary {
}
}

#[hotpath::measure(label = "automation_runtime.run_ledger.load_page", future = true)]
pub async fn load_run_records_page(
dashboard_root: &Path,
limit: usize,
Expand All @@ -908,6 +910,7 @@ pub async fn load_run_records_page(
.map_err(|e| config_error(format!("failed to join automation run ledger read: {e}")))?
}

#[hotpath::measure(label = "automation_runtime.run_ledger.load_for_task_key", future = true)]
pub async fn load_run_records_for_task_key(
dashboard_root: &Path,
requested_task_key: &str,
Expand Down Expand Up @@ -1261,6 +1264,7 @@ fn is_session_evidence_budget_exhausted_skip(
status == AutomationRunStatus::Skipped && session_evidence_budget_exhausted_error
}

#[hotpath::measure(label = "automation_runtime.run_ledger.scan_task_summary")]
fn read_run_ledger_task_summary(
path: &Path,
task: AgentTaskKind,
Expand Down Expand Up @@ -1479,6 +1483,7 @@ fn decode_task_summary(
Ok(summary)
}

#[hotpath::measure(label = "automation_runtime.run_ledger.scan_page")]
fn read_any_run_records_page(
file: &std::fs::File,
path: &Path,
Expand Down Expand Up @@ -1531,6 +1536,7 @@ struct FilteredRunSelection {
effective_task_key: String,
}

#[hotpath::measure(label = "automation_runtime.run_ledger.scan_filtered")]
fn read_filtered_run_records_two_pass(
file: &std::fs::File,
path: &Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ pub(super) fn read_exact_run_digest(path: &Path, run_id: &str) -> Result<Option<
read_exact_run_match(&file, path, run_id).map(|found| found.map(|found| found.digest))
}

#[hotpath::measure(label = "automation_runtime.run_ledger.read_exact_identity")]
pub(super) fn read_exact_run_identity_from_file(
file: &std::fs::File,
path: &Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub enum ExactRunUnboundDiscardOutcome {
/// Stages the canonical JSON row by borrowing the runner-owned record. The
/// record is streamed twice (digest, then durable file) but is never cloned or
/// collected into a payload-sized buffer.
#[hotpath::measure(label = "automation_runtime.run_ledger.bind_exact")]
pub fn bind_staged_run_record_exact<T>(
dashboard_root: &Path,
record: &AutomationRunLedgerRecord,
Expand Down Expand Up @@ -410,6 +411,7 @@ pub async fn discard_staged_run_record_exact(
/// The validator runs under the spool lock. It may acquire the journal lock,
/// establishing the same `spool -> journal` order as exact binding. Returning
/// `false` retains every candidate and lets the caller resnapshot newer state.
#[hotpath::measure(label = "automation_runtime.run_ledger.discard_unbound", future = true)]
pub async fn discard_unbound_staged_run_records_if<F>(
dashboard_root: &Path,
run_id: &str,
Expand Down Expand Up @@ -438,6 +440,7 @@ where
})?
}

#[hotpath::measure(label = "automation_runtime.run_ledger.publish_exact_blocking")]
pub fn publish_staged_run_record_exact_blocking(
dashboard_root: &Path,
run_id: &str,
Expand Down Expand Up @@ -483,6 +486,7 @@ fn publish_staged_run_record_exact_blocking_with_publisher(
/// Repairs only a corrupt exact-append intent whose ledger state has one
/// independently provable outcome. Valid intents remain owned by their exact
/// publication and are not resolved without that journal binding.
#[hotpath::measure(label = "automation_runtime.run_ledger.repair_append_intent")]
pub fn repair_corrupt_run_ledger_append_intent_blocking(dashboard_root: &Path) -> Result<()> {
repair_corrupt_run_ledger_append_intent_impl(
dashboard_root,
Expand Down Expand Up @@ -539,6 +543,7 @@ fn repair_corrupt_run_ledger_append_intent_impl(

/// Blocking form of [`discard_staged_run_record_exact`] for owners that must
/// retain a claim across process-blocking durability work.
#[hotpath::measure(label = "automation_runtime.run_ledger.discard_exact")]
pub fn discard_staged_run_record_exact_blocking(
dashboard_root: &Path,
run_id: &str,
Expand Down Expand Up @@ -593,6 +598,7 @@ where
})?
}

#[hotpath::measure(label = "automation_runtime.run_ledger.discard_stale_exact")]
fn discard_stale_staged_run_record_exact_after_terminal_blocking<F>(
dashboard_root: &Path,
run_id: &str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ impl SessionScopeAuthorizer for ProductionAutomationSessionAuthorizer {
}

impl ProductionAutomationSessionRetrieval {
#[hotpath::measure(label = "automation_runtime.retrieval.mint_request_context")]
fn request_context(
&self,
provider: Option<&str>,
Expand Down Expand Up @@ -341,6 +342,10 @@ fn automation_session_policy_digest() -> Option<PolicyDigest> {
PolicyDigest::from_access_policy_digest(&digest).ok()
}

#[hotpath::measure(
label = "automation_runtime.retrieval.retrieve_session_evidence",
future = true
)]
pub(super) async fn retrieve_automation_session_evidence(
retrieval: &dyn AutomationSessionRetrieval,
query_text: &str,
Expand Down Expand Up @@ -398,6 +403,7 @@ pub(super) async fn retrieve_automation_session_evidence(
Ok(retrieval.retrieve(temporal_query).await)
}

#[hotpath::measure(label = "automation_runtime.retrieval.accept_outcome")]
pub(super) fn accept_automation_temporal_outcome(
outcome: SessionRetrievalOutcome<TemporalKernelResult>,
) -> AutomationTemporalRetrieval {
Expand Down Expand Up @@ -586,6 +592,7 @@ fn registered_scope_matches(
}
}

#[hotpath::measure(label = "automation_runtime.retrieval.resolve_anchor", future = true)]
async fn active_registered_automation_anchor(database: &RegisteredGlobalDb) -> Option<SessionId> {
let snapshot = database.read_snapshot().await.ok()?;
let mut rows = snapshot
Expand Down Expand Up @@ -661,6 +668,10 @@ fn profile_automation_identity(
))
}

#[hotpath::measure(
label = "automation_runtime.retrieval.bind_project_authority",
future = true
)]
pub async fn registered_project_automation_retrieval(
database: RegisteredGlobalDbLeaseV1,
profile_identity: &dyn ProfileIdentityReadPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ pub fn schedule_decision(
schedule_decision_or_history_denial(config, task, records, activity, now_secs, true)
}

#[hotpath::measure(label = "automation_runtime.scheduler.decide_host_receipt")]
pub fn host_receipt_decision(
config: &AutomationConfig,
task: AgentTaskKind,
Expand Down Expand Up @@ -814,6 +815,7 @@ fn new_automation_task_lock_token() -> Result<String> {
Ok(hex::encode(random))
}

#[hotpath::measure(label = "automation_runtime.scheduler.acquire_task_lock")]
fn try_acquire_task_lock_blocking(
path: &Path,
ownership_token: &str,
Expand Down Expand Up @@ -1157,6 +1159,7 @@ impl AutomationTaskLock {
}
}

#[hotpath::measure(label = "automation_runtime.scheduler.release_task_lock")]
fn remove_owned_task_lock_blocking(path: &Path, ownership_token: &str) -> std::io::Result<()> {
let _coordination = acquire_task_lock_coordination(path)?;
let Some(snapshot) = read_task_lock_snapshot(path)? else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ fn is_reserved_support_path(relative: &Path) -> bool {
/// file under `dir` except `SKILL.md`, the manifest/pending sidecars, and
/// `*.new` staging), returned sorted by relative path to mirror the ordering
/// [`ManagedSkill::materialized_package_hash`] hashes support files in.
#[hotpath::measure(label = "automation_runtime.skill_materialization.scan_support_files")]
fn collect_on_disk_support_files(dir: &Path) -> Result<Vec<(PathBuf, Vec<u8>)>> {
fn walk(base: &Path, dir: &Path, out: &mut Vec<(PathBuf, Vec<u8>)>) -> Result<()> {
let entries = match fs::read_dir(dir) {
Expand Down Expand Up @@ -347,6 +348,7 @@ fn collect_on_disk_support_files(dir: &Path) -> Result<Vec<(PathBuf, Vec<u8>)>>
/// does, and — when the result matches the recorded hash — returns a re-derived
/// manifest proving the package is pristine (safe to treat as owned). Returns
/// `Ok(None)` when the file is missing, has no content-hash, or has drifted.
#[hotpath::measure(label = "automation_runtime.skill_materialization.recompute_package")]
fn recompute_on_disk_package(
dir: &Path,
provenance: &FileProvenance,
Expand Down Expand Up @@ -1468,6 +1470,7 @@ fn skills_for_scope(skills: &[ManagedSkill], scope: &MaterializationScope) -> Ve
/// and `project_root` (project): a scope is eligible when its host config
/// directory (`.claude` / `.codex`) is present, so we never create a host
/// integration the user has not opted into.
#[hotpath::measure(label = "automation_runtime.skill_materialization.detect_scopes")]
pub fn detect_scopes(home: &Path, project_root: &Path) -> Vec<MaterializationScope> {
let mut scopes = Vec::new();
for host in MaterializationHost::all() {
Expand Down
Loading