Repository navigation
mcpx: cap returned exec stdout at exec.maxOutputBytes (CODE-16 of #1937) #2979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff81050
mcpx: cap returned exec stdout at exec.maxOutputBytes (CODE-16, #1937)
dezren39 a93571b
mcpx: truncation marker stays within small limits; bounded rune-bound…
dezren39 ed860b7
mcpx: capped stdout cannot bypass the cap via Result or the JSON enve…
dezren39 efa33d1
fix(mcpx): honor request-scoped exec.maxOutputBytes in daemon handleE…
dezren39 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package daemon | ||
|
|
||
| import ( | ||
| "io" | ||
| "log" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/dezren39/mcpx/internal/settings" | ||
| ) | ||
|
|
||
| // #1937 (CODE-16) Codex finding: exec.maxOutputBytes is call-scoped, but | ||
| // the daemon's handleExec built its service from cached startup | ||
| // settings, so a per-request --exec-max-output-bytes was silently | ||
| // ignored for remote executions. handleExec now applies | ||
| // s.callSettings(r).Bytes("exec.maxOutputBytes") to the service it runs; | ||
| // this pins the resolution that assignment relies on: the header value | ||
| // wins for the one request, and without a header the daemon's own | ||
| // (default) value stands. | ||
| func TestCallSettingsExecMaxOutputBytes(t *testing.T) { | ||
| sch, err := settings.New(settings.Registry()) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| s := &Server{ | ||
| set: settings.NewSet(sch), | ||
| logger: log.New(io.Discard, "", 0), | ||
| } | ||
|
|
||
| req := httptest.NewRequest(http.MethodPost, "/v1/exec", nil) | ||
| req.Header.Set(CallSettingsHeader, `{"exec.maxOutputBytes":"1024"}`) | ||
| if got := s.callSettings(req).Bytes("exec.maxOutputBytes"); got != 1024 { | ||
| t.Errorf("request-scoped exec.maxOutputBytes = %d, want 1024", got) | ||
| } | ||
|
|
||
| bare := httptest.NewRequest(http.MethodPost, "/v1/exec", nil) | ||
| if got := s.callSettings(bare).Bytes("exec.maxOutputBytes"); got != 64*1024 { | ||
| t.Errorf("default exec.maxOutputBytes = %d, want %d (64KiB)", got, 64*1024) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package execsvc_test | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/dezren39/mcpx/internal/execsvc" | ||
| ) | ||
|
|
||
| // CODE-16 (#1937), Codex P2 on PR 2979: when large JSON stdout is | ||
| // capped, the parsed Result must not survive as a side channel that | ||
| // lets a renderer re-present the uncapped answer in full. | ||
| func TestTruncatedJSONStdoutClearsStdoutDerivedResult(t *testing.T) { | ||
| svc := service(t, store(t)) | ||
| svc.Limits.StdoutLimit = 200 | ||
| res, _ := run(t, svc, ` | ||
| import { installGlobals } from "./mcpx-client.ts"; | ||
| installGlobals(); | ||
| console.log(JSON.stringify({ data: "x".repeat(5000) })); | ||
| `, execsvc.Options{}) | ||
|
|
||
| if !res.StdoutTruncated { | ||
| t.Fatal("expected StdoutTruncated") | ||
| } | ||
| if len(res.Stdout) > 200 { | ||
| t.Fatalf("capped stdout is %d bytes, over the 200-byte cap", len(res.Stdout)) | ||
| } | ||
| if res.Result != nil { | ||
| t.Fatalf("stdout-derived Result survived truncation: %#v", res.Result) | ||
| } | ||
| } | ||
|
|
||
| // Under the cap the stdout-derived Result is offered parsed, as | ||
| // before: the clearing above must only fire on truncation. | ||
| func TestUntruncatedJSONStdoutKeepsResult(t *testing.T) { | ||
| svc := service(t, store(t)) | ||
| svc.Limits.StdoutLimit = 200 | ||
| res, _ := run(t, svc, ` | ||
| import { installGlobals } from "./mcpx-client.ts"; | ||
| installGlobals(); | ||
| console.log(JSON.stringify({ total: 2 })); | ||
| `, execsvc.Options{}) | ||
|
|
||
| if res.StdoutTruncated { | ||
| t.Fatal("under-cap output marked truncated") | ||
| } | ||
| m, ok := res.Result.(map[string]any) | ||
| if !ok || m["total"] != float64(2) { | ||
| t.Fatalf("JSON on stdout should be offered parsed, got %#v", res.Result) | ||
| } | ||
| if !strings.Contains(res.Stdout, "total") { | ||
| t.Fatalf("stdout = %q", res.Stdout) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.