Skip to content

fix(orchestration): recover stripped task deps - #16743

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:codex/fix-powershell-task-deps
Aug 30, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:codex/fix-powershell-task-deps

Conversation

@Pr1p

@Pr1p Pr1p commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

ELI5

PowerShell can hand Orca a dependency list where the JSON quotes are gone. Orca now still accepts that list when it clearly contains valid generated task IDs.

What Changed

  • Keep normal JSON array parsing for orchestration task-create --deps as the primary path.
  • Add a narrow fallback for bracketed generated task IDs such as [task_b2a580db74d8] after argv quote stripping.
  • Add CLI/RPC regression coverage for the stripped Windows form.

Why

The documented contract is still --deps <json_array>, but Windows PowerShell can strip inner quotes before the value reaches the runtime. The fallback is intentionally strict: it only accepts bracketed, comma-separated IDs matching task_[0-9a-f]{12}. Malformed values and broader non-JSON input continue to fail.

Linked Issue

Fixes #16706

Visual Proof

N/A — CLI/runtime behavior only; no UI or visual change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Local checks run on Windows workspace:

  • pnpm exec vitest run --config config/vitest.config.ts src/cli/handlers/orchestration-task-create-cli.test.ts src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts --reporter=dot
  • pnpm exec oxlint src/cli/handlers/orchestration-task-create-cli.test.ts src/main/runtime/rpc/methods/orchestration.ts src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts
  • pnpm exec oxfmt --check src/cli/handlers/orchestration-task-create-cli.test.ts src/main/runtime/rpc/methods/orchestration.ts src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts
  • pnpm run typecheck:node
  • pnpm run typecheck:cli

Note: local typechecks emitted the existing engine warning because this environment uses Node v22.23.1 while the package declares Node 24.

AI Disclosure

Implemented with GPT-5 Codex assistance under user direction. I inspected the linked issue, made the focused change, and ran the checks listed above.

Review

Ready for maintainer review.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Cross-platform: normal JSON remains the preferred path on every platform; the fallback only handles a Windows argv stripping shape that still contains valid generated task IDs. SSH/remote: no wire shape changes. Backwards compatibility: accepted valid JSON behavior is unchanged; invalid non-JSON values still fail unless they match the narrow generated-ID fallback.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

orchestration.taskCreate now parses dependencies through a shared helper. The helper accepts JSON arrays of strings and validated bracketed, comma-separated generated task IDs. Invalid dependency values still produce the existing validation error. New tests verify CLI flag mapping, terminal handle propagation, PowerShell-stripped dependencies, and dependent task dispatch behavior.

Merge Risk: 🔵 Low · up to fc8d8

The compatibility fallback currently accepts uppercase task IDs even though the intended format is lowercase-only. This is a bounded behavior mismatch and is mergeable with explicit owner follow-up to remove case-insensitive matching and add rejection coverage.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: recovering stripped task dependencies for orchestration.
Description check ✅ Passed The description covers the required sections, explains the problem and solution, links issue #16706, records testing, and addresses visual proof and compatibility considerations. The unchecked full-su…
Linked Issues check ✅ Passed The changes satisfy issue #16706. They preserve JSON array parsing, recover the documented PowerShell-stripped form with strict task-ID validation, persist dependencies for child tasks, and add CLI, r…
Out of Scope Changes check ✅ Passed The changes are limited to dependency parsing and related CLI, RPC, runtime-boundary, Windows, and regression tests. No unrelated production behavior or UI changes are included.
Docstring Coverage ✅ Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files.
Full details: Description check

Explanation

The description covers the required sections, explains the problem and solution, links issue #16706, records testing, and addresses visual proof and compatibility considerations. The unchecked full-suite checklist item is acceptable because CI coverage is noted.

Full details: Linked Issues check

Explanation

The changes satisfy issue #16706. They preserve JSON array parsing, recover the documented PowerShell-stripped form with strict task-ID validation, persist dependencies for child tasks, and add CLI, runtime, and Windows boundary regression coverage.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Pr1p
Pr1p force-pushed the codex/fix-powershell-task-deps branch from 7ec3027 to eebbbf2 Compare August 28, 2026 06:22
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Pr1p

Pr1p commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main and addressed the review follow-up:

  • Added docstrings for the touched dependency parsing helpers.
  • Strengthened the regression to assert a PowerShell-stripped deps payload is persisted as a real task dependency.

Local validation:

  • pnpm exec vitest run --config config/vitest.config.ts src/cli/handlers/orchestration-task-create-cli.test.ts src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts src/shared/runtime-client-export-parity.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/main/providers/windows-shell-preflight-runtime.windows.test.ts
  • pnpm tc
  • pnpm exec oxlint --report-unused-disable-directives-severity warn src/cli/handlers/orchestration-task-create-cli.test.ts src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts src/main/runtime/rpc/methods/orchestration.ts

