Skip to content

Add durable mcpx daemon call ledger - #11789

Merged
dezren39 merged 1 commit into
mainfrom
queue/20392-9374-mcpx-call-ledger
Nov 18, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/20392-9374-mcpx-call-ledger

Conversation

@dezren39

@dezren39 dezren39 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Record payload-free mcpx daemon tool-call outcomes, caller identity when available, and duration in a rotated, bounded JSONL ledger.
  • Prune daily ledger files to eight calendar days and retain bounded file rotations.
  • Include daemon-recorded totals in aggregator analytics, separately labeling transcript-derived OpenCode mcpx calls as a subset.

Verification

  • go test ./internal/daemon/... ./internal/logging/... (from pkgs/mcpx)
  • bun test test/mcpx-call-ledger-9374.test.ts test/config.test.ts test/quota-horizon-9553.test.ts (aggregator)
  • bun run typecheck (aggregator)
  • git diff --check
  • Full aggregator bun test was attempted but did not complete: port 4871 was already in use and unrelated suite failures occurred; targeted changed-area tests pass.

Closes #9374


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 18, 2026 11:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T11:52:02.968534Z ca4e8c6 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8392b4ba-a505-403a-b8f2-8ab89b412ebe
Commits

Reviewing files that changed from the base of the PR and between f72f822 and ca4e8c6.

Files selected for processing: 12

  • pkgs/mcpx/internal/daemon/call_frames_test.go
  • pkgs/mcpx/internal/daemon/call_ledger.go
  • pkgs/mcpx/internal/daemon/input_required.go
  • pkgs/mcpx/internal/daemon/routes_proto.go
  • pkgs/mcpx/internal/daemon/server.go
  • pm-stack/aggregator/src/analytics-store.ts
  • pm-stack/aggregator/src/config.ts
  • pm-stack/aggregator/src/quota-analytics-view.ts
  • pm-stack/aggregator/src/server.ts
  • pm-stack/aggregator/test/config.test.ts
  • pm-stack/aggregator/test/mcpx-call-ledger-9374.test.ts
  • pm-stack/aggregator/test/quota-horizon-9553.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +650 to +653
const size = statSync(path).size;
if (size > budget) continue;
budget -= size;
for (const line of readFileSync(path, "utf8").split("\n")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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")])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +1953 to +1957
if s.callLedger != nil {
attrs := map[string]any{
"server": server,
"tool": tool,
"outcome": "success",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +253 to +254
callLedger, ledgerErr := logging.NewFileSink(logging.FileOptions{
Dir: filepath.Join(opts.Paths.State, "call-ledger"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@dezren39
dezren39 merged commit 1bee3ad into main Nov 18, 2026
5 checks passed
@dezren39
dezren39 deleted the queue/20392-9374-mcpx-call-ledger branch November 18, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcpx daemon: durable call ledger (direct daemon calls are invisible to analytics)

1 participant