Skip to content

refactor(onboard): extract gateway lifecycle ownership - #9178

Merged
prekshivyas merged 1 commit into
mainfrom
codex/7695-gateway-composition
Aug 14, 2026
Merged

refactor(onboard): extract gateway lifecycle ownership#9178
prekshivyas merged 1 commit into
mainfrom
codex/7695-gateway-composition

Conversation

@cv

@cv cv commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Move onboarding gateway lifecycle decisions from src/lib/onboard.ts into focused gateway application modules. Add a ratcheted entry-boundary check so gateway decisions cannot return and later phase work must decrease its recorded allowances.

Related Issue

Fixes #9171

Advances #9172. Provider, messaging, and policy allowances remain assigned to #9169, #9170, and #9172.

Changes

  • Move process cleanup, registration, Docker-driver start, provider-aware start, and recovery into src/lib/onboard/gateway/.
  • Keep src/lib/onboard.ts responsible for sequencing and dependency wiring. Its line count decreases from 4,274 to 3,902, and fan-out decreases from 210 to 202.
  • Add a repository check that records decision occurrences by category and declaration. The check rejects increases and requires budget decreases.
  • Record zero gateway allowances. Record current messaging, policy, and provider allowances for their assigned follow-up issues.
  • Add late-binding tests for gateway name and port changes. Add process identity and entry-boundary regression tests.

The focused modules are required by #9171. A direct move into one facade kept the original coupling, so the lifecycle is split by current responsibility. The focused tests and the architecture check protect these contracts.

Type of Change

  • 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

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: Internal ownership and contributor checks change. Commands, configuration, defaults, guidance, and runtime behavior do not change.
  • 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: An independent Codex review found no remaining findings after the lazy-binding, lifecycle-authority, process-identity, and ratchet fixes.
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Documentation Writer Review

DGX Station Hardware Evidence

  • Tested on DGX Station
  • Tested commit:
  • Station profile/scenario:
  • Result:
  • Supporting evidence:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • 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
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result or justification: npm run test:changed passed 1,271 tests in 107 files. Focused gateway, onboarding, and architecture suites passed 154 tests.
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result:
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Carlos Villela cvillela@nvidia.com

@cv cv added refactor PR restructures code without intended behavior change area: onboarding Onboarding FSM, provider setup, sandbox launch, or first-run flow area: architecture Architecture, design debt, major refactors, or maintainability labels Aug 14, 2026
@cv cv self-assigned this Aug 14, 2026
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@cv, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: aeb9301f-0d6b-4f27-900c-5de02861c62a

📥 Commits

Reviewing files that changed from the base of the PR and between e271504 and 625971a.

📒 Files selected for processing (16)
  • ci/onboard-entry-composition-budget.json
  • ci/source-architecture-budget.json
  • scripts/checks/onboard-entry-composition.mts
  • scripts/checks/run.mts
  • src/lib/onboard.ts
  • src/lib/onboard/gateway/application.ts
  • src/lib/onboard/gateway/docker-driver-start.ts
  • src/lib/onboard/gateway/entry-decisions.ts
  • src/lib/onboard/gateway/late-binding.test.ts
  • src/lib/onboard/gateway/process-lifecycle.test.ts
  • src/lib/onboard/gateway/process-lifecycle.ts
  • src/lib/onboard/gateway/recovery.ts
  • src/lib/onboard/gateway/registration.ts
  • src/lib/onboard/gateway/start.ts
  • test/checks-runner.test.ts
  • test/onboard-entry-composition.test.ts

Comment @coderabbitai help to get the list of available commands.

@github-code-quality

github-code-quality Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in commit 625971a in the codex/7695-gateway-c... branch remains at 96%, unchanged from commit d01ba9d in the main branch.

TypeScript / code-coverage/cli

The overall coverage in commit 625971a in the codex/7695-gateway-c... branch remains at 82%, unchanged from commit 93461f3 in the main branch.

Show a code coverage summary of the most impacted files.
File main 93461f3 codex/7695-gateway-c... 625971a +/-
src/lib/onboard...reachability.ts 90% 80% -10%
src/lib/cua/run...ime-manifest.ts 84% 90% +6%
src/lib/inferen...file/cleanup.ts 78% 85% +7%
src/lib/onboard.ts 35% 43% +8%
src/lib/readine...y-production.ts 66% 77% +11%
src/lib/onboard...driver-start.ts 0% 38% +38%
src/lib/inferen...ycle-adapter.ts 0% 77% +77%
src/lib/onboard...ce-lifecycle.ts 0% 89% +89%
src/lib/state/r...al-inference.ts 0% 92% +92%
src/lib/gateway...art-guidance.ts 0% 95% +95%

Updated August 14, 2026 19:59 UTC

Comment thread src/lib/onboard.ts
removeDockerDriverGatewayRegistration,
retireLegacyGatewayForDockerDriverUpgrade,
runQuietOpenshell,
stopDockerDriverGatewayProcess,
Comment thread src/lib/onboard.ts
});

const {
attachGatewayMetadataIfNeeded,
Comment thread src/lib/onboard.ts
const {
attachGatewayMetadataIfNeeded,
recoverGatewayRuntime,
registerDockerDriverGatewayEndpoint,
Comment thread src/lib/onboard.ts
startDockerDriverGateway,
startGateway,
startGatewayForRecovery,
startGatewayWithOptions,
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — No blocking findings reported

Advisor assessment: No blocking advisor findings reported
Next action: Review the warnings below.
Findings: 0 blockers · 1 warning · 0 suggestions

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 1 warning · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings differ; normalized terminology decisions differ; normalized E2E selections differ; Nemotron reported the same number of blockers, 1 fewer warning, the same number of suggestions.
4 terminology differences from the second opinion

Advisory only. These are normalized differences from the primary terminology receipt.

  • decision ratchet at scripts/checks/onboard-entry-composition.mts:15: selected only by the second-opinion lane as define.
  • entry decisions at src/lib/onboard.ts:513: selected only by the second-opinion lane as established.
  • onboarding entry composition at scripts/checks/onboard-entry-composition.mts:312: selected only by the second-opinion lane as established.
  • new-decision at scripts/checks/onboard-entry-composition.mts:15: selected only by the second-opinion lane as define.
3 additional E2E selections from the second opinion

Advisory only. The primary lane did not select these E2E jobs or targets.

  • double-onboard: The completed second-opinion lane identified E2E coverage that the primary lane omitted.
  • gpu-double-onboard: The completed second-opinion lane identified E2E coverage that the primary lane omitted.
  • concurrent-gateway-ports: The completed second-opinion lane identified E2E coverage that the primary lane omitted.

Second-opinion terminology and E2E selections are advisory. Live E2E does not run automatically for pull requests.

3 semantic terminology decisions

Terminology decisions are advisory. They affect the assessment only when a separate finding identifies concrete semantic impact.

  • define — onboarding entry composition boundary at scripts/checks/onboard-entry-composition.mts:312: Define the term near its first contributor-facing output. State the measured source and the decision categories.
  • justified — late binding at src/lib/onboard/gateway/late-binding.test.ts:12: Keep the modifier. The test establishes the needed contrast by changing the binding before registration and startup.
  • established — Docker-driver gateway at src/lib/onboard/gateway/docker-driver-start.ts:184: Keep the established term and capitalization.

E2E guidance

Advisory only. A maintainer can dispatch the default E2E suite for the commit under review.

Recommended E2E: managed-image-protected-runtime

Manual-only E2E: managed-image-multiarch-startup, onboard-repair, onboard-resume, cloud-onboard
The manual PR workflow does not run these selectors for the commit under review. Run them from reviewed code on main.

1 optional E2E recommendation
  • gateway-guard-recovery
1 warning · 0 suggestions

Warnings

Warnings do not block.

PRA-1 Warning — Cover standalone Docker-driver startup failure

  • Location: src/lib/onboard/gateway/docker-driver-start.ts:192
  • Category: tests
  • Problem: The test suite does not exercise the extracted `cutover === "launch"` path in `startDockerDriverGateway`. That path has distinct child-process, runtime-marker, readiness, bridge-reachability, and failure-reporting behavior.
  • Impact: A refactor error in standalone startup failure handling can leave the Docker-driver gateway path without a focused regression test. Callers may receive changed failure behavior after a child exits or readiness times out.
  • Recommendation: Add a focused test for the extracted standalone launch failure branch. Keep the package-managed fallback test, but cover the child-process readiness failure path separately.
  • Verification: Inspect late-binding.test.ts and confirm that its package-managed fallback returns before the standalone launch code at docker-driver-start.ts:192-258.
  • Test coverage: Add a focused `createDockerDriverGatewayStart` test that makes cutover return `launch`, then simulates an exited or unhealthy startup result and asserts that failure reporting occurs and the healthy-success path does not run.
  • Simplification (native): Remove Do not add an E2E suite for this branch.; use Use the existing dependency-injected `createDockerDriverGatewayStart` factory to test the launch failure branch.. Net: 0 lines.
  • Keep: Runtime E2E jobs remain required for Docker and sandbox behavior; this unit test only proves the extracted branch wiring.
  • Evidence: src/lib/onboard/gateway/docker-driver-start.ts:192-258 implements the standalone launch path after `cutover === "launch"`. src/lib/onboard/gateway/late-binding.test.ts:91-158 configures `startPackageManagedDockerDriverGatewayWithEnvOverride`, so its test returns from the managed fallback instead of entering the standalone launch path. src/lib/onboard/gateway/docker-driver-start.ts:248-257 reports startup failure when readiness is not healthy.

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

Comment thread src/lib/onboard.ts
removeDockerDriverGatewayRegistration,
retireLegacyGatewayForDockerDriverUpgrade,
runQuietOpenshell,
stopDockerDriverGatewayProcess,
Comment thread src/lib/onboard.ts
});

