Skip to content

arch: async I/O modernization — unblock true parallel execution #506

Open

Description

@admarble

Problem (User Impact)

Users running sequant run 100 101 102 --concurrency 3 expect three issues to execute in parallel. In practice, spawnSync calls in github.ts, worktree-manager.ts, and batch-executor.ts block the Node.js event loop — meaning "parallel" execution serializes whenever any issue hits a git or GitHub CLI call. A slow gh issue view (common with GitHub rate limiting) freezes all concurrent issues, not just the one making the call.

Additionally, each issue triggers individual gh CLI invocations for metadata, comments, PR status, and labels. With 10 issues, that's 30-40 sequential subprocess calls before any real work begins.

Why Now

  • Parallel execution is Sequant's primary performance feature — it's half-broken without async I/O
  • The p-limit(3) concurrency control in run.ts:812 is correct but ineffective when subprocess calls block the event loop
  • Commander.js has supported async action handlers since v5 — the "sync callers need sync APIs" constraint that created fetchIssueCommentBodiesSync() and getPRStatusSync() no longer applies
  • arch: extract RunOrchestrator — decouple execution engine from CLI wiring #503 (RunOrchestrator) creates a clean async boundary — this issue migrates the internals to match

Acceptance Criteria

Async Subprocess Migration

  • AC-1: All spawnSync / execSync calls in src/lib/workflow/ replaced with async equivalents. Use execa (v7+) or a typed async wrapper around child_process.spawn
  • AC-2: GitHubProvider (src/lib/workflow/platforms/github.ts) — all sync methods (fetchIssueCommentBodiesSync, getPRStatusSync, checkAuthSync, listClosedIssuesSync) converted to async. Sync variants removed
  • AC-3: All callers of removed sync methods migrated to async (phase-detection.ts, pr-status.ts, doctor.ts, batch-executor.ts)
  • AC-4: WorktreeManager — git operations (git worktree add, git checkout, git rebase, git diff) use async subprocess execution

GitHub Query Batching

  • AC-5: New batchFetchIssues(issueNumbers: number[]) method on GitHubProvider that fetches metadata for N issues in a single gh api graphql call (title, labels, body, comments with phase markers)
  • AC-6: batch-executor.ts uses batchFetchIssues() at batch start instead of per-issue getIssueInfo() calls. Target: 1 API call for N issues instead of N calls
  • AC-7: Phase marker parsing (SEQUANT_PHASE comments) included in the batch query — no separate per-issue comment fetching
  • AC-8: Concurrency limit of 5 for any remaining individual gh API calls (respects GitHub secondary rate limits)

Verification

  • AC-9: Parallel execution with --concurrency 3 shows measurable improvement: wall-clock time for 3-issue run should be closer to 1x single-issue time, not 3x
  • AC-10: All existing tests pass. New tests verify async behavior (e.g., concurrent subprocess calls don't serialize)

Scope & Gaps to Watch

  • Gap: Error handling changes — spawnSync returns { status, stdout, stderr } synchronously. Async execa throws on non-zero exit by default. All callers must handle the new error contract (use { reject: false } where needed or catch explicitly)
  • Gap: doctor.ts sync dependency — The doctor command runs sequential health checks using sync subprocess calls. Must migrate to async but preserve sequential execution order (health checks should not run in parallel)
  • Gap: GraphQL query complexity — GitHub's GraphQL API has a node limit. For batches of 20+ issues, the query may need pagination. Test with realistic batch sizes (10, 20, 50 issues)
  • Gap: Offline/CI environments — gh CLI may not be authenticated in some CI environments. Async migration must preserve the graceful degradation (return defaults on failure) that sync methods currently provide
  • Risk: execa dependency — Adds ~50KB. Alternative: a 20-line typed wrapper around child_process.spawn. Either is fine, but decide and document the choice. If the project avoids heavy dependencies, the wrapper is better
  • Risk: Timeout behavior — spawnSync timeout kills the child process immediately. Async timeouts need an AbortController pattern. Ensure git operations that hang (e.g., waiting for credential input) are still killed

Technical Notes

  • Best practice from research: execa is the standard for production CLI tools. For staying dependency-light, a typed wrapper with reject: false option is ~15 lines
  • Current sync call sites to migrate:
    • github.ts: 8 methods using spawnSync("gh", ...)
    • worktree-manager.ts: ~20 spawnSync("git", ...) calls
    • batch-executor.ts: spawnSync("gh", ...) in getIssueInfo(), parseDependencies()
    • run.ts: detectDefaultBranch() uses spawnSync("git", ...)
    • phase-detection.ts: calls sync GitHub methods
  • Existing batchQueryIssuesAndPRs() in github.ts can be extended for AC-5/6
  • Commander.js awaits async action handlers since v5 — no barrier to async at the top level

Dependencies

Batch Group

sequant run batch 2 (parallel with event system and phase registry — all depend only on #503)

Activity

  1. added
    enhancement
    roadmap
    on Apr 8, 2026
  2. admarble commented on Apr 9, 2026

    @admarble
    ContributorAuthor

    Architecture Review: Recommended Scope Split

    After an overcomplexity assessment of the #503-#508 target architecture, this issue should be split. The async migration is justified — spawnSync genuinely blocks the event loop during parallel execution — but the scope is too broad for one issue.

    Phase A: This issue (critical path)

    Focus on GitHubProvider — this is where the actual bottleneck lives. A slow gh issue view during --concurrency 3 freezes all concurrent issues, not just the one making the call.

    Keep:

    • AC-1 scoped to GitHubProvider only (8 sync methods → async)
    • AC-2 (GitHubProvider async method conversion)
    • AC-3 (migrate callers of GitHubProvider sync methods)
    • AC-5 (batchFetchIssues() GraphQL batching) — real perf win, 1 API call for N issues
    • AC-6 (batch-executor uses batchFetchIssues())
    • AC-7 (phase marker parsing in batch query)
    • AC-8 (concurrency limit for remaining individual gh calls)
    • AC-9 (verification — parallel execution measurably improves)
    • AC-10 (tests pass)

    Defer to follow-up issue:

    • AC-4 (WorktreeManager async migration, ~20 spawnSync("git", ...) calls) — these are per-issue sequential operations. Making git worktree add async doesn't help when issue A's worktree setup must finish before issue A's phases begin. The event loop benefit is marginal compared to GitHubProvider where calls happen during the parallel fan-out.

    Rationale

    The ~30+ spawnSync call sites span two very different profiles:

    1. GitHubProvider (8 methods) — called during parallel issue processing, blocks event loop across all concurrent issues. High impact fix.
    2. WorktreeManager (~20 calls) — called sequentially per-issue during setup. Making these async lets other issues proceed during git ops, but the real bottleneck is GitHub API latency (network), not git ops (local disk). Low-medium impact.

    Fix the bottleneck that matters first. File the WorktreeManager migration as a separate low-priority issue.

    Updated AC checklist

    • GitHubProvider — all sync methods converted to async (fetchIssueCommentBodiesSync → fetchIssueCommentBodies, etc.)
    • All callers migrated (phase-detection.ts, pr-status.ts, doctor.ts, batch-executor.ts)
    • batchFetchIssues() — single GraphQL query for N issues (title, labels, body, comments)
    • batch-executor.ts uses batchFetchIssues() at batch start
    • Phase marker parsing included in batch query
    • Concurrency limit (5) for remaining individual gh calls
    • Parallel execution with --concurrency 3 shows measurable improvement
    • All tests pass
    • WorktreeManager async migration deferred to follow-up issue
  3. added 2 commits that reference this issue on Apr 9, 2026
  4. added
    backlog
    on Apr 15, 2026
  5. admarble commented on May 11, 2026

    @admarble
    ContributorAuthor

    → PARK — Backlog label already applied per author's own architecture review (2026-04-09). The review recommended a scope split: keep Phase A (GitHubProvider async + GraphQL batching, ACs 1–3, 5–10) as the actionable critical-path work, defer Phase B (WorktreeManager async migration, AC-4) to a separate low-priority issue.

    Resume after: parallel execution latency becomes a real pain point, or a user reports it. When unparked, file Phase A as a slimmed issue per the architecture review rather than executing the original AC set.

  6. admarble commented on May 12, 2026

    @admarble
    ContributorAuthor

    Supersedes prior assess from 2026-05-11 (PARK)

    → PARK — Backlog label remains the live state. The descoped Phase A (GitHubProvider async + GraphQL batching, ACs 1–3, 5–10) is the actionable critical-path work; Phase B (WorktreeManager, AC-4) is deferred per the 2026-04-09 review.

    New signal worth recording: #604's chain-mode forensics (df6277c) attribute parallel-mode failures to rate limits, QA saturation, and the AC_MET_BUT_NOT_A_PLUS retry loop — not event-loop blocking from sync subprocess calls. So even Phase A wouldn't move the documented success-rate needle. Phase A still has standalone value (cleaner async surface, faster fan-out under no-rate-limit conditions), but the user-pain trigger this issue was waiting on hasn't materialized.

    Resume after: parallel execution latency becomes a real pain point under non-rate-limited conditions, or someone files a slow-parallel report. When unparked, file Phase A as a slimmed issue per the architecture review rather than executing the original AC set.

  7. admarble commented on May 14, 2026

    @admarble
    ContributorAuthor

    → PARK — Re-confirming the 2026-05-12 PARK. No new signal warrants unparking.

    The descoped Phase A (GitHubProvider async + GraphQL batching) remains the actionable critical-path work; Phase B (WorktreeManager, AC-4) stays deferred per the 2026-04-09 review. Per #604's chain-mode forensics, parallel-mode failures trace to rate limits, QA saturation, and the AC_MET_BUT_NOT_A_PLUS retry loop — not event-loop blocking from sync subprocess calls.

    Resume after: parallel execution latency becomes a real pain point under non-rate-limited conditions, or someone files a slow-parallel report. When unparked, file Phase A as a slimmed issue per the architecture review rather than executing the original AC set.

  8. admarble commented on May 31, 2026

    @admarble
    ContributorAuthor

    Supersedes 3 prior assessments (most recent: 2026-05-14)

    → PARK — Dependency blockers cleared (#503 closed 2026-04-09, #504 closed 2026-05-14), but the live gate is the backlog label ("Deferred until user traction, 100+ WAU"), not a dependency. Re-assessed 3× since 2026-05-11 without execution — this is a deliberate product gate, not a stuck issue.

    No new signal warrants unparking. The descoped Phase A (GitHubProvider async + GraphQL batching, ACs 1–3, 5–10) remains the actionable critical-path work; Phase B (WorktreeManager, AC-4) stays deferred per the 2026-04-09 review. Per #604's chain-mode forensics, parallel-mode failures trace to rate limits, QA saturation, and the AC_MET_BUT_NOT_A_PLUS retry loop — not event-loop blocking from sync subprocess calls — so even Phase A wouldn't move the documented success-rate needle.

    Resume after: parallel execution latency becomes a real pain point under non-rate-limited conditions, or someone files a slow-parallel report. When unparked, file Phase A as a slimmed issue per the architecture review rather than executing the original AC set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogenhancementroadmap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions