Skip to content

feat(executorrpc): add a Files and Commands client for the agent loop - #2863

Merged
blkt merged 4 commits into
mainfrom
feat/2710-files-commands-client
Nov 19, 2026
Merged

blkt merged 4 commits into
mainfrom
feat/2710-files-commands-client

Conversation

@blkt

@blkt blkt commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds internal/executorrpc/executorclient, a client of the executor FileService and CommandService that implements tool.Workspace, tool.WorkspaceNamespace, tool.AuthorityResourceResolver, and a foreground tool.CommandRunner. It works against the trusted service or a local executor, so the agent loop can use one client for both.

  • Each call gets its full RequestContext from a per-call RequestContextFunc and sends it in the opaque context field (the first message on streams). A nil func sends an empty context, which an executor ignores. No methods were added to Workspace, CommandRunner, or CommandStreamer.
  • Nothing is retried. executorclient.Dial always sets grpc.WithDisableRetry, and a command is sent on exactly one stream. A stream that breaks after the start confirmation, or an OUTCOME_UNKNOWN result, returns the host-side executorclient.ErrOutcomeUnknown. When the caller's context ends, the client sends a cancel and waits up to 30s for the result.
  • Before Started, the client reports "did not start" only for a refusal the executor tagged: InvalidArgument, LIMIT_EXCEEDED, NO_SHELL, or the new START_FAILED. Any other error, including transport errors that gRPC maps to Internal, returns ErrOutcomeUnknown. On the executor side, the command supervisor now reports a start whose handshake with its helper fails after the command was sent as commandserver.ErrStartUnknown (an untagged Unknown status), instead of "did not start".
  • Against a misbehaving executor, a file read over WithMaxFileBytes fails with ErrLimitExceeded, and command output is capped by WithMaxOutputBytes (both 256 MiB by default). Truncated output, whether clipped by the client or flagged with output_truncated by the executor, ends with ... [output truncated], on stderr when stdout is empty.
  • fileconformance drops its own minimal Workspace and runs the conformance suites through this client, so fileserver, memexecutor, and mecatl-executor serve are all checked through it. Target.Client becomes Target.Conn.
  • executionclient.NewTemplateProvider gains an opt-in WithExecutorServices(), which builds the run environment's workspace and runner from the new client on the existing pinned mTLS connection, converting the run claim into the RequestContext on every call. It is off by default, and cmd/mecak8s does not set it. The remote workspace conformance and file-tool tests in executionclient run over both transports.

Issue relationship

Closes #2710

The new client is a target of files_conformance_test.go alongside the current transport. Making it the only transport, dropping the ExecutionProviderService target, and the demo going through it are criteria of the transport switch (#2718), since mecatl-execution-provider does not serve FileService or CommandService yet.

Type of change

  • New feature

Test plan

Baseline checks

  • Linting (task lint)
  • Pre-review race suite (task test:race)
  • Offline demo (go run ./cmd/mecademo): tool call, permission ask and approval, result. The demo runs on local memfs and does not use the new client.
  • task check:pr

Focused tests:

  • TestDroppedConnectionDuringCommandIsUnknownAndNotRetried drops the connection mid-command and checks for ErrOutcomeUnknown with one script start over one stream.
  • TestExecutorServicesCarryTheRunClaim checks the claim fields reach the server.
  • TestFailureBeforeStartedIsUnknownUnlessRefused, TestOutputIsCappedAndTruncationReported, and TestReadOverClientLimitFails cover the start classification and the client caps; TestStartFailures checks commandserver tags each refusal, and TestStartFailuresAreTaggedOnlyWhenNothingRan (Linux) checks the supervisor's no-shell, failed-exec, and vanished-helper cases.
  • The FileService conformance suites run the same 130 subtests as on main, now through the client.

Changes

File Change
internal/executorrpc/executorclient/ New client: Workspace, Runner, Dial, ErrOutcomeUnknown, ErrLimitExceeded, size options
contracts/proto/mecatl/executor/v1/errors.proto ERROR_REASON_START_FAILED
internal/executorrpc/commandserver/server.go Tags a failed process start with START_FAILED; ErrStartUnknown for a start that may have run
internal/executionexecutor/supervisor_linux.go Helper reports failed; other handshake failures are ErrStartUnknown
internal/executorrpc/fileconformance/conformance.go Uses the client instead of its own Workspace; Target.Conn
internal/adapter/executionclient/client.go Opt-in WithExecutorServices(), runContext.executorContext
internal/adapter/executionclient/files_conformance_test.go Conformance and file-tool tests over both transports
internal/executorrpc/fileserver, memexecutor, cmd/mecatl-executor tests Follow the Target.Conn change

User-facing change

None. The new path is off by default.

API compatibility

  • Assessment: additive. ErrorReason gains ERROR_REASON_START_FAILED = 9, which commandserver now attaches to its existing Internal "command did not start" status; the code and message are unchanged. A start that may have run now returns Unknown instead of Internal. A client that does not know the value sees an unrecognized enum in the detail and behaves as before. Nothing outside this repo consumes mecatl.executor.v1 yet. executionclient keeps calling ExecutionProviderService unless WithExecutorServices() is set, and no binary sets it.
  • Major/feature changes: feature (new enum value).
  • Upgrade implications: none for this PR. Turning the option on is the mecak8s and trusted-service break already accepted for Switch file and command operations to the executor server #2718.
  • Go source: fileconformance.Target.Client becomes Target.Conn, and fileconformance.Dial returns a *grpc.ClientConn. Both are internal test helpers whose in-repo callers are updated.

Special notes for reviewers

These need settling before #2718 turns the option on:

  • The old workspace refreshed the lease and retried read-only calls once after a definitive auth denial. The new path only reads the current claim, because the proxy's denial code is not defined yet.
  • The old workspace held opMu because the provider allows one active operation. The new client sends calls concurrently, which assumes the proxy accepts concurrent calls.

Add `internal/executorrpc/executorclient`, which implements
`tool.Workspace`, `tool.WorkspaceNamespace`,
`tool.AuthorityResourceResolver`, and a foreground `tool.CommandRunner`
over the executor `FileService` and `CommandService`. It works against
the trusted service or a local executor, and imports only `engine`, the
generated executor contract, and gRPC.

Each call builds its full `RequestContext` through a per-call function
and sends it in the opaque context. Calls are sent once, and `Dial`
always disables gRPC retries. A command stream that fails after the
start confirmation, or a result of `COMMAND_STATE_OUTCOME_UNKNOWN`,
returns `ErrOutcomeUnknown` and is never retried; ending the caller's
context sends a cancel and still waits for the result.

`fileconformance` drops its own minimal `Workspace` and runs the
`FileService` conformance suites through this client, so `fileserver`,
`memexecutor`, and `mecatl-executor serve` are all checked through it.

`executionclient.NewTemplateProvider` gains `WithExecutorServices`,
which serves run environments through the new client on the same pinned
mTLS connection. It stays off until the provider proxies these
services in the transport switch. The remote workspace conformance and
file-tool tests now run over both transports.

Refs: #2710

@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 as an off-by-default step. Retries are disabled in a way callers can't override, the command is sent on exactly one stream, the authority path is checked against the root, and the read protocol checks (data after version, no version) are good. Running fileconformance through this client is a nice way to cover the server and the client together.

Two things I'd want settled before #2718 turns WithExecutorServices() on (inline). Neither blocks this PR.

started := false
for {
msg, err := stream.Recv()
if err != nil && !started {

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.

On the "did not start" window you flagged in the description: I think the client can already tell these apart. Every refusal that commandserver makes before runner.Start returns a handler status (validation errors, NO_SHELL with FailedPrecondition, Internal "command did not start"). The window you're worried about, where the process starts and then sending Started fails, can only show up on the client as a transport-level code: Unavailable, Canceled, DeadlineExceeded, or Unknown.

So before started, treating those transport codes as ErrOutcomeUnknown and only the rest as notStarted would close the gap. "Did not start" reads to the model as safe to retry, and a non-idempotent command (a git push, a migration) could then run twice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be addressed, could you have a look?

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.

Looks good. A failure before Started now counts as "not started" only when the executor tagged it as a refusal (validation, LIMIT_EXCEEDED, NO_SHELL, the new START_FAILED); anything else is ErrOutcomeUnknown. Requiring an explicit Started event instead of any first message, and the supervisor's failed vs. handshake timeout split, close the server side of it too. Thanks.

if version != nil {
return nil, tool.FileVersion{}, fmt.Errorf("%w: data after version", errProtocol)
}
data = append(data, msg.GetData()...)

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.

The client trusts the server to bound the read: data grows for as long as chunks arrive. The same applies to stdout/stderr in receive. When this talks directly to an executor, that server sits in the workload Pod, which is the less trusted side. A cap on the client side at the max file size (and at the max output size for commands) would keep a misbehaving or compromised executor from growing memory in the agent loop. It's a cheap check, and it makes the client stand on its own instead of relying on the server's limits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be addressed, could you have a look?

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.

The mechanism looks right: reads fail with ErrLimitExceeded before appending, and command output is truncated with a marker. One follow-up before #2718 turns this on: the only production caller (executionclient/client.go NewWorkspace/NewRunner) passes no options, so the effective cap is the 256 MiB default, about 50x the 5 MiB the server enforces. Since the client now sends calls concurrently, that's 256 MiB per call. Passing WithMaxFileBytes/WithMaxOutputBytes from the template's limits (or executionenv.MaxFileBytes) there would make the cap meaningful. Not blocking.

blkt added 3 commits November 18, 2026 19:28
Address review on the executor client:

- A failure before `Started` is outcome unknown unless the server
  reported a refusal. Transport codes (`Unavailable`, `Canceled`,
  `DeadlineExceeded`, `Unknown`) and a clean end can follow a process
  that started, so they no longer read as "did not start", which the
  model treats as safe to retry. Only `Started` counts as the start
  confirmation; output before it is a protocol violation.
- `Workspace` fails a read over `WithMaxFileBytes` with
  `ErrLimitExceeded`, and `Runner` keeps at most `WithMaxOutputBytes`
  of combined output, still reading until the result so the outcome
  stays known. Both default to 256 MiB, a ceiling against a misbehaving
  executor above the servers' own limits.
- Output clipped by the client, or flagged `output_truncated` by the
  server, ends with a truncation marker.

Refs: #2710
gRPC maps transport failures such as RST_STREAM to `codes.Internal`,
the code `commandserver` used for "command did not start", so a
dropped stream before `Started` could report a command that ran as
never started.

Add `ERROR_REASON_START_FAILED` and send it with that refusal. Before
`Started` the client now reports "did not start" only for
`InvalidArgument`, `LIMIT_EXCEEDED`, `NO_SHELL`, and `START_FAILED`;
anything else is `ErrOutcomeUnknown`.

The truncation marker no longer names the executor, since the client
cap can clip too, and goes on stderr when stdout is empty.
The supervisor wrote the command to its helper and then treated a
status read timeout, read error, or garbled line as "command did not
start", although the helper may already have started the shell. With
`ERROR_REASON_START_FAILED`, that became a tagged refusal the client
trusts as never ran.

The helper now writes "failed" when the shell never started. Any other
handshake failure after the command is sent returns
`commandserver.ErrStartUnknown`, which `commandserver` sends as an
untagged `Unknown` status, so the client reports `ErrOutcomeUnknown`.

@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.

Re-approving on the fix commits. Start-failure classification is now correct on both ends, and the client has its own response bounds. One non-blocking follow-up on the default cap is in the workspace.go thread.

@blkt
blkt enabled auto-merge (squash) November 19, 2026 10:25
@blkt
blkt merged commit 0cfe848 into main Nov 19, 2026
48 checks passed
@blkt
blkt deleted the feat/2710-files-commands-client branch November 19, 2026 10:44
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.

Client for Files and Commands

2 participants