Skip to content

[Bug]: internal_tool_call activity records skip the 64KB response truncation #1173

Closed

Description

@antongulin

What happened?

My config.db grew to about 940MB. Most of it is the activity log.

When I looked inside, I found records far bigger than the 64KB response limit. The biggest single record is 10.75MB, which is about 160 times the cap.

I checked every activity record over 200KB. There are 82 of them, and they are all the same kind:

types of oversized records: {'internal_tool_call': 82}

 SIZE MB  TYPE                   TOOL              response field len   response_truncated
   10.75  internal_tool_call     call_tool_read              10470961   False
    5.14  internal_tool_call     call_tool_read               5133653   False
    4.98  internal_tool_call     call_tool_read               4972547   False
    4.82  internal_tool_call     call_tool_read               4813426   False
    4.70  internal_tool_call     call_tool_read               4698651   False

Every one is type: internal_tool_call with tool_name: call_tool_read. Not a single normal tool call is oversized. So regular calls are being truncated correctly, and this one path is not.

Also note the last column. None of these records has response_truncated set, which fits: nothing truncated them, so nothing flagged them.

The truncation code itself looks fine. internal/storage/activity.go has DefaultMaxResponseSize = 64 * 1024 and a truncateResponse(response string, maxSize int) that appends ...[truncated]. It just does not seem to run on this path.

There is a matching comment in internal/httpapi/activity.go:

Arguments, Response and Metadata are unbounded in practice (only Response is truncated, at 64KB)

And internal/server/mcp.go has emitActivityInternalToolCallTruncated, described as being for a handler whose recorded response is larger than what the agent received. So a truncating variant exists for the internal path. It looks like the plain internal emit path is the one that stores the full response.

I have not traced which call site is at fault, so I may have the mechanism wrong. The stored data is what I am sure about.

Expected behavior

An internal_tool_call record should be truncated at activity_max_response_size (64KB by default), the same as a normal tool call, and should get response_truncated: true when that happens.

Steps to reproduce

  1. Add an upstream with a tool that returns a very large response. I hit this with cloudflare-workers workers_get_worker_code, which returns a whole bundled Worker.
  2. Call that tool through mcpproxy's own call_tool_read, so the record is stored as internal_tool_call.
  3. Read the newest record back from the activity_records bucket in config.db.
  4. The stored response is the full size, not 64KB, and response_truncated is not set.

MCPProxy version

MCPProxy v0.63.0 (personal) linux/amd64

Operating system

Linux

Relevant logs

Nothing is logged. It is silent, which is why it went unnoticed for months. Sizes for context:

activity_records          267 MB   10889 records   avg 24 KB   largest 10.5 MB
server_*_tool_calls       432 MB   ~17000 records              largest  9.1 MB

Why this matters

The setting is there to bound how big the activity log can get, and this path quietly ignores it. A handful of big calls can add hundreds of MB. My database is 940MB and there is no error anywhere to suggest something is wrong.

Pre-submission checklist

  • I searched existing issues and did not find a duplicate.

Activity

  1. antongulin commented on Sep 2, 2026

    @antongulin
    ContributorAuthor

    Correction to my own report. I cloned the repo and traced it properly, and I got the cause wrong above.

    I said regular tool calls are being truncated and this one path is not. That is not right. Nothing is truncated. The truncation code is written and unit-tested but never wired into the write path at all.

    At b4a586a:

    • truncateResponse (internal/storage/activity.go:35) and its exported wrapper TruncateActivityResponse (:535) have zero production callers. The only caller anywhere is internal/storage/activity_test.go:317.
    • The config field ActivityMaxResponseSize (internal/config/config.go:468, default 65536 at :1801) is never read. Those two lines are its only mentions in the whole tree.
    • All three places that build an activity record assign the response straight through with no size check: internal/runtime/activity_service.go:617, :896, :981.
    • SaveActivity does not truncate either.

    So the reason all 82 oversized records are internal_tool_call is not that this path skips a check the others apply. It is that call_tool_read proxies whole upstream responses, so it is simply where the large payloads happen to be. A normal tool call returning 10MB would be stored at 10MB too.

    One more thing I misread. ResponseTruncated on the record is not a storage flag. Per the Spec 103 comment at activity_service.go:855-859 it means the recorded response is larger than the one the agent received. That is the opposite direction from storage truncation, so a fix should not just reuse that field without thinking about the two meanings.

    The observed data in the report is unchanged and still accurate. Only my explanation was wrong.

    This makes it a smaller and more contained fix than I first described: apply the existing TruncateActivityResponse on the write path and feed it ActivityMaxResponseSize. ActivityService already receives retention config from runtime.go:329, so the value has a natural home. I am putting a PR together and will link it here.

  2. Dumbris commented on Sep 7, 2026

    @Dumbris
    Member

    Fixed by #1174 (activity-log response cap applied on the write path, merged 2026-09-04 as 7a27851e7) and #1214 (per-server tool-call history bounds plus mcpproxy db compact, merged 2026-09-05 as f95fc1428) — thanks for both the report and the PR.

    Verified on current main: truncateForStorage (internal/runtime/activity_service.go:258) is now applied at all three record-building sites. The subtlety you raised was kept — the storage cut deliberately does not set ResponseTruncated, because that field carries the opposite Spec-103 meaning ("the agent received less") that two cost consumers read as "exclude from delivered traffic".

    Run mcpproxy db compact to reclaim space already written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions