Skip to content

feat: improve spawn error handling and reporting across full stack#249

Merged
tiann merged 4 commits intotiann:mainfrom
fireblue:feat/improve-spawn-error-handling
Mar 9, 2026
Merged

feat: improve spawn error handling and reporting across full stack#249
tiann merged 4 commits intotiann:mainfrom
fireblue:feat/improve-spawn-error-handling

Conversation

@fireblue
Copy link
Contributor

@fireblue fireblue commented Mar 6, 2026

Create Session 时,现在的代码如果失败了不会报具体的原因,这个PR能够显示具体的原因,如Failed to spawn HAPI process - no PID returned (cwd=/home/xxx/test_dir; EACCES: permission denied, posix_spawn '/home/xxx/hapi/cli/dist-exe/bun-linux-x64-baseline/hapi')

  • Return error result instead of throwing in apiMachine spawn handler
  • Add lastSpawnError field to RunnerState for persistent error tracking
  • Add error awaiter system for early process exit/error detection before webhook
  • Build detailed webhook failure messages with exit code, signal, and stderr tail
  • Report spawn outcomes to hub via runner state updates
  • Handle more spawn result types in rpcGateway with better error messages
  • Display runner last spawn error in web UI (NewSession & SpawnSession)
  • Extract shared formatRunnerSpawnError utility to avoid duplication

- Return error result instead of throwing in apiMachine spawn handler
- Add lastSpawnError field to RunnerState for persistent error tracking
- Add error awaiter system for early process exit/error detection before webhook
- Build detailed webhook failure messages with exit code, signal, and stderr tail
- Report spawn outcomes to hub via runner state updates
- Handle more spawn result types in rpcGateway with better error messages
- Display runner last spawn error in web UI (NewSession & SpawnSession)
- Extract shared formatRunnerSpawnError utility to avoid duplication

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Summary

  • 未发现新增问题
  • 风险: 新增错误路径缺少测试覆盖

Testing

  • Not run (automation)

Use `type === 'error'` instead of `type !== 'success'` to properly
narrow the discriminated union, allowing TypeScript to infer errorMessage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fireblue fireblue force-pushed the feat/improve-spawn-error-handling branch from fce96c2 to 4b81896 Compare March 6, 2026 08:29
@tiann
Copy link
Owner

tiann commented Mar 7, 2026

@tiann review

@github-actions
Copy link

github-actions bot commented Mar 7, 2026

I found 1 blocking issue.

  • lastSpawnError only gets persisted when reportSpawnOutcomeToHub runs (cli/src/runner/run.ts:416, cli/src/runner/run.ts:536, cli/src/runner/run.ts:554, handler defined at cli/src/runner/run.ts:678).
  • But several failure paths return before that hook is called: mkdir failure for simple sessions (cli/src/runner/run.ts:221), missing worktree base directory (cli/src/runner/run.ts:249), and worktree creation failure (cli/src/runner/run.ts:261).
  • Those errors still come back in the immediate spawn RPC response, but they are not written into runnerState.lastSpawnError, so the new banners in web/src/components/NewSession/index.tsx:257 and web/src/components/SpawnSession.tsx:147 will not show them after reload/reopen.

Validation: could not run bun typecheck here because bun is not installed in this environment.


HAPI Bot

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Review mode: initial. No issues found in changed lines. Residual risk: spawn-error paths not covered by tests here; end-to-end behavior not validated. Testing: not run (automation).

@tiann tiann merged commit 4716d31 into tiann:main Mar 9, 2026
2 checks passed
jasonczc pushed a commit to jasonczc/haqi that referenced this pull request Mar 15, 2026
…iann#249)

* feat: improve spawn error handling and reporting across full stack

- Return error result instead of throwing in apiMachine spawn handler
- Add lastSpawnError field to RunnerState for persistent error tracking
- Add error awaiter system for early process exit/error detection before webhook
- Build detailed webhook failure messages with exit code, signal, and stderr tail
- Report spawn outcomes to hub via runner state updates
- Handle more spawn result types in rpcGateway with better error messages
- Display runner last spawn error in web UI (NewSession & SpawnSession)
- Extract shared formatRunnerSpawnError utility to avoid duplication

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(cli): narrow spawnResult type check to fix TS2339 error

Use `type === 'error'` instead of `type !== 'success'` to properly
narrow the discriminated union, allowing TypeScript to infer errorMessage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit 4716d31)
doraemonkeys added a commit to doraemonkeys/hapi that referenced this pull request Mar 16, 2026
feat: improve spawn error handling and reporting across full stack (tiann#249)

Adapted to fork's sessionManager architecture:
- pidToErrorAwaiter + buildWebhookFailureMessage → sessionManager.ts
- SpawnOutcomeReporter injected via setSpawnOutcomeReporter()
- rpcGateway: merged requestToApproveDirectoryCreation + obj.message fallback
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.

2 participants