GitHub Actions for the new head are currently action_required, so they need maintainer approval before they can run.

@Pr1p
Pr1p force-pushed the codex/fix-powershell-task-deps branch from eebbbf2 to 7ba9774 Compare August 28, 2026 06:50
@Pr1p

Pr1p commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Added the CLI/runtime integration regression CodeRabbit requested in 7ba9774b:

  • Runs the real orchestration CLI handlers against the in-memory runtime RPC harness.
  • Creates a real parent task through orchestration task-create.
  • Creates a child task through orchestration task-create --deps [<parent>], matching the Windows PowerShell-stripped argv shape.
  • Verifies the child is persisted as pending with the parent recorded in deps.
  • Verifies dependency gating blocks dispatch while the parent is incomplete, then promotes and dispatches after the parent is completed.

Validation after the change:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/methods/orchestration-cli-runtime-boundary.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/methods/orchestration-cli-runtime-boundary.test.ts src/cli/handlers/orchestration-task-create-cli.test.ts src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts
  • pnpm tc
  • pnpm exec oxlint --report-unused-disable-directives-severity warn src/cli/handlers/orchestration-task-create-cli.test.ts src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts src/main/runtime/rpc/methods/orchestration.ts src/main/runtime/rpc/methods/orchestration-cli-runtime-boundary.test.ts

pnpm run check:code-quality:changed still fails in this local Windows shell before lint execution with spawnSync pnpm.cmd EINVAL under Node v22.23.1; the direct oxlint invocation above passes for the same changed files. GitHub Actions for the new head are action_required and need maintainer approval before they run.

@Pr1p
Pr1p force-pushed the codex/fix-powershell-task-deps branch from 7ba9774 to 1c05c51 Compare August 28, 2026 07:59
@nwparker
nwparker force-pushed the codex/fix-powershell-task-deps branch from 1c05c51 to eb7f463 Compare August 30, 2026 05:04
@greptile-apps

greptile-apps Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR recovers PowerShell-stripped orchestration dependency arrays while preserving canonical JSON parsing.

  • Adds a strict fallback for bracketed, comma-separated generated task IDs.
  • Routes task creation dependency parsing through the shared parser.
  • Adds unit, CLI/RPC boundary, dispatch-gating, and Windows PowerShell regression coverage.
  • Updates persisted-session worktree reference metadata for workspaceDocHistory.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/main/runtime/orchestration/task-deps-flag.ts Adds canonical JSON parsing with a narrowly constrained fallback for PowerShell-stripped generated task IDs.
src/main/runtime/rpc/methods/orchestration.ts Replaces inline dependency parsing in task creation with the shared parser.
src/main/cli/native-cli-powershell-argv-boundary.test.ts Verifies the actual PowerShell 5.1 native argv transformation on Windows.
src/main/runtime/orchestration/task-deps-flag.test.ts Covers canonical input, stripped input, malformed values, wrong JSON shapes, and generated-ID compatibility.
src/main/runtime/rpc/methods/orchestration-cli-runtime-boundary.test.ts Exercises stripped dependencies end-to-end through CLI mapping, RPC validation, persistence, readiness gating, and dispatch.
src/main/persistence/restoring-sessions/session-worktree-ownership.ts Classifies workspace document history as containing no worktree ownership references.

Sequence Diagram

sequenceDiagram
  participant PS as PowerShell
  participant CLI as Orca CLI
  participant RPC as taskCreate RPC
  participant Parser as Dependency parser
  participant DB as Orchestration DB
  PS->>CLI: --deps [task_012345abcdef]
  CLI->>RPC: raw deps string
  RPC->>Parser: parse dependencies
  Parser->>Parser: JSON parse, then strict argv fallback
  Parser-->>RPC: task ID array
  RPC->>DB: createTask with dependencies
  DB-->>RPC: pending or ready task
Loading

Reviews (4): Last reviewed commit: "fix(orchestration): recover stripped tas..." | Re-trigger Greptile

@nwparker
nwparker force-pushed the codex/fix-powershell-task-deps branch from eb7f463 to fc8d85f Compare August 30, 2026 05:07
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ed3ad0db-b440-469b-bec7-5b26c7130306

📥 Commits

Reviewing files that changed from the base of the PR and between 3031c23 and fc8d85f78b31c3558cb2f1753741fbff52bd1017.