const {
attachGatewayMetadataIfNeeded,
Comment thread src/lib/onboard.ts
const {
attachGatewayMetadataIfNeeded,
recoverGatewayRuntime,
registerDockerDriverGatewayEndpoint,
Comment thread src/lib/onboard.ts
startDockerDriverGateway,
startGateway,
startGatewayForRecovery,
startGatewayWithOptions,

@prekshivyas prekshivyas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head 625971a. No blocking findings. Required checks are green. Non-blocking follow-up: add focused coverage for the standalone Docker-driver launch failure path.

@prekshivyas
prekshivyas merged commit f369791 into main Aug 14, 2026
62 checks passed
@prekshivyas
prekshivyas deleted the codex/7695-gateway-composition branch August 14, 2026 20:37
cv added a commit that referenced this pull request Aug 15, 2026
<!-- markdownlint-disable MD041 -->
## Summary

Close static TypeScript coverage gaps in the onboarding
entry-composition ratchet after #9178. The check now records existing
lifecycle decisions that the prior scan missed and fails closed when new
decisions exceed the merge-base ceiling.

## Related Issue

Advances #9172.

## Changes

- Scan declaration headers, callable scopes, initializers, module
statements, and nested callable bodies.
- Normalize the static lifecycle and recovery call forms covered by the
regression matrix.
- Record existing gateway, messaging, policy, and provider decisions.
The work in #9169, #9170, and #9172 will remove these allowances.
- Reject budget increases above the decisions present at the merge base.
- Add regression tests for the decision and recovery syntax that the
check detects.

## 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:
- [ ] Docs updated for user-facing behavior changes
- [x] Docs not applicable — justification: This change affects an
internal repository check only.
- [x] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [x] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification: Independent Codex
Desktop review passed all nine security categories for commit under
review `9072818a6220c97bcd02a2b20b0a34915902df6d`. The PR-owned files
are unchanged by the additive merge of
`a8ceeb1a6e5ca4e517a4bc0c9767f8a7cc52916d`. That merge adds Google
Gemini docs and provider-catalog tests outside this check. The review
confirmed fixed-argument Git execution, fail-closed merge-base errors,
lexical alias isolation, and positive and negative tests.
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:

## Documentation Writer Review

- [x] Documentation writer subagent reviewed the completed changes
- Result: `no-docs-needed`
- Evidence: The PR changes an internal repository check, its allowance
data, and tests. The additive merge of
`a8ceeb1a6e5ca4e517a4bc0c9767f8a7cc52916d` changes only Google Gemini
docs and provider-catalog tests. The merge does not alter the three
PR-owned blobs or their reviewed behavior. This change does not alter
runtime, CLI, API, configuration, defaults, policy schema, or supported
product behavior. The prior focused tests passed 179/179. I did not
rerun them because the PR-owned blobs are unchanged.
- Agent: Codex Desktop
<!-- docs-review-head-sha: 9072818 -->
<!-- docs-review-agents-blob-sha: e30afb2 -->

## DGX Station Hardware Evidence

- [ ] Tested on DGX Station
- Tested commit:
- Station profile/scenario:
- Result:
- Supporting evidence:

## 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 test/onboard-entry-composition.test.ts
test/checks-runner.test.ts` passed, 179/179 tests.
- [ ] Applicable broad gate passed — `npm run check` was attempted.
Host-specific failures include an unsafe writable parent, a foreign user
gateway service, overlong Unix socket paths, and missing plugin-local
`json5`. GitHub CI provides the clean broad 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)

---
Signed-off-by: Carlos Villela <cvillela@nvidia.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved detection of gateway and onboarding decisions across complex
code patterns, including callbacks, nested calls, recovery actions, and
lifecycle logic.
* Added safeguards to prevent composition budgets from expanding beyond
approved limits.
* Improved validation and reporting when comparison baselines cannot be
determined.

* **Tests**
* Expanded coverage for decision detection, budget enforcement,
duplicate allowances, and category or declaration changes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>
Co-authored-by: Prekshi Vyas <prekshiv@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: architecture Architecture, design debt, major refactors, or maintainability area: onboarding Onboarding FSM, provider setup, sandbox launch, or first-run flow refactor PR restructures code without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract onboarding gateway lifecycle application

3 participants