docs/plans/2026-07-10-pr-6635-remaining-comments.md
Goal: Prevent a resolved-on-listen daemon from retaining its HTTP listener after channel worker startup fails, and verify worker base environments reach child processes.
Architecture: Keep generic runtime failures on their existing degraded-health path. When a requested channel worker fails during startup, begin a raw listener close before rejecting runtimeReady; retain its promise so a subsequent public close waits for the same drain instead of closing twice. Extend the existing supervisor spawn assertion with an explicit injected base environment value.
Files:
Modify: packages/cli/src/serve/run-qwen-serve.test.ts
Modify: packages/cli/src/serve/run-qwen-serve.ts
Change the existing resolveOnListen worker-start failure test to assert handle.server.listening is false after runtimeReady rejects.
Run the focused test and confirm it fails because the listener remains open.
Mark only channel worker startup failures for listener closure; start server.close during failure cleanup, force-close existing connections, retain its drain promise, and log a close error without masking the startup error.
Make public handle.close() await that existing listener drain instead of attempting a second close.
Run the focused test and confirm the listener is no longer active.
Files:
Modify: packages/cli/src/serve/channel-worker-supervisor.test.ts
Extend the existing spawned-worker environment test with workerBaseEnv: { ...process.env, CUSTOM: 'value' } and assert the spawn options contain CUSTOM: 'value'.
Run the focused supervisor test file.
npm run build, npm run typecheck, npm run lint, and git diff --check.Files:
Modify: packages/cli/src/serve/channel-worker-group.test.ts
Modify: packages/cli/src/serve/channel-worker-group.ts
Modify: packages/cli/src/serve/run-qwen-serve.test.ts
Modify: packages/cli/src/serve/run-qwen-serve.ts
Add a group test that calls enqueueWebhookTask() for a named channel and expects only that channel's owning supervisor to receive the task.
Run cd packages/cli && npx vitest run src/serve/channel-worker-group.test.ts and confirm the test fails because ChannelWorkerGroup has no enqueueWebhookTask method.
Add enqueueWebhookTask: ChannelWorkerSupervisor['enqueueWebhookTask'] to ChannelWorkerGroup, resolve named selections to their owning entry, use the all entry for --channel all, and return channel_worker_unavailable when no group owns the task channel.
Add serve orchestration tests that capture the createServeApp dependencies, verify enqueueChannelWebhookTask forwards to the worker group, and preserve the no-worker structured-unavailable behavior.
Reconnect enqueueChannelWebhookTask in run-qwen-serve.ts and run both focused test files until green.
Files:
Modify: packages/cli/src/serve/channel-worker-group.test.ts
Preserve the CI failure evidence: tsc --build reports TS2741 because fakeRegistry() predates the required WorkspaceRegistry.add method merged from main.
Add the minimal add test double to fakeRegistry(); no production behavior changes.
Run cd packages/cli && npx tsc --noEmit and confirm the missing-method error is gone.
npm run build && npm run typecheck, npm run lint, and git diff --check.Files:
Modify: packages/cli/src/serve/server.ts
Modify: packages/cli/src/serve/run-qwen-serve.ts
Modify: packages/cli/src/serve/run-qwen-serve.test.ts
Extend the multi-workspace orchestration test with a webhook configured only in secondary workspace settings and confirm the deferred request fails with 401 on the primary-only lookup.
Derive webhook configuration sources from the frozen channel ownership plan, limited to the selected channel names for each workspace.
Use the owning workspace for deferred webhook secret authentication and load the same per-workspace sources when registering runtime routes.
Confirm the secondary webhook authenticates, starts the deferred runtime, dispatches only to the secondary supervisor, and returns 202.
Re-run full verification and code review before pushing.