📒 Files selected for processing (7)
  • src/cli/handlers/orchestration-task-create-cli.test.ts
  • src/main/cli/native-cli-powershell-argv-boundary.test.ts
  • src/main/runtime/orchestration/task-deps-flag.test.ts
  • src/main/runtime/orchestration/task-deps-flag.ts
  • src/main/runtime/rpc/methods/orchestration-cli-runtime-boundary.test.ts
  • src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/cli/handlers/orchestration-task-create-cli.test.ts
  • src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts
  • src/main/runtime/rpc/methods/orchestration-cli-runtime-boundary.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

@@ -0,0 +1,34 @@
const INVALID_DEPS_ERROR = 'Invalid --deps: must be a JSON array of task IDs'
const GENERATED_TASK_ID_PATTERN = /^task_[0-9a-f]{12}$/i

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject uppercase fallback IDs.

The i flag accepts values such as [TASK_B2A580DB74D8]. Those values do not match the specified strict fallback grammar, task_[0-9a-f]{12}. Remove i and add uppercase rejection cases.

Proposed fix
-const GENERATED_TASK_ID_PATTERN = /^task_[0-9a-f]{12}$/i
+const GENERATED_TASK_ID_PATTERN = /^task_[0-9a-f]{12}$/
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const GENERATED_TASK_ID_PATTERN = /^task_[0-9a-f]{12}$/i
const GENERATED_TASK_ID_PATTERN = /^task_[0-9a-f]{12}$/

@nwparker
nwparker force-pushed the codex/fix-powershell-task-deps branch from fc8d85f to fc475f3 Compare August 30, 2026 05:42
@nwparker
nwparker force-pushed the codex/fix-powershell-task-deps branch from fc475f3 to ec3050a Compare August 30, 2026 05:51
@nwparker
nwparker merged commit 07df4bf into stablyai:main Aug 30, 2026
57 of 60 checks passed
nwparker added a commit that referenced this pull request Aug 30, 2026
Windows PowerShell 5.1 does not escape inner quotes when building a native
command line, so `--options '["a","b"]'` reaches orca.exe as `--options [a,b]`.
The value is correct when printed and damaged by the time argv is parsed, so the
resulting "invalid JSON" error blamed the user's input rather than the shell.

#16743 recovered this for `--deps`, which is safe only because generated task IDs
have a fixed 12-hex grammar. The same mangling hits `--options`, `--payload` and
`--result`, and those are NOT safely recoverable: `["1","2"]` and `[1,2]` arrive
at argv identically, so a general repair would silently turn strings into numbers.

Detect instead. `getOptionalJsonFlag` rejects the damaged shape up front with an
error that names the shell and shows the workaround. It fires only when the value
is bracketed, quote-free, fails JSON.parse, AND consists entirely of bare tokens
that quoting would rescue, so valid JSON is untouched.

Also share the generated-id contract: `task-deps-flag` hardcoded
/^task_[0-9a-f]{12}$/i, which silently diverges if `generateId`'s byte count
changes. It now calls `isGeneratedId`, with a test pinning the two together.

Verified on a Windows host. Measured argv, which the new test pins as a fixture:
  PS_VALUE=["task_b2a580db74d8","task_c3b691ec85e9"]
  ARGV=["--deps","[task_b2a580db74d8,task_c3b691ec85e9]"]

Before: Invalid --options: must be a JSON array of strings
After:  --options arrived as [a,b], which is not valid JSON.
        Windows PowerShell 5.1 strips the inner quotes ...
nwparker added a commit that referenced this pull request Aug 30, 2026
* fix(cli): name PowerShell when it strips quotes from JSON flags

Windows PowerShell 5.1 does not escape inner quotes when building a native
command line, so `--options '["a","b"]'` reaches orca.exe as `--options [a,b]`.
The value is correct when printed and damaged by the time argv is parsed, so the
resulting "invalid JSON" error blamed the user's input rather than the shell.

#16743 recovered this for `--deps`, which is safe only because generated task IDs
have a fixed 12-hex grammar. The same mangling hits `--options`, `--payload` and
`--result`, and those are NOT safely recoverable: `["1","2"]` and `[1,2]` arrive
at argv identically, so a general repair would silently turn strings into numbers.

Detect instead. `getOptionalJsonFlag` rejects the damaged shape up front with an
error that names the shell and shows the workaround. It fires only when the value
is bracketed, quote-free, fails JSON.parse, AND consists entirely of bare tokens
that quoting would rescue, so valid JSON is untouched.

Also share the generated-id contract: `task-deps-flag` hardcoded
/^task_[0-9a-f]{12}$/i, which silently diverges if `generateId`'s byte count
changes. It now calls `isGeneratedId`, with a test pinning the two together.

