From b17c74cfd5ebb39fe70ffaff78de198120278636 Mon Sep 17 00:00:00 2001 From: jif Date: Wed, 7 Oct 2026 11:03:11 +0000 Subject: [PATCH] Record telemetry for AGENTS.md changes made by apply_patch (#51652) ## What changed Increment `codex.agents_md.edit` for committed `apply_patch` changes to `AGENTS.md` and `AGENTS.override.md`, matching filenames case-insensitively and tagging the counter with the normalized filename. Count additions, deletions, updates, and distinct move destinations, including changes committed before a later patch failure. GitOrigin-RevId: bcbfa671acb37a2a24fe7e4effc9318981a22ec7 --- .../core/src/tools/runtimes/apply_patch.rs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/codex-rs/core/src/tools/runtimes/apply_patch.rs b/codex-rs/core/src/tools/runtimes/apply_patch.rs index 45cc7e2e9b..b013646e8f 100644 --- a/codex-rs/core/src/tools/runtimes/apply_patch.rs +++ b/codex-rs/core/src/tools/runtimes/apply_patch.rs @@ -15,6 +15,7 @@ use crate::tools::sandboxing::ToolError; use crate::tools::sandboxing::ToolRuntime; use crate::tools::sandboxing::executor_windows_sandbox_selection; use codex_apply_patch::AppliedPatchDelta; +use codex_apply_patch::AppliedPatchFileChange; use codex_apply_patch::ApplyPatchAction; use codex_apply_patch::ApplyPatchOptions; use codex_exec_server::FileSystemSandboxContext; @@ -169,7 +170,7 @@ impl ToolRuntime for ApplyPatchRunti &mut self, req: &ApplyPatchRequest, attempt: &SandboxAttempt<'_>, - _ctx: &ToolCtx, + ctx: &ToolCtx, ) -> Result { let started_at = Instant::now(); let fs = req.turn_environment.environment.get_filesystem(); @@ -203,6 +204,28 @@ impl ToolRuntime for ApplyPatchRunti Ok(delta) => delta, Err(failure) => failure.into_parts().1, }; + // Count committed paths, including changes made before a later patch failure. + for change in delta.changes() { + let move_path = match &change.change { + AppliedPatchFileChange::Update { move_path, .. } => move_path.as_ref(), + AppliedPatchFileChange::Add { .. } | AppliedPatchFileChange::Delete { .. } => None, + }; + for path in + std::iter::once(&change.path).chain(move_path.filter(|path| *path != &change.path)) + { + if let Some(filename @ ("agents.md" | "agents.override.md")) = path + .basename() + .map(|name| name.to_ascii_lowercase()) + .as_deref() + { + ctx.step_context.session_telemetry.counter( + "codex.agents_md.edit", + /*inc*/ 1, + &[("filename", filename)], + ); + } + } + } self.committed_delta.append(delta); let output = ExecToolCallOutput { exit_code,