Repository navigation
Add durable mcpx daemon call ledger - #11789
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca4e8c6d9d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if callerSession != "" { | ||
| attrs["caller_session"] = callerSession | ||
| } | ||
| s.callLedger.Write(logging.Record{Time: time.Now(), Msg: "tool_call", Attrs: attrs}, nil) |
There was a problem hiding this comment.
Record calls from the ask and explicit-task execution paths
Calls executed through /v1/ask or explicit /v1/call tasks never reach this ledger write. handleAskBegin calls s.reg.CallAsk in routes_proto.go:628, and startCallTask calls s.reg.Call in ops.go:804; neither invokes reportCallFrame. The ask path is used by the MCP proxy (internal/cli/serve_ask.go:218), so this omits a production call flow, not just an internal helper. Record outcomes at those execution sites as well, or move ledger recording to a shared execution boundary, so daemon totals include their successes and errors.
Useful? React with 👍 / 👎.
| const size = statSync(path).size; | ||
| if (size > budget) continue; | ||
| budget -= size; | ||
| for (const line of readFileSync(path, "utf8").split("\n")) { |
There was a problem hiding this comment.
Avoid silently dropping retained files from seven-day totals
When retained ledger files total more than 32 MiB, this skips entire files but presents the result as the seven-day call total. The producer permits 16 MiB per file plus eight rotations and eight daily files, so its normal retention bounds exceed this reader's budget. Files are scanned oldest-first, and even expired records consume the budget before timestamp filtering; older files can therefore cause the newest calls and errors to disappear from analytics. Aggregate incrementally or expose truncation explicitly rather than reporting incomplete counts as totals.
Useful? React with 👍 / 👎.
| if len(stem) < len("2006-01-02") { | ||
| continue | ||
| } | ||
| day, err := time.Parse("2006-01-02", stem[:len("2006-01-02")]) |
There was a problem hiding this comment.
Parse ledger dates in the same timezone as the retention cutoff
On hosts west of UTC, time.Parse interprets the filename as UTC midnight while cutoff uses local midnight. For example, on November 18 in Los Angeles, mcpx-2026-11-11.jsonl parses to November 11 at 00:00Z, before the cutoff at 08:00Z, and is deleted even though November 11 is the eighth retained calendar day. That file can still contain calls within the aggregator's rolling seven-day window. Use time.ParseInLocation with now.Location(), or compare calendar dates consistently, to avoid prematurely deleting valid history.
Useful? React with 👍 / 👎.
| if s.callLedger != nil { | ||
| attrs := map[string]any{ | ||
| "server": server, | ||
| "tool": tool, | ||
| "outcome": "success", |
There was a problem hiding this comment.
Exclude simulated dry-run calls from the execution ledger
When an exec request uses dryRun: true, its calls still reach this reporter after dryRunResult returns synthetic responses without contacting any server, as shown in handleCall, handleBatch, and handleCallPath. The new ledger nevertheless records them as successful executions without preserving the dry-run marker, and readMcpxCallLedger counts those rows as daemon activity. Rehearsing a script therefore inflates execution totals and successful-call counts even though no tools ran. Skip ledger writes for dry-run calls, or preserve and filter their synthetic status while retaining the existing exec call frames.
Useful? React with 👍 / 👎.
| callLedger, ledgerErr := logging.NewFileSink(logging.FileOptions{ | ||
| Dir: filepath.Join(opts.Paths.State, "call-ledger"), |
There was a problem hiding this comment.
Coordinate ledger rotation across config-specific daemons
When different project configurations run concurrently, their daemons share Paths.State (Paths.ForConfig changes only the socket and info paths), so each opens this same daily ledger file. FileSink only synchronizes within one instance and keeps its descriptor open: one daemon can rotate and eventually prune the file another daemon is still writing. The quieter daemon then appends new call records to an unlinked file until its own rotation or day change, silently dropping current activity from analytics. Use a process-safe shared writer/rotation scheme or separate per-daemon files that analytics aggregates.
Useful? React with 👍 / 👎.
Summary
Verification
Closes #9374
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.