Verified on a Windows host. Measured argv, which the new test pins as a fixture:
  PS_VALUE=["task_b2a580db74d8","task_c3b691ec85e9"]
  ARGV=["--deps","[task_b2a580db74d8,task_c3b691ec85e9]"]

Before: Invalid --options: must be a JSON array of strings
After:  --options arrived as [a,b], which is not valid JSON.
        Windows PowerShell 5.1 strips the inner quotes ...

* fix(cli): scope JSON-flag detection to genuinely JSON flags

Review found the detector wired to two flags that are not JSON:

- `orchestration ask --options` is documented `<csv>` and the runtime splits it
  on commas, so `--options [a,b]` was a legitimate value being rejected.
- `task-update --result` is stored verbatim and reused as dispatch failure text;
  existing tests pass free text, so a bracketed `[ok]` was being rejected.

Both revert to `getOptionalStringFlag`. Only `gate-create --options`
(`<json_array>`) and `send --payload` (`<json>`) are JSON-parsed and keep it.

Three further review fixes:

- Objects now require a `key:value` pair per entry. `{a,b}` and `{a:b,c}` were
  reported as quote-stripped although quoting them cannot produce valid JSON.
- The raw value is no longer echoed. A `--payload` can carry secrets and this
  message reaches `--json` output; the flag name and guidance are enough.
- The message hedges the shell attribution. Detection inspects only the value's
  shape, so it also fires when a macOS/Linux user forgets to quote, where
  PowerShell is not involved.

Verified against a Windows host, all six cases: both JSON flags fire on the
mangled shape and pass valid JSON through to the runtime; both non-JSON flags
now reach the runtime again; and the secret in `{token:hunter2}` appears zero
times in the error output.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#17351)

* fix(cli): name PowerShell when it strips quotes from JSON flags

Windows PowerShell 5.1 does not escape inner quotes when building a native
command line, so `--options '["a","b"]'` reaches orca.exe as `--options [a,b]`.
The value is correct when printed and damaged by the time argv is parsed, so the
resulting "invalid JSON" error blamed the user's input rather than the shell.

stablyai#16743 recovered this for `--deps`, which is safe only because generated task IDs
have a fixed 12-hex grammar. The same mangling hits `--options`, `--payload` and
`--result`, and those are NOT safely recoverable: `["1","2"]` and `[1,2]` arrive
at argv identically, so a general repair would silently turn strings into numbers.

Detect instead. `getOptionalJsonFlag` rejects the damaged shape up front with an
error that names the shell and shows the workaround. It fires only when the value
is bracketed, quote-free, fails JSON.parse, AND consists entirely of bare tokens
that quoting would rescue, so valid JSON is untouched.

Also share the generated-id contract: `task-deps-flag` hardcoded
/^task_[0-9a-f]{12}$/i, which silently diverges if `generateId`'s byte count
changes. It now calls `isGeneratedId`, with a test pinning the two together.

Verified on a Windows host. Measured argv, which the new test pins as a fixture:
  PS_VALUE=["task_b2a580db74d8","task_c3b691ec85e9"]
  ARGV=["--deps","[task_b2a580db74d8,task_c3b691ec85e9]"]

Before: Invalid --options: must be a JSON array of strings
After:  --options arrived as [a,b], which is not valid JSON.
        Windows PowerShell 5.1 strips the inner quotes ...

* fix(cli): scope JSON-flag detection to genuinely JSON flags

Review found the detector wired to two flags that are not JSON:

- `orchestration ask --options` is documented `<csv>` and the runtime splits it
  on commas, so `--options [a,b]` was a legitimate value being rejected.
- `task-update --result` is stored verbatim and reused as dispatch failure text;
  existing tests pass free text, so a bracketed `[ok]` was being rejected.

Both revert to `getOptionalStringFlag`. Only `gate-create --options`
(`<json_array>`) and `send --payload` (`<json>`) are JSON-parsed and keep it.

Three further review fixes:

- Objects now require a `key:value` pair per entry. `{a,b}` and `{a:b,c}` were
  reported as quote-stripped although quoting them cannot produce valid JSON.
- The raw value is no longer echoed. A `--payload` can carry secrets and this
  message reaches `--json` output; the flag name and guidance are enough.
- The message hedges the shell attribution. Detection inspects only the value's
  shape, so it also fires when a macOS/Linux user forgets to quote, where
  PowerShell is not involved.

Verified against a Windows host, all six cases: both JSON flags fire on the
mangled shape and pass valid JSON through to the runtime; both non-JSON flags
now reach the runtime again; and the secret in `{token:hunter2}` appears zero
times in the error output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task-create --deps rejects non-empty arrays again on 1.4.190 (Windows regression)

2 participants