feat: add WriteFileInWorkspaceStream #2
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/streaming-workspace-write"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of basepeak-ai/bpai#1220 — workspace file writes materialise the file many times over; a single large file OOM-killed a tenant.
What
WriteFileInWorkspaceStream(ctx, filePath, r io.Reader, opts...)posts a small JSON header followed directly byrto the server's newworkspaces/write-file-streamroute (basepeak-ai/gptscript#13). The content is never held in memory as a whole.Run.requestnow sends anio.Readerpayload as is (application/octet-stream) instead of JSON-marshalling it. Response handling stays the same asrunBasicCommand, so conflict errors still parse intoConflictInWorkspaceError.A server without the route answers 404. That is returned as
ErrStreamingWriteUnsupported, so callers can fall back toWriteFileInWorkspace. Becausermay have been partly read by then, the caller has to reopen its source.WriteFileInWorkspaceis unchanged.Measured
Writing a 1 GiB file, peak RSS of the calling process:
WriteFileInWorkspaceWriteFileInWorkspaceStreamTests
TestWriteFileInWorkspaceStream: a ~3.6 MB binary round-trip through a real workspace-provider daemon, with a path containing a space and a subdirectory, plus a revision conflict.TestWriteFileInWorkspaceStreamOldServer: a 404 maps toErrStreamingWriteUnsupported.The integration test needs a gptscript binary that has the new route. Until basepeak-ai/gptscript#13 is merged and released, run it with
GPTSCRIPT_BINpointing at a build of that branch.Review (fresh-context reviewers) — outcome
Fixed
Read. A stream of unknown length now goes through a pipe that fails when the context is done. Test: a stalled source with a 300 ms deadline returns at 0.3 s. Without the fix, the same test hangs until the test runner kills it.Content-Lengthagain, as the buffered route did.ris unread onErrStreamingWriteUnsupported: reworded. Also removed a dead 404 check on a pre-response error path.Dismissed
Re-validated on the final commit
WriteFileInWorkspace([]byte): ~34 MiB peak in the server, and nothing in the client beyond the caller's own buffer.CI note: this repo's workflows fail after 0 s on
maintoo, so these local runs are the evidence.