# WO-47: Validate and execute diagnostics without blocking the agent

Status: repository repair complete and delivered to `origin/main`. Publication and live validation remain with the user.

## Finding and root repair

Field review F2 recorded `requestedSteps.filter is not a function`: a JSON-encoded string reached an unchecked array cast. Review also found silently omitted requested checks, successful 0/0 results, implicit package downloads, and synchronous subprocess calls that can block typing and Stop for two minutes per step.

Use an executable input contract at runner admission and direct invocation. Validate requested steps and project paths before launching anything. Report unavailable requested checks and empty detection explicitly. Use configured local commands through the existing asynchronous process runner, with bounded output, timeout and cancellation of the owning process group. Preserve actual per-step outcomes in typed command receipts; never invent an aggregate successful command.

## Owned paths

- `packages/execution/src/tools/diagnostic.ts` and diagnostic tests.
- `packages/execution/src/types.ts`: optional array of actual command receipts.
- Runner and CLI adapter receipt propagation, coordinated with WO-48.

## Acceptance

- [x] String/null/object/invalid/empty steps and invalid path/fix arguments are rejected before execution, with actionable errors.
- [x] Valid subsets execute exactly; explicit unavailable checks and zero detected checks cannot report success.
- [x] No implicit dependency download or empty-test override; actual exit failures remain visible regardless of stdout.
- [x] Event-loop responsiveness, bounded timeout, Stop, descendant cleanup and sibling isolation are exercised with local fixtures.
- [x] Actual per-step receipts survive adapter, runner evidence recording and terminal reporting, including mixed outcomes.
- [x] Record full package verification, scoped commit and push.

## Implemented behavior and focused verification

`DiagnosticTool.validateInput` and direct `execute` share the same value-level guard. The production CLI regression reproduces the field's JSON-string `steps` through the real adapter and runner: validation rejects it before the tool body or a process executes. Unsupported or unavailable explicit checks reject the whole request before dispatch. Default detection requires at least one available command.

Configured package scripts run through `npm run <step>` with argument arrays; fallback runners must already exist in a local `node_modules/.bin` directory. The tool no longer launches `npx` or adds Jest's `--passWithNoTests`. Local ESLint and Biome receive their respective `--fix` and `--write` flags. Commands execute using `runProcessBuffer` with a copied environment, bounded capture, a per-command timeout, and private process-group cancellation on Unix. Stop drains the owning invocation and prevents later steps; another tool instance remains independent. Build, lint fixes and package scripts retain external-effect authority.

`ToolResult.executionReceipts` carries one actual command receipt per attempted step. Completed processes retain their actual exit status. Timeout, cancellation and incomplete capture use null effective/primary status, preserving any raw zero exit in `runnerExitCode`; a cancelled process cannot become verification success merely by handling TERM with `exit(0)`. Earlier completed checks remain separately attributable when a later check fails. No aggregate successful command is invented.

Focused verification (2026-09-05, synthetic processes and temporary projects only):

- `packages/execution/tests/diagnostic.test.ts`: 35 passing tests.
- Existing `packages/execution/tests/process-async.test.ts`: 1 passing descendant-cancellation test.
- `packages/cli/tests/diagnostic-boundary.test.ts`: 3 passing production-boundary tests, including exact two-command terminal reports with exit pairs `[0, 0]` and `[0, 7]`.
- Execution typecheck passed. Logs: `/tmp/omnius-wo47-diagnostic-tests.log`, `/tmp/omnius-wo47-cli-boundary-tests.log`, `/tmp/omnius-wo47-execution-types.log`.

These receipts prove the observed process outcomes, not the completeness of a project's test suite. Configured package scripts remain project-owned commands and may themselves perform network access or modify files; the diagnostic tool does not invent a sandbox or infer an exact changed-file list. Unix descendant ownership is covered on the current host. Publication and live validation remain outside this workorder's repair execution.

The complete execution package passed 1,820 tests with 3 pre-existing skips across 163 suites (`/tmp/omnius-remedies-execution-full.log`). The production CLI boundary tests and receipt consumer ship with WO48 so that each source commit has its dependencies.

## Repository acceptance and delivery

- Source repair: `d4c37489`, delivered to `origin/main`; coordinated changes: `672bef53 (CLI adapter and report integration)`.
- Clean rebuild of all workspace packages and final orchestrator rebuild passed.
- Execution: 1,820 passed / 3 existing skips across 163 suites.
- CLI: 2,575 passed across 274 suites. Rerun with `--maxWorkers=4 --minWorkers=1` cleared the original five UI import timeouts without changing those tests or their limits.
- Orchestrator: full run covered 228 suites with 2,847 passed / 1 existing skip / 1 outdated fixture failure. The fixture lacked required `pipefail`; it was corrected, and all 10 tests in that suite then passed. No production source changed after the full run began. This is full-suite coverage plus the corrected suite rerun, not a claim that the initial command exited successfully.
- Across these packages, all 7,243 distinct non-skipped tests have a passing result on the final implementation. Logs: `/tmp/omnius-remedies-execution-full.log`, `/tmp/omnius-remedies-orchestrator-full.log`, `/tmp/omnius-remedies-receipt-fixture.log`, `/tmp/omnius-remedies-cli-final.log`.

Checks used hermetic backend/Telegram transport and synthetic local process/project fixtures. No live inference, service restart, installed-package replacement, Telegram sends or publication were performed. The existing publish staging and unrelated discovery changes were preserved.
