Commit d34dab5
fix(inference): validate every runtime adapter port through one shared path (#9545)
## Summary
The Bedrock Runtime adapter was the only one of the three local runtime
adapters that never
validated its configured host port, so
`NEMOCLAW_BEDROCK_RUNTIME_ADAPTER_PORT` could place it on
the Ollama inference port, the Ollama auth proxy port, a port inside the
dashboard allocation
range, or any other configured service port. Its two siblings reject all
of those before spawning
anything. After this change all three adapters reject the same
collisions and produce the same
named errors.
## Related Issue
Fixes #9544
## Changes
`src/lib/core/ports.ts`
- Deleted `validateBedrockRuntimeAdapterPort`,
`validateOpenRouterRuntimeAdapterPort` and
`validateHttpsPinRuntimeAdapterPort`.
- Added one `CURRENT_RUNTIME_PORT_CONFIGURATION` next to the catalog,
and
`validateRuntimeAdapterPort(ownerEnvVar, port, options =
CURRENT_RUNTIME_PORT_CONFIGURATION)`, which
calls `validateServicePort(ownerEnvVar, port, options, ownerEnvVar)`.
- `validateLlamaCppPortReservation`'s bottom call now takes that same
object instead of rebuilding the
ten fields a second time.
`src/lib/inference/bedrock-runtime-adapter.ts`,
`openrouter-runtime-adapter-lifecycle.ts`,
`https-pin-runtime-adapter.ts`
- Deleted all three `validateAdapterPortConfiguration()` helpers and the
eight now-dead port imports in
each of the two sibling files.
- Each ensure path opens with a direct `validateRuntimeAdapterPort("<its
own env var>", <its own port>)`.
`src/lib/core/ports.test.ts`
- The three near-identical describes collapse into one
`validateRuntimeAdapterPort` describe: an
`ADAPTER_OWNERS` table of the three owner/default/label triples, a
`SHARED_CONFLICTS` table, and a
generated matrix crossing each owner against the shared conflicts *and*
the other two adapters'
defaults. Same assertions as before, one copy. Plus one case proving the
no-options overload
validates against the live configuration.
`src/lib/inference/runtime-adapter-port-collisions.test.ts`
- Added in `f1f589858` by @prekshivyas. It covers all three public
ensure paths symmetrically, so it
answers the boundary-test request without reintroducing the per-adapter
asymmetry that a
Bedrock-only ensure test would have created. Each case asserts the named
validation error and that
no adapter process is spawned and no pid, token, or state file is
written.
Production is net **+42 / −94 = −52 lines** and is unchanged by the
follow-up commit. Including the
new boundary-test file, the complete PR is **+191 / −141 = +50 lines**
across the repo. An earlier
revision of this description quoted the repo-wide figure from before
that file existed.
## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)
## Quality Gates
- [x] Tests added or updated for changed behavior
- [ ] Existing tests cover changed behavior — justification:
- [ ] Tests not applicable — justification:
- [x] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [ ] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification:
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:
## Verification
- [x] PR description includes a `Signed-off-by:` line and every commit
appears as `Verified` in GitHub
- [x] Normal `pre-commit`, `commit-msg`, and `pre-push` hooks passed, or
`npm run validate:pr` passed after refreshing `origin/main` when hooks
were skipped or unavailable
- [x] Targeted behavior tests pass for the current change set, or tests
are marked not applicable above — command/result or justification:
`npx vitest run --project cli src/lib/core/ports.test.ts
src/lib/inference/bedrock-runtime-adapter.test.ts` — 73 passed (73).
Without the change the nine new cases fail; with it they pass.
`npm run validate:pr` passed, including `Codebase growth guardrails` and
`TypeScript (CLI)`.
- [ ] Applicable broad gate passed — `npm test` for broad
runtime/test-harness changes; `npm run check` for repo-wide
validation/coverage changes — command/result:
- [x] Quality Gates section completed with required justifications or
waivers
- [x] No secrets, API keys, or credentials committed
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)
---
**Note on overlap with #9537:** #9537 restructures the same file and
converges on the same shape — it rewrites
`validateLlamaCppPortReservation` into a direct
`validateServicePort(...)` call. This revision no longer merges cleanly
with it: exactly one file and one region conflict, the doc comment above
`validateLlamaCppPortReservation`. I resolved it in a scratch worktree
and the port tests still pass there. Happy to rebase on #9537 the moment
it lands, or to reorder if you would rather take this one first.
Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved port validation for Bedrock, OpenRouter, and HTTPS pin
runtime adapters.
* Prevented runtime adapters from using ports reserved by other services
or adapters.
* Added safeguards against overlapping and conflicting port assignments.
* Ensured adapter startup checks reflect the current service
configuration.
* Prevented conflicting adapters from starting or creating incomplete
runtime state.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>
Signed-off-by: Julie Yaunches <jyaunches@nvidia.com>
Co-authored-by: Prekshi Vyas <prekshiv@nvidia.com>
Co-authored-by: Julie Yaunches <jyaunches@nvidia.com>1 parent 722ff55 commit d34dab5
6 files changed
Lines changed: 191 additions & 141 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | | - | |
| 10 | + | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
181 | 180 | | |
182 | 181 | | |
183 | 182 | | |
184 | | - | |
185 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
186 | 189 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 190 | + | |
194 | 191 | | |
195 | 192 | | |
196 | 193 | | |
197 | 194 | | |
198 | | - | |
199 | | - | |
200 | 195 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 196 | + | |
206 | 197 | | |
207 | | - | |
| 198 | + | |
208 | 199 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 200 | + | |
223 | 201 | | |
224 | 202 | | |
225 | 203 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
238 | 217 | | |
239 | 218 | | |
240 | | - | |
| 219 | + | |
241 | 220 | | |
242 | | - | |
| 221 | + | |
243 | 222 | | |
244 | 223 | | |
245 | 224 | | |
246 | 225 | | |
247 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
248 | 233 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | 236 | | |
252 | 237 | | |
253 | 238 | | |
| |||
261 | 246 | | |
262 | 247 | | |
263 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
264 | 278 | | |
265 | 279 | | |
266 | 280 | | |
| |||
275 | 289 | | |
276 | 290 | | |
277 | 291 | | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
| 292 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| 382 | + | |
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 45 | + | |
58 | 46 | | |
59 | 47 | | |
60 | 48 | | |
| |||
1467 | 1455 | | |
1468 | 1456 | | |
1469 | 1457 | | |
1470 | | - | |
1471 | | - | |
1472 | | - | |
1473 | | - | |
1474 | | - | |
1475 | | - | |
1476 | | - | |
1477 | | - | |
1478 | | - | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
1482 | | - | |
1483 | | - | |
1484 | | - | |
1485 | | - | |
1486 | | - | |
1487 | | - | |
1488 | | - | |
1489 | 1458 | | |
1490 | 1459 | | |
1491 | 1460 | | |
| |||
1523 | 1492 | | |
1524 | 1493 | | |
1525 | 1494 | | |
1526 | | - | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1527 | 1499 | | |
1528 | 1500 | | |
1529 | 1501 | | |
| |||
Lines changed: 5 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 8 | + | |
21 | 9 | | |
22 | 10 | | |
23 | 11 | | |
| |||
209 | 197 | | |
210 | 198 | | |
211 | 199 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | 200 | | |
232 | 201 | | |
233 | 202 | | |
| |||
247 | 216 | | |
248 | 217 | | |
249 | 218 | | |
250 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
251 | 223 | | |
252 | 224 | | |
253 | 225 | | |
| |||
0 commit comments