Repository navigation
feat(executorrpc): serve FileService from mecatl-executor serve - #2853
Conversation
78500ff to
1d10b1e
Compare
rdimitrov
left a comment
There was a problem hiding this comment.
LGTM. Bounded upload drain, the per-call max-file-bytes check against executionenv.MaxFileBytes, error mapping, and the refcounted lock table (entries removed when idle, waits honour ctx) all look right, and buffering in memory up to MaxFileBytes is a fine interim step until WorkspaceStreamer exists.
Non-blocking thought on the server lock: the rationale is to keep write serialization independent of the plugged-in workspace, but it only covers CreateFile/ReplaceFile. RemoveFile, RenameFile and CopyFile's destination can still race a conditional replace on the same path without it. osfs covers all of them today, so nothing is broken. For microvm, it's worth deciding whether the workspace contract owns this (in which case this lock is redundant), or whether the server lock should cover every mutating RPC.
Add `internal/executorrpc/fileserver`, a gRPC adapter for the executor `FileService` over a `Workspace` seam (`tool.Workspace`, `tool.WorkspaceNamespace`, `tool.BoundedWorkspaceReader`, `tool.AuthorityResourceResolver`). It imports only `engine`, the generated contract, and gRPC; the existing `internal-executorrpc` depguard rule keeps `osfs` out, and `cmd/mecatl-executor` plugs `osfs` in on `/workspace`. `CreateFile` and `ReplaceFile` buffer the streamed chunks up to `WithMaxFileBytes` and write only after the caller closes its stream. A server-lifetime lock table keyed by `tool.LedgerKey` serializes the version check and write per path across calls. `ReadFile` streams 3 MiB chunks with the version on the last message. `serve` registers the Files service next to Commands and takes `-max-file-bytes` for the template's `maxFileBytes`. The one-shot Pod exec mode is unchanged. Add `internal/executorrpc/fileconformance`, which runs the `fsconformance` suites over gRPC through a minimal client, against `memfs` in the adapter tests and `osfs` in the command tests.
1d10b1e to
4a4fe8c
Compare
Summary
Serves the executor
FileServiceover gRPC frommecatl-executor serve, next to the Commands service from #2695. Nothing in the running system uses it yet; Pod exec keeps working until the transport switch (#2718).internal/executorrpc/fileserveris the adapter. Its seam,fileserver.Workspace, combinestool.Workspace,tool.WorkspaceNamespace,tool.BoundedWorkspaceReaderandtool.AuthorityResourceResolver, so the package imports onlyengine, the generated contract and gRPC. The existinginternal-executorrpcdepguard rule keepsosfsout;cmd/mecatl-executorplugsosfsin on/workspace.Serverserializes create-only writes and conditional replacements per path for the life of the process, keyed bytool.LedgerKey. The lock is taken after the caller closes its stream and held only for the version check and write, never while an upload is in flight. Waiting gives up when the call's context ends.MaxFileBytesbounds both directions: uploads fail withLIMIT_EXCEEDEDas soon as the received total passes the limit, and reads useReadVersionBounded.serve -max-file-bytestakes the template's value (1 toexecutionenv.MaxFileBytes); passing it from the controller is Switch file and command operations to the executor server #2718.internal/executorrpc/fileconformancerunsfsconformance.Run,RunNamespace,RunMutationAffinityandRunExternalMutationConflictover gRPC through a minimal test client: againstmemfsin the adapter tests and againstosfsthrough the realservewiring incmd/mecatl-executor. The adapter tests don't import rootosfs, so Move the contract and adapters into standalone modules #2716 stays a package move.Issue relationship
Closes #2694
Stacked on #2832 (#2770); retarget to
mainonce that merges.Type of change
Test plan
Baseline checks
task lint)task test): covered bytask test:racetask test:race)go run ./cmd/mecademo): tool call, permission ask and approval, and result; the demo doesn't go through this server until Switch file and command operations to the executor server #2718task docs)task site:build)task api:check)task api:update+engine/CHANGELOG.mdAlso run:
go test -race -count=3on./internal/executorrpc/...,./cmd/mecatl-executor/and./internal/executionexecutor/in agolang:1.27.3linux/arm64 container as uid 1000, andgolangci-linton the touched packages withGOOS=linux. The race test for per-path serialization was mutation-checked: removing the lock, using one global key, or keying by the raw path instead oftool.LedgerKeyeach fails it.task check:prfails only onbuf breakingagainstmain, from the streaming RPCs in #2832; it clears once #2832 merges.Changes
internal/executorrpc/fileserver/server.goFileServiceadapter, limits, error mappinginternal/executorrpc/fileserver/locks.gointernal/executorrpc/fileconformance/conformance.gofsconformanceover gRPC, bufconnDial, test clientcmd/mecatl-executor/serve.goFileServiceonosfs;-max-file-bytes.golangci.ymlRunnerUser-facing change
None.
Special notes for reviewers
executor-protocol.mdspools writes through aWorkspaceStreamerextension inengine/tool, which doesn't exist yet and is out of scope here (nothing underengine/changes). Each upload is held in memory up toMaxFileBytes(at most 5 MiB per concurrent write) and committed with the whole-fileCreateFile/ReplaceFile. Spooling is deferred untilWorkspaceStreamerexists. A stream that fails or is cancelled before the caller closes it writes nothing.osfs's.osfsalready serializes writes per canonical path across the process, which is enough on its own in a long-livedserveprocess. The server's lock keeps the guarantee independent of the plugged-in workspace (microvm will plug in its own). Its key is lexical, so symlink aliases get different server keys;osfs's canonical-path locks still cover them.CopyFileisn't bounded byMaxFileBytes, as in the one-shot executor today.servestill registers both services.