NemoClaw icon indicating copy to clipboard operation
NemoClaw copied to clipboard

bug(messaging): forward-list failure is reclassified as no entry during cleanup

Open ericksoa opened this issue 3 months ago • 2 comments

Summary

The messaging fixed-forward cleanup adapter violates the fail-closed contract of bestEffortForwardStopForSandbox.

When openshell forward list fails, the messaging capture adapter returns null. ensureAgentFixedForward converts that null to "", so the shared cleanup helper parses it as a successful empty list, returns "no-entry", and attempts a sandbox-scoped forward stop.

This was found by tracing the adapter contract on current main at c11f455582556d49bd31cb8dfda3588221ff60e6. It is a code-proven latent defect; a live runtime reproduction has not yet been captured.

Why this is a bug

The shared helper deliberately distinguishes these outcomes:

  • "list-failed": ownership is unknown, so skip the stop.
  • "no-entry": enumeration succeeded and found no live entry, so a sandbox-scoped defensive stop is allowed.

That contract is documented and implemented in forward-cleanup.ts.

The dashboard adapter preserves it by throwing when its nullable capture returns null (dashboard-forward-control.ts). The messaging fixed-forward adapter instead erases the failure:

https://github.com/NVIDIA/NemoClaw/blob/c11f455582556d49bd31cb8dfda3588221ff60e6/src/lib/onboard/agent-fixed-forward.ts#L29-L35

(args, opts) => (deps.runCaptureOpenshell(args, opts) ?? "") as string

The concrete messaging capture returns null for any non-zero OpenShell result and supplies that function to ensureAgentFixedForward:

Trigger

The messaging host-forward recovery path is entered after a rebuild, and openshell forward list returns a non-zero status—for example while the gateway is unavailable, the connection is refused, or the probe times out.

The failure then follows this path:

captureOpenShellOutput -> null
ensureAgentFixedForward -> null ?? "" -> ""
bestEffortForwardStopForSandbox -> empty ownership map
result -> "no-entry"
forward stop <port> <sandbox> is attempted

The stop is sandbox-scoped, which limits cross-sandbox blast radius, but it still mutates forward state precisely when the helper's stated policy is to fail closed because ownership could not be established.

Expected behavior

A failed or timed-out forward-list operation must produce "list-failed" and must not invoke forward stop.

A genuinely successful empty list may continue to produce "no-entry" and run the sandbox-scoped defensive stop.

Suggested design

Recommended: make failure representation explicit at the shared boundary instead of relying on every adapter to remember to throw.

  1. Change ForwardListRunner to return string | null.
  2. In bestEffortForwardStopForSandbox, classify both a thrown exception and null as "list-failed" before parsing.
  3. Remove the ?? "" coercion from the stop adapter in agent-fixed-forward.ts.
  4. Keep start-polling semantics separate: converting null to empty output may be acceptable while polling for a newly started forward, but it is not acceptable for an ownership-sensitive stop decision.
  5. Add a regression test proving that a nullable capture failure causes no runOpenshell stop call, plus a control test proving that a successful "" result still follows "no-entry".

A narrower patch that makes the agent-fixed-forward.ts stop adapter throw on null, matching dashboard-forward-control.ts, is also valid. Centralizing the classification is preferable because it makes the safety contract harder for future adapters to violate.

Help wanted

A contributor familiar with the OpenShell forward lifecycle is needed to:

  • confirm that null is the intended non-zero/timeout signal for the messaging capture seam;
  • audit other bestEffortForwardStopForSandbox adapters for failure-to-empty coercions;
  • implement the shared-boundary normalization (or the narrow adapter fix);
  • add the focused regression coverage described above.

No device-specific environment should be required; the defect can be reproduced with injected runners in a unit test.

ericksoa avatar Aug 07 '26 04:08 ericksoa

I'd like to pick this up, if no one else has started.

I reproduced the reasoning against main and can confirm the defect. A couple of findings that may be useful before scope is settled.

Adapter audit. There are three call sites of bestEffortForwardStopForSandbox, and only one violates the contract:

Call site List-failure handling
src/lib/onboard/dashboard-forward-control.ts:33 throws on null — correct
src/lib/tunnel/agent-forward-stop.ts:96 throws on non-zero status — correct
src/lib/onboard/agent-fixed-forward.ts:30 ?? "" coercion — the bug

So the "adapters throw on failure" convention already holds at two of three sites, and this one is the outlier.

One correction to the trigger list. The description includes probe timeout as a trigger. On this path I don't think it reaches the coercion. captureOpenShellOutput calls captureOpenshell without ignoreError, so an ETIMEDOUT falls through isIgnoredCaptureError into handleSpawnError, which exits the process (src/lib/adapters/openshell/client.ts:133-149). The reachable trigger looks like non-zero exit status only — gateway unavailable, connection refused. That doesn't change the fix, but it does change what the regression test should inject, so I wanted to flag it rather than write a test around a path that can't run.

Scope question. The description offers two options and prefers centralizing. I'd lean toward the narrow adapter fix, and I want to check that before writing code rather than after:

  • Widening ForwardListRunner to string | null touches the shared type, the helper, and all three adapters in order to correct one line at one site.
  • The convention it would replace is already documented in the helper's comment block and already followed by the other two adapters.
  • The start-polling runner in the same file (agent-fixed-forward.ts:42-44) keeps its ?? "", per point 4 in the description, so the wider change wouldn't make that file uniformly non-nullable anyway.

If maintainers would rather have the shared-boundary normalization so future adapters can't reintroduce this, I'm happy to do that instead — I just don't want to pick the larger change unilaterally.

Planned work, either way:

  1. Make the stop adapter in agent-fixed-forward.ts surface list failure instead of coercing it, matching dashboard-forward-control.ts.
  2. Leave the start-poll coercion unchanged.
  3. Regression test: an injected capture returning null produces "list-failed" and issues no runOpenshell stop call.
  4. Control test: a successful "" result still produces "no-entry" and still issues the sandbox-scoped stop.

Both tests use injected runners, so no OpenShell environment is needed.

One note on severity, in case it affects prioritization: the blast radius here looks narrow. The stop is sandbox-scoped, so it cannot reach another sandbox's forward, and it sits immediately before a deliberate restart on the same port. The practical cost is that the documented fail-closed guarantee is not actually enforced on this path, and that messaging loses the "could not enumerate forwards" diagnostic that agent-forward-stop.ts emits in the same situation. I'd still like to fix it, but I don't want to overstate it as a user-facing failure.

Let me know on the scope question and I'll open a PR.

sdshah09 avatar Aug 07 '26 04:08 sdshah09

I’m taking the shared-boundary fix described here: nullable forward-list results will remain failures at the ownership-sensitive cleanup boundary, with regression coverage for both null failure and successful empty output.

aryansk avatar Aug 07 '26 04:08 aryansk