probo icon indicating copy to clipboard operation
probo copied to clipboard

MCP `updateDocument` on large documents exceeds the API server's 30 s WriteTimeout; update succeeds but client gets 502

Open Mike-LandClever opened this issue 3 weeks ago • 4 comments

Summary

On a self-hosted Probo (0.340.0), the MCP updateDocument tool regularly takes longer than 30 seconds on large documents. The API server is built with httpserver.NewServer from go.gearno.de/kit with no options, so it inherits the kit defaults: WriteTimeout: 30s, ReadTimeout: 30s (pkg/probod/probod.go, runApiServer). When the tool call runs past 30 s, the handler finishes and the update is committed, but the connection has already hit its write deadline. The response never reaches the client, and the reverse proxy (CloudFront in our case) returns 502.

The MCP client (Claude) reports the call as failed even though the change was saved. A retry can apply the same edit twice.

Evidence (probod logs, 7 days)

Tool Calls Median Max Calls ≥ 29 s
updateDocument 37 9.5 s 34.6 s 10
publishDocument 28 1.7 s 10.3 s 0
all other tools — < 0.2 s < 0.2 s 0
  • Several POST /api/mcp/v1 requests are logged at almost exactly 30.000s, and others at 33–34 s, all with status 200 and "tool call result","is_error":false.
  • Duration grows over time on the same document: about 24.5 s per update two days ago, 33–35 s now. The document's getDocument response is about 0.7–1.4 MB.
  • Example log line (IDs removed):
    mcp "tools/call" method completed  duration_ms=34588  tool=updateDocument
    POST /api/mcp/v1 200 3.6kB 34.604847689s
    

Where the time seems to go

DocumentService.Update (pkg/probo/document_service.go) does very little except, when Content is set, collaboration.PutContent followed by collaboration.MaterializedContent, inside one transaction. Because the duration grows with each edit to the same document, our guess is that this work replays or re-encodes the document's growing collaboration history on every update. We haven't profiled it.

Expected

An MCP tool call either returns its result or a clean error. A successful write shouldn't come back to the client as a 502.

Suggested fixes (any one helps)

  1. Raise or disable WriteTimeout for the API server (httpserver.WithWriteTimeout(...)), at least on /api/mcp/v1, or make it configurable (e.g. PROBOD_API_WRITE_TIMEOUT). An http.ResponseController.SetWriteDeadline per request on the MCP route would also work.
  2. Make updateDocument content writes cost O(change) rather than O(history), e.g. by compacting or snapshotting the collaboration state.
  3. Optionally, have the streamable-HTTP MCP response send SSE keep-alives or progress notifications for long tool calls. This only helps once (1) is in place, because Go's write deadline is absolute, not idle.

Environment

  • Probo 0.340.0, official image, Docker Compose, single instance
  • Reverse proxy: AWS CloudFront (origin read timeout 60 s), so the 30 s cut-off is Probo's, not the proxy's
  • MCP client: Claude custom connector (streamable HTTP, stateless)

Mike-LandClever avatar Nov 10 '26 17:11 Mike-LandClever

@Mike-LandClever should be better now could you confirm?

gearnode avatar Nov 13 '26 16:11 gearnode

Should be improved after #2326 stack of changes will be merged.

lukkor avatar Nov 16 '26 10:11 lukkor

Thanks both. We upgraded to 0.345.0 on 13 Nov and picked up 0.346.0 on 15 Nov. Unfortunately MCP saves are now slower, and a new merge error shows up.

tools/call durations from the probod logs (ms):

Version Tool Calls Median Max Calls ≥ 29 s
0.340.0 updateDocument 72 6,860 43,818 24
0.340.0 publishDocument 53 1,992 12,938 0
0.345.0 updateDocument 10 957 131,752 2
0.346.0 updateDocument 34 127,923 186,042 22
0.346.0 publishDocument 15 27,017 115,162 7

The 30 s write deadline no longer cuts responses (requests now run 2–3 minutes), but our proxy gives up at 60 s. 22 MCP requests on 0.346.0 ended with status 0 (client gone), and the client then retries, so saves to the same document overlap. For example, two updateDocument calls started 9 s apart took 160 s and 147 s.

New error on 0.345.0 and 0.346.0 (8 times since the upgrade, all on the same document):

internal error in MCP tool handler: cannot apply document collaboration edits:
cannot persist collaboration edits: cannot merge refreshed collaboration document:
cannot merge Automerge document: cannot apply direct merge batch:
cannot validate merged actor sequence: duplicate actor sequence 51

The sequence number in the error rises with each occurrence (38, 41, 42, 44, 47, 49, 51, 51). It looks like the MCP writer reuses an actor ID, and the new retry loop keeps hitting the same conflict until it gives up.

Not resource pressure: the dataset is tiny (3 documents, 102 collaboration_changes rows, 336 kB). The instance is a t4g.medium with a full CPU credit balance and around 2% CPU at rest. CPU goes to 75–98% only while these saves run, so the time is spent inside probod, not waiting on Postgres. pg_stat_activity shows no lock waits.

Unrelated, but new in 0.346.0: with no tracing address configured, probod now tries to export traces to localhost:4318 and logs open telemetry error ... connection refused every 5 s (about 47k lines since Friday). Is there a setting to turn tracing off completely?

Happy to test the #2326 stack once it's released.

Mike-LandClever avatar Nov 16 '26 10:11 Mike-LandClever

@Mike-LandClever with the latest version it should be fixed. Could you confirm?

gearnode avatar Nov 17 '26 21:11 gearnode