Skip to content

Fix: Prevent crashes from unhandled promise rejections (#221)#243

Closed
pottertech wants to merge 1 commit intoqwibitai:mainfrom
pottertech:fix-unhandled-rejections
Closed

Fix: Prevent crashes from unhandled promise rejections (#221)#243
pottertech wants to merge 1 commit intoqwibitai:mainfrom
pottertech:fix-unhandled-rejections

Conversation

@pottertech
Copy link
Copy Markdown
Contributor

This PR fixes issue #221 by adding global error handlers to prevent crashes from unhandled promise rejections.

Changes

  • Add process.on('unhandledRejection') handler that logs errors and continues
  • Add process.on('uncaughtException') handler with graceful shutdown
  • Add top-level shutdown function for error handlers
  • Wrap streaming output callback in try/catch
  • Errors now trigger proper cursor rollback to prevent duplicate messages

Impact

  • Application no longer crashes when agents throw unhandled errors
  • Errors are logged and system continues operating
  • Graceful shutdown on fatal errors (connections close properly, queue drains)
  • Better retry behavior with exponential backoff preserved

…ctions

Fixes qwibitai#221

- Add process.on('unhandledRejection') handler with logging
- Add process.on('uncaughtException') handler with graceful shutdown
- Add top-level shutdown function for error handlers to call
- Wrap streaming output callback in try/catch
- Add retry tracking with exponential backoff in error handling

This prevents the entire message loop from crashing when agents or
containers throw unhandled errors. The system now:
1. Logs unhandled rejections and continues
2. Gracefully shuts down on uncaught exceptions
3. Handles errors in streaming callbacks safely

Co-authored-by: Brodie Foxworth <brodie.foxworth@pottersquill.com>
Peyton-Spencer added a commit to omniaura/nanoclaw that referenced this pull request Feb 16, 2026
…crashes

Adopted from upstream PR qwibitai#243 by pottertech (Skip Potter):
qwibitai#243

Fixes issue qwibitai#221 - Unhandled promise rejections crash the entire process

Changes:
1. Add module-level unhandledRejection handler (prevents process crashes)
2. Add module-level uncaughtException handler (graceful shutdown)
3. Move error handler registration from main() to module level
4. Wrap streaming output callback in try/catch (prevents rejection propagation)
5. Connect shutdown function for error handlers to call

Impact:
- Prevents process crashes from unhandled rejections
- Enables graceful shutdown on uncaught exceptions
- Improves error recovery in streaming callbacks
- Maintains service availability during agent errors

Overlap with our Stability Audit (2026-02-14):
- Our audit identified this as Issue #1 (CRITICAL)
- Upstream PR qwibitai#243 provides production-tested implementation
- This PR supersedes local fixes from audit

Risk: LOW
- Defensive programming only
- No behavior changes to core logic
- Proven in upstream testing

Co-authored-by: Skip Potter <skippotter@Skips-MacBook-Air.local>
Co-authored-by: Brodie Foxworth <brodie.foxworth@pottersquill.com>
Peyton-Spencer added a commit to omniaura/nanoclaw that referenced this pull request Feb 16, 2026
…crashes (#107)

Adopted from upstream PR qwibitai#243 by pottertech (Skip Potter):
qwibitai#243

Fixes issue qwibitai#221 - Unhandled promise rejections crash the entire process

Changes:
1. Add module-level unhandledRejection handler (prevents process crashes)
2. Add module-level uncaughtException handler (graceful shutdown)
3. Move error handler registration from main() to module level
4. Wrap streaming output callback in try/catch (prevents rejection propagation)
5. Connect shutdown function for error handlers to call

Impact:
- Prevents process crashes from unhandled rejections
- Enables graceful shutdown on uncaught exceptions
- Improves error recovery in streaming callbacks
- Maintains service availability during agent errors

Overlap with our Stability Audit (2026-02-14):
- Our audit identified this as Issue #1 (CRITICAL)
- Upstream PR qwibitai#243 provides production-tested implementation
- This PR supersedes local fixes from audit

Risk: LOW
- Defensive programming only
- No behavior changes to core logic
- Proven in upstream testing

Co-authored-by: Skip Potter <skippotter@Skips-MacBook-Air.local>
Co-authored-by: Brodie Foxworth <brodie.foxworth@pottersquill.com>
@TomGranot
Copy link
Copy Markdown
Collaborator

Heads up — PR #242 also addresses issue #221. You might want to compare approaches and see what each can learn from the other.

@TomGranot
Copy link
Copy Markdown
Collaborator

@gavrielc — Duplicate of #242 — both fix issue #221. See my comparison comment on #242.

@TomGranot
Copy link
Copy Markdown
Collaborator

This was already fixed in #355 (merged). The .catch() handlers are in place. Thanks though!

@TomGranot TomGranot closed this Mar 5, 2026
aviadr1 referenced this pull request in Garsson-io/nanoclaw Mar 20, 2026
…tion, meta-aggregation (kaizen #243, #245, #246)

Three improvements to kaizen skills that share a root cause: the reflection
and analysis system was too abstract and too trusting of cached state.

1. **#246 — Concrete-to-abstract ladder** (highest leverage): Replace 4
   abstract meta-reflection questions ("Are the skills asking the right
   questions?") with a 5-step concrete-to-abstract ladder that starts with
   specific friction and zooms out to mechanism design. Each step includes
   a concrete example from a real incident.

2. **#243 — Git-log verification** (quickest win): Gap analysis must now
   verify each recommendation against `git log` and merged PRs before
   declaring it low-hanging fruit. Prevents the stale-recommendation
   problem where already-fixed issues waste investigation time.

3. **#245 — Meta-finding aggregation** (foundational): New Phase 2.5 in
   gap-analysis that scans recent PR bodies for KAIZEN_IMPEDIMENTS,
   extracts type:"meta" findings, and reports patterns across sessions.
   Surfaces systemic friction that individual reflections miss.

Zero hook changes — all modifications are in skill SKILL.md files only.
The existing hook infrastructure (kaizen-reflect.sh, pr-kaizen-clear.sh)
already supports the type:"meta" schema and doesn't embed the reflection
questions that changed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
aviadr1 referenced this pull request in Garsson-io/nanoclaw Mar 20, 2026
…tion, meta-aggregation (kaizen #243, #245, #246) (#228)

Three improvements to kaizen skills that share a root cause: the reflection
and analysis system was too abstract and too trusting of cached state.

1. **#246 — Concrete-to-abstract ladder** (highest leverage): Replace 4
   abstract meta-reflection questions ("Are the skills asking the right
   questions?") with a 5-step concrete-to-abstract ladder that starts with
   specific friction and zooms out to mechanism design. Each step includes
   a concrete example from a real incident.

2. **#243 — Git-log verification** (quickest win): Gap analysis must now
   verify each recommendation against `git log` and merged PRs before
   declaring it low-hanging fruit. Prevents the stale-recommendation
   problem where already-fixed issues waste investigation time.

3. **#245 — Meta-finding aggregation** (foundational): New Phase 2.5 in
   gap-analysis that scans recent PR bodies for KAIZEN_IMPEDIMENTS,
   extracts type:"meta" findings, and reports patterns across sessions.
   Surfaces systemic friction that individual reflections miss.

Zero hook changes — all modifications are in skill SKILL.md files only.
The existing hook infrastructure (kaizen-reflect.sh, pr-kaizen-clear.sh)
already supports the type:"meta" schema and doesn't embed the reflection
questions that changed.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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