mirror of
https://github.com/openai/codex.git
synced 2026-09-20 12:47:38 +00:00
## Why Memory usage telemetry identifies artifact kinds but does not distinguish reads from `memories` and `memories_v2`. ## What changed Return each artifact's memory version from shell command classification and add a `memory_version` tag (`v1` or `v2`) to usage counters. Normalize Windows path separators before classifying memory paths. ## Testing Extend regression coverage for both memory versions with Unix and PowerShell reads, and add a test for commands that read artifacts from both roots. GitOrigin-RevId: 68eaab3af0317613e4969e8c4e5478b18255ca52
52 lines
1.7 KiB
Rust
52 lines
1.7 KiB
Rust
use crate::tools::context::ToolInvocation;
|
|
use crate::tools::context::ToolPayload;
|
|
use crate::tools::flat_tool_name;
|
|
use crate::tools::handlers::unified_exec::ExecCommandArgs;
|
|
use codex_memories_read::usage::MEMORIES_USAGE_METRIC;
|
|
use codex_memories_read::usage::memories_usage_from_command;
|
|
use codex_protocol::MemoryVersion;
|
|
|
|
pub(crate) fn emit_metric_for_tool_read(invocation: &ToolInvocation, success: bool) {
|
|
let Some(command) = shell_script_for_invocation(invocation) else {
|
|
return;
|
|
};
|
|
|
|
let success = if success { "true" } else { "false" };
|
|
let tool_name = flat_tool_name(&invocation.tool_name);
|
|
for (kind, version) in memories_usage_from_command(&command) {
|
|
invocation.turn.session_telemetry.counter(
|
|
MEMORIES_USAGE_METRIC,
|
|
/*inc*/ 1,
|
|
&[
|
|
("kind", kind.as_tag()),
|
|
(
|
|
"memory_version",
|
|
match version {
|
|
MemoryVersion::V1 => "v1",
|
|
MemoryVersion::V2 => "v2",
|
|
},
|
|
),
|
|
("tool", tool_name.as_ref()),
|
|
("success", success),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
pub(crate) fn shell_script_for_invocation(invocation: &ToolInvocation) -> Option<String> {
|
|
let ToolPayload::Function { arguments } = &invocation.payload else {
|
|
return None;
|
|
};
|
|
|
|
if !invocation.tool_name.is_default_namespace() {
|
|
return None;
|
|
}
|
|
|
|
match invocation.tool_name.name.as_str() {
|
|
"exec_command" => serde_json::from_str::<ExecCommandArgs>(arguments)
|
|
.ok()
|
|
.map(|params| params.cmd),
|
|
_ => None,
|
|
}
|
|
}
|