Skip to content

fix(providers): send provider replies without a 40 ms delay - #13381

Merged
cv merged 2 commits into
v1from
fix/provider-tcp-nodelay
Oct 17, 2026
Merged

cv merged 2 commits into
v1from
fix/provider-tcp-nodelay

Conversation

@cv

@cv cv commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Failure

Every provider call from OpenTofu took about 40 ms, regardless of the work it did. tf-provider, which serves all our providers' gRPC, listens on TCP and never sets TCP_NODELAY on accepted connections. So each small reply waits on Nagle's algorithm and OpenTofu's delayed acknowledgment.

In the OpenShell contract tests, OpenTofu commands took 223 of 227 seconds: 140 applies at about 1.0 s and 120 plans at about 0.6 s. A trace of one apply shows 24 schema calls and other provider calls, each about 40 ms apart, while the provider's own schema work takes microseconds. Users pay this on every plan, apply, and destroy. The stall also pushed #13375's contract binaries over their CI test-duration budgets.

Decision

Vendor tf-provider at its pinned revision under crates/vendor/tf-provider, as openshell-sdk is, and set TCP_NODELAY on each accepted connection (without_delay in src/server.rs). The root manifest patches tf-provider to the copy.

NOTICE.md records the source revision, the omitted files, and the changes. The fix is also reported upstream in aneoconsulting/tf-provider#21; remove the copy once upstream sets TCP_NODELAY.

Validation

  • Regression test: the new test in the vendored crate (cargo test --manifest-path crates/vendor/tf-provider/Cargo.toml) failed against the unchanged behavior and passes with the fix. cargo ci doesn't run vendored crates' tests.
  • OpenShell contract tests, run serially: 227 s before, 86.7 s after.
  • cargo ci passes locally: 1543 unit tests and 152 lifecycle tests. The lifecycle step took 91 s, against 144 s for a comparable v1 run.

cv added 2 commits October 16, 2026 21:37
tf-provider serves each provider's gRPC over TCP without TCP_NODELAY, so
every reply waited on Nagle's algorithm and OpenTofu's delayed
acknowledgment: about 40 ms per provider call. Vendor tf-provider at its
pinned revision and set TCP_NODELAY on accepted connections. The
OpenShell contract tests drop from 227 s to 87 s run serially.
@cv
cv enabled auto-merge (squash) October 17, 2026 05:06
@cv
cv merged commit 1844e32 into v1 Oct 17, 2026
@cv
cv deleted the fix/provider-tcp-nodelay branch October 17, 2026 05:09
@github-actions

Copy link
Copy Markdown
Contributor

