Skip to content

Tail remote MCP logs before downloading - #1797

Merged
xeophon merged 1 commit into
feat/nano-as-v1from
codex/tail-remote-mcp-logs
Jun 21, 2026
Merged

Tail remote MCP logs before downloading#1797
xeophon merged 1 commit into
feat/nano-as-v1from
codex/tail-remote-mcp-logs

Conversation

@xeophon

@xeophon xeophon commented Jun 21, 2026

Copy link
Copy Markdown
Member

Overview

Bound MCP server failure-log collection at the runtime boundary so diagnostics no longer transfer and decode an entire remote log just to keep its suffix.

Why

log_tail previously called runtime.read(log) and only applied limit after the complete file reached the host and was decoded. A large server log could therefore consume hundreds of MiB and block the event loop while the launcher was already trying to report a startup failure. In remote runtimes, the unnecessary file transfer adds another unbounded cost.

Change

  • Run tail -c <limit> <log> inside the runtime with separate, argv-safe arguments.
  • Return the bounded stdout when tail succeeds while preserving missing/unreadable log behavior as an empty diagnostic.
  • Return immediately for nonpositive limits, avoiding the old [-0:] behavior that returned the entire stripped log.
  • Keep the optimization localized to log_tail; successful server launches and their control flow are unchanged.

Performance impact

A three-round median benchmark over a 256 MiB log measured:

Metric Before After Saved
Wall time 26.337 ms 3.087 ms 23.250 ms (88.3%)
Maximum event-loop stall 12.441 ms 1.180 ms 11.261 ms (90.5%)
Peak traced host allocation 512.01 MiB 0.27 MiB 511.74 MiB (>99.9%)
Runtime-to-host log payload 268,435,456 bytes at most 2,000 bytes 268,433,456 bytes (>99.999%)

Wall time used perf_counter, loop stall used a 1 ms asyncio heartbeat, and host allocation used tracemalloc. The new measurement includes process startup for tail.

Tradeoff

Tiny failure logs may pay a remote command-startup cost. This path only runs while enriching launch failures, and bounding the transferred data prevents error reporting from downloading an arbitrarily large log.


Note

Low Risk
Change is confined to error-enrichment on failed server launch and assumes standard tail in runtimes; no auth or rollout success-path behavior changes.

Overview
log_tail no longer pulls the full remote log into the host and slices it locally. It runs tail -c <limit> inside the runtime so failure diagnostics stay bounded (default 2000 bytes), which avoids huge transfers and decode stalls when MCP startup fails on large logs.

Nonpositive limit now returns "" immediately instead of relying on Python slicing that could return the entire stripped log for limit == 0. Successful launches are unchanged; this only affects log snippets attached to ToolsetError paths in serve_in_runtime.

Reviewed by Cursor Bugbot for commit 65c4f52. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Use tail -c to read last N bytes of remote MCP logs before downloading

Updates log_tail in launch.py to invoke tail -c <limit> via runtime.run instead of reading and slicing the full log file in memory. Returns an empty string for non-positive limits or non-zero exit codes, and no longer strips whitespace or applies error-replacement decoding.

Macroscope summarized 65c4f52.

@macroscopeapp

macroscopeapp Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Small performance optimization to the log_tail utility function that avoids downloading large remote logs into host memory by running tail -c remotely instead. The function is used only for error enrichment, maintains proper error handling, and the change is well-documented.

You can customize Macroscope's approvability policy. Learn more.

@xeophon
xeophon merged commit 8db1017 into feat/nano-as-v1 Jun 21, 2026
5 checks passed
pull Bot pushed a commit to Stars1233/verifiers that referenced this pull request Jun 23, 2026
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.

1 participant