> For the complete documentation index, see [llms.txt](https://faction-os.gitbook.io/faction-os-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase20-session02-queue-terminal-execution/code-review.md).

# Code Review and Repair Report

**Session ID**: `phase20-session02-queue-terminal-execution` **Package**: null - cross-package monorepo session **Reviewed**: 2026-06-28 **Scope**: All uncommitted changes in the working tree **Result**: RESOLVED

## Review Surface

**Files reviewed** (all uncommitted implementation/session changes):

* `.spec_system/state.json` - tracked-modified
* `.spec_system/specs/phase20-session02-queue-terminal-execution/spec.md` - untracked
* `.spec_system/specs/phase20-session02-queue-terminal-execution/tasks.md` - untracked
* `.spec_system/specs/phase20-session02-queue-terminal-execution/implementation-notes.md` - untracked
* `apps/cli/README_cli.md` - tracked-modified
* `apps/cli/src/lib/orchestrationDiagnostics.js` - tracked-modified
* `apps/cli/tests/orchestrationDiagnostics.test.js` - tracked-modified
* `apps/server/src/lib/orchestrationDiagnostics.ts` - tracked-modified
* `apps/server/src/lib/orchestrationValidation.ts` - tracked-modified
* `apps/server/src/managers/taskExecutionCoordinator.ts` - untracked
* `apps/server/src/managers/taskQueue.ts` - tracked-modified
* `apps/server/src/routes/orchestration.ts` - tracked-modified
* `apps/server/src/server.ts` - tracked-modified
* `apps/server/tests/orchestration.test.ts` - tracked-modified
* `apps/server/tests/orchestrationDiagnostics.test.ts` - tracked-modified
* `apps/server/tests/taskExecutionCoordinator.test.ts` - untracked
* `apps/web/README_web.md` - tracked-modified
* `apps/web/src/components/orchestration/CommandCenterPanes.tsx` - tracked-modified
* `apps/web/src/components/orchestration/OrchestrationShell.tsx` - tracked-modified
* `apps/web/src/components/orchestration/OrchestrationTabs.tsx` - tracked-modified
* `apps/web/src/components/orchestration/QueueWorkbench.tsx` - tracked-modified
* `apps/web/src/lib/commandCenterUi.ts` - tracked-modified
* `apps/web/src/lib/orchestrationApi.ts` - tracked-modified
* `apps/web/src/lib/orchestrationUi.ts` - tracked-modified
* `apps/web/src/store/useGameStore.ts` - tracked-modified
* `apps/web/tests/CommandCenterPanes.test.tsx` - tracked-modified
* `apps/web/tests/TerminalRuntimeDrawer.test.tsx` - tracked-modified
* `apps/web/tests/commandCenterStore.test.ts` - tracked-modified
* `apps/web/tests/orchestrationApi.test.ts` - tracked-modified
* `apps/web/tests/orchestrationUi.test.ts` - tracked-modified
* `docs/api/README_api.md` - tracked-modified
* `docs/api/event-api-hook-contracts.md` - tracked-modified
* `packages/protocol/src/taskQueue.ts` - tracked-modified
* `packages/protocol/tests/orchestration.test.ts` - tracked-modified
* `tests/e2e/orchestration-command-center.e2e.ts` - tracked-modified

**Inventory commands**: `git status`, `git diff HEAD`, `git diff --cached`, `git ls-files --others --exclude-standard`

`code-review.md` was created by this `creview` step after the review and repair pass.

## Findings by Severity

### Critical

No findings.

### High

* `apps/server/src/managers/taskQueue.ts:566` and `apps/server/src/managers/taskExecutionCoordinator.ts:285` - Explicit terminal `commandLabel` values from request-scoped executable payloads were copied into public queue execution summaries without server-side redaction. A secret-like label could leak through REST queue entries and `task_queue_update` frames even though raw `commandText` stayed private. | Fix: Added `safeTerminalCommandLabel` / `safeCommandLabel` so explicit labels and fallback labels are redacted before entering broad summaries. Updated the route test to use `commandLabel: "echo token=secret-token"` and assert broad responses/events do not include the token. | Status: FIXED
* `apps/server/src/routes/orchestration.ts:133` - Terminal dispatch was async, but other queue mutation routes could still update or reject the same entry while the terminal run was in flight. A later completion update could overwrite the intervening mutation and clear rejection state. | Fix: Added a route-level queue execution lock for terminal dispatch that blocks update/reject/restore/unavailable/start-tracking while allowing duplicate dispatch requests to reach the coordinator duplicate path. Added a controlled PTY route test proving reject returns `409` during in-flight terminal dispatch and the dispatch can still complete. | Status: FIXED

### Medium

* `apps/web/src/lib/orchestrationApi.ts:4144` - The web broad queue payload guard rejected any serialized response containing substrings such as `stdout` or `commandText`, even when those words appeared only in safe title text. That could break queue hydration for legitimate tasks. | Fix: Replaced substring scanning with recursive object-key checks for blocked broad fields. Added a web API regression that rejects a raw `stdout` field but accepts a safe title containing `stdout` and `commandText` as words. | Status: FIXED

### Low

No findings.

## Assumptions and Deliberate Non-Fixes

None.

## Behavior Changes

* Broad queue execution summaries now redact explicit terminal command labels before REST or WebSocket exposure.
* Queue update/reject/restore/unavailable/start-tracking mutations now return a compact `409` while a terminal dispatch for the same entry is in flight.
* The web queue response guard now rejects blocked raw field keys instead of harmless text values containing blocked-field words.

## Verification

* Tests: `npx vitest run packages/protocol/tests/orchestration.test.ts` - PASS - 1 file, 13 tests.
* Tests: `npx vitest run apps/server/tests/orchestration.test.ts apps/server/tests/orchestrationDiagnostics.test.ts apps/server/tests/taskExecutionCoordinator.test.ts` - PASS - 3 files, 20 tests.
* Tests: `npx vitest run apps/web/tests/orchestrationApi.test.ts apps/web/tests/orchestrationUi.test.ts apps/web/tests/CommandCenterPanes.test.tsx apps/web/tests/TerminalRuntimeDrawer.test.tsx apps/web/tests/commandCenterStore.test.ts` - PASS - 5 files, 60 tests.
* Tests: `npx vitest run apps/cli/tests/orchestrationDiagnostics.test.js` - PASS - 1 file, 6 tests.
* Tests: `npx playwright test tests/e2e/orchestration-command-center.e2e.ts --project=app-desktop -g "dispatches a terminal queue row"` - PASS - 1 test.
* Tests: `npx playwright test tests/e2e/orchestration-command-center.e2e.ts --project=app-mobile -g "dispatches a terminal queue row"` - PASS - 1 test.
* Type checker: `npm --workspace @factionos/protocol run typecheck` - PASS.
* Type checker: `npm --workspace @factionos/server run typecheck` - PASS.
* Type checker: `npm --workspace @factionos/web run typecheck` - PASS.
* Formatter: `npm run format:check` - PASS.
* Linter: `npm run lint` - PASS.
* Formatter repair: `npx biome format --write ...` - PASS - formatted touched source/test files after initial format check reported formatting drift.
* Diff hygiene: `git diff --check` - PASS.
* ASCII/LF: Perl CRLF and non-ASCII scans over `git diff --name-only -z HEAD` - PASS.
* Final diff re-read: no remaining issues found.

## Summary

1. Reviewed 35 uncommitted implementation, test, documentation, and session files across protocol, server, web, CLI, docs, and e2e coverage.
2. Findings: 0 critical, 2 high, 1 medium, 0 low; all resolved with focused tests.
3. No deliberate non-fixes remain.
4. Focused unit, browser, typecheck, format, lint, diff, ASCII, and LF checks passed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase20-session02-queue-terminal-execution/code-review.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