cv added a commit that referenced this pull request Oct 17, 2026
… reply delay (#13382)

## Failure

#13381 committed `crates/vendor/tf-provider/target/`: 1,908 files, about
574 MB of Cargo build output. `.gitignore` ignored only the root
`/target/`, and `NOTICE.md` tells contributors to run `cargo test
--manifest-path crates/vendor/tf-provider/Cargo.toml`, which creates
that directory and an untracked `Cargo.lock` beside it. Every fetch of
`v1` since then downloads the build output.

#13381 also left one 40 ms reply delay in the tests. The fake OpenShell
gateway in `crates/nemoclaw-test-fixtures/src/openshell.rs` serves
without `TCP_NODELAY`, so each reply to the provider waits on Nagle's
algorithm and the provider's delayed acknowledgment, the delay #13381
removed from `tf-provider`.

## Decision

- Delete `crates/vendor/tf-provider/target/`.
- Ignore `target/` at any depth, and
`/crates/vendor/tf-provider/Cargo.lock`, which `NOTICE.md` says the copy
omits.
- Set `TCP_NODELAY` on each connection the fake gateway accepts, as
`tf-provider` now does.
- Lower the provider contract budgets in `.config/test-budgets.yaml` and
the matching per-test timeouts in `.config/nextest.toml` to the measured
times plus margin.

This commit does not shrink the repository's history: the build output
stays in `1844e321f4`. Removing it would require rewriting `v1`.

## Validation

`openshell-provider` contract tests in an Ubuntu 24.04 arm64 VM (8 CPUs)
with the linux_arm64 CI bundle. That VM reproduced CI's per-test times
before either fix.

| Build | Serial | 4 threads |
|---|---|---|
| Before #13381 | 171 s | 43 s |
| `tf-provider` fix only (measured with the same patch) | 80 s | 19 s |
| This branch | 21.2 s | 7.0 s |

Also ran `cargo fmt --all --check`, Clippy for `nemoclaw-test-fixtures`,
and `cargo test --manifest-path crates/vendor/tf-provider/Cargo.toml`,
after which `git status` showed no untracked files.

Linux CI, this PR's first run (39015106152) against `v1` after #13381
(39005227268) and before it (#13378, attempt 3):

| Binary, summed | Before #13381 | After #13381 | This PR |
|---|---|---|---|
| `openshell-provider::contract`, amd64 / arm64 | 182.4 / 175.9 s |
106.7 / 88.0 s | 56.3 / 48.6 s |
| `nemoclaw-provider::contract`, amd64 / arm64 | 55.9 / 50.3 s | 31.8 /
22.4 s | 27.5 / 23.2 s |
| `fabric-provider::contract`, amd64 / arm64 | 34.3 / 36.7 s | 21.6 /
22.1 s | 13.5 / 14.4 s |

New budgets, summed / per test: `openshell-provider::contract` 80 / 6 s
(was 190 / 12), `nemoclaw-provider::contract` 45 / 8 s (was 110 / 10),
`fabric-provider::contract` 25 / 10 s (was 40 / 22). They rest on one
run per platform. `cargo test -p nemoclaw-build --test integration ci::`
checks that the budgets and nextest timeouts agree.
cv added a commit that referenced this pull request Oct 19, 2026
…13445)

## Failure

`kubernetes::connection::forward` relays local connections to a
Kubernetes gateway through a port-forward, but it doesn't set
`TCP_NODELAY` on the local connections it accepts. When a reply from the
cluster arrives in pieces, such as a gRPC response's frames, each piece
after the first waits for the client's delayed acknowledgment of the one
before. That's about 40 ms on Linux, the same delay #13381 and #13382
removed from provider and fake-gateway replies.

In an Ubuntu 24.04 arm64 VM, a fake gateway that answers each one-byte
request with two writes 1 ms apart took 44 ms per round trip through
`forward`, and 2.7 ms with `TCP_NODELAY`. I have not measured a real
port-forward to a cluster.

## Change

Set `TCP_NODELAY` on each local connection `forward` accepts. A
connection that refuses the option is still relayed.

## Validation

- New test
`forwarded_replies_arriving_in_pieces_reach_the_client_promptly` in
`crates/nemoclaw-sdk/tests/kubernetes_connection.rs` requires a median
round trip under 20 ms. In the Linux VM it failed before the change
(41.9 ms) and passed three times after it. macOS doesn't show the delay,
so the test passes there either way.
- `cargo test -p nemoclaw-sdk --test integration kubernetes`: 136 passed
on Linux (VM) and macOS.
- `cargo fmt --all --check` and Clippy for `nemoclaw-sdk`.

## Checked and left unchanged

These were also missing `TCP_NODELAY`; the same VM showed no delay, so
this PR doesn't touch them:

- **Ollama proxy** (`crates/nemoclaw-ollama-proxy`): streamed chunks
arrived 0.1 ms after the daemon wrote them, with and without the option,
at 10, 2 and 1 ms between chunks.
- **Shared HTTP test fixture** (`crates/test-support/http.rs`): it
closes each connection right after replying, which sends the held body.
The 135 SDK Kubernetes tests took 4.4–4.9 s before and 4.9–5.5 s after.

Not measured: kube's client connects with hyper-util's
`HttpConnector::new()`, which leaves `TCP_NODELAY` off on our
connections to the Kubernetes API server.
@wscurran wscurran added area: networking DNS, proxy, TLS, ports, host aliases, or connectivity area: performance Latency, throughput, resource use, benchmarks, or scaling bug-fix PR fixes a bug or regression v1 NemoClaw v1 branch labels Oct 23, 2026
@cv cv added this to the Roadmap: GTC DC 2026 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: networking DNS, proxy, TLS, ports, host aliases, or connectivity area: performance Latency, throughput, resource use, benchmarks, or scaling bug-fix PR fixes a bug or regression v1 NemoClaw v1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants