fix(server): wire real total_tool_calls in process_end#377
Merged
Conversation
`emit_process_end` hardcoded `total_tool_calls: 0` behind a "future PR
can add an AtomicU64" comment, so the documented `n` field on every
`process_end` audit record ("number of tool calls dispatched") was
always 0 — a phantom metric.
Add a process-lifetime `tool_calls: Arc<AtomicU64>` to `AuditWriter`
(mirroring the existing `suppressed_failures` counter), increment it once
on each successful `log_tool_start` — the single per-dispatch chokepoint,
shared across all writer clones — and expose `total_tool_calls()`.
`emit_process_end` now reads the real count. The counter lives on the
writer rather than the server, so no constructor signatures change.
Closes #341
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
emit_process_endhardcodedtotal_tool_calls: 0behind a "future PR can add an AtomicU64" comment, so the documentednfield on everyprocess_endaudit record ("number of tool calls dispatched in this process") was always 0 — a phantom metric.This adds a process-lifetime
tool_calls: Arc<AtomicU64>toAuditWriter(mirroring the existingsuppressed_failurescounter), increments it once on each successfullog_tool_start— the single per-dispatch chokepoint, shared across all writer clones — and exposestotal_tool_calls().emit_process_endnow reads the real count.Placing the counter on the writer (which
emit_process_endalready holds, and which isArc-shared across clones) rather than onImapMcpServermeans no constructor signatures change.Count semantics: one increment per successfully-started tool call, including the infrastructure path (
use_account,list_accounts). A call counts when itstool_startis accepted (including a write suppressed underfail_open = true); afail_open = falsewrite failure aborts the call and is not counted.Verification:
total_tool_calls_counts_each_tool_start(starts at 0, increments perlog_tool_start, non-tool records don't bump it, clones share the counter)rimap-auditlib tests passcargo clippy -p rimap-audit -p rimap-server --all-targets --all-featurescleanCloses #341
🤖 Generated with Claude Code