Skip to content

feat(executorrpc): serve FileService from mecatl-executor serve - #2853

Merged
blkt merged 1 commit into
mainfrom
feat/2694-files-server
Nov 18, 2026
Merged

blkt merged 1 commit into
mainfrom
feat/2694-files-server

Conversation

@blkt

@blkt blkt commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Serves the executor FileService over gRPC from mecatl-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/fileserver is the adapter. Its seam, fileserver.Workspace, combines tool.Workspace, tool.WorkspaceNamespace, tool.BoundedWorkspaceReader and tool.AuthorityResourceResolver, so the package imports only engine, the generated contract and gRPC. The existing internal-executorrpc depguard rule keeps osfs out; cmd/mecatl-executor plugs osfs in on /workspace.
  • A lock table owned by the Server serializes create-only writes and conditional replacements per path for the life of the process, keyed by tool.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.
  • MaxFileBytes bounds both directions: uploads fail with LIMIT_EXCEEDED as soon as the received total passes the limit, and reads use ReadVersionBounded. serve -max-file-bytes takes the template's value (1 to executionenv.MaxFileBytes); passing it from the controller is Switch file and command operations to the executor server #2718.
  • Reads stream in 3 MiB chunks with the version on the last message only.
  • internal/executorrpc/fileconformance runs fsconformance.Run, RunNamespace, RunMutationAffinity and RunExternalMutationConflict over gRPC through a minimal test client: against memfs in the adapter tests and against osfs through the real serve wiring in cmd/mecatl-executor. The adapter tests don't import root osfs, so Move the contract and adapters into standalone modules #2716 stays a package move.

Issue relationship

Closes #2694

Stacked on #2832 (#2770); retarget to main once that merges.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

Baseline checks

  • Linting (task lint)
  • Fast offline test suite (task test): covered by task test:race
  • Pre-review race suite (task test:race)
  • Offline demo (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 #2718
  • Markdown changed: docs generation/link checks (task docs)
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check)
  • Intentional engine API change: task api:update + engine/CHANGELOG.md

Also run: go test -race -count=3 on ./internal/executorrpc/..., ./cmd/mecatl-executor/ and ./internal/executionexecutor/ in a golang:1.27.3 linux/arm64 container as uid 1000, and golangci-lint on the touched packages with GOOS=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 of tool.LedgerKey each fails it.

task check:pr fails only on buf breaking against main, from the streaming RPCs in #2832; it clears once #2832 merges.

Changes

File Change
internal/executorrpc/fileserver/server.go FileService adapter, limits, error mapping
internal/executorrpc/fileserver/locks.go Per-path lock table
internal/executorrpc/fileconformance/conformance.go fsconformance over gRPC, bufconn Dial, test client
cmd/mecatl-executor/serve.go Registers FileService on osfs; -max-file-bytes
.golangci.yml Deny message names the seam instead of only Runner

User-facing change

None.

Special notes for reviewers

  • Writes are buffered in memory, not spooled to disk. executor-protocol.md spools writes through a WorkspaceStreamer extension in engine/tool, which doesn't exist yet and is out of scope here (nothing under engine/ changes). Each upload is held in memory up to MaxFileBytes (at most 5 MiB per concurrent write) and committed with the whole-file CreateFile/ReplaceFile. Spooling is deferred until WorkspaceStreamer exists. A stream that fails or is cancelled before the caller closes it writes nothing.
  • The server lock overlaps osfs's. osfs already serializes writes per canonical path across the process, which is enough on its own in a long-lived serve process. 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.
  • CopyFile isn't bounded by MaxFileBytes, as in the one-shot executor today.
  • Per-service enable flags are left to Per-service enable flags #2696; serve still registers both services.

@blkt blkt self-assigned this Nov 17, 2026
@blkt
blkt added this pull request to stack #2854 November 17, 2026 21:45
@blkt
blkt marked this pull request as ready for review November 18, 2026 08:22
@blkt
blkt force-pushed the feat/2694-files-server branch from 78500ff to 1d10b1e Compare November 18, 2026 09:03

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Base automatically changed from feat/2770-chunked-file-transfer to main November 18, 2026 09:50
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.
@blkt
blkt force-pushed the feat/2694-files-server branch from 1d10b1e to 4a4fe8c Compare November 18, 2026 09:50
@blkt
blkt enabled stacked auto-merge (squash) November 18, 2026 09:53
@blkt
blkt merged commit c8cbdcf into main Nov 18, 2026
50 checks passed
@blkt
blkt deleted the feat/2694-files-server branch November 18, 2026 10:06
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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.

Files gRPC server

2 participants