Skip to content

fix(runtime): classify expected and unexpected process exits#889

Closed
luoye520ww wants to merge 3 commits into
KunAgent:developfrom
luoye520ww:codex/fix-885-runtime-exit-classification
Closed

fix(runtime): classify expected and unexpected process exits#889
luoye520ww wants to merge 3 commits into
KunAgent:developfrom
luoye520ww:codex/fix-885-runtime-exit-classification

Conversation

@luoye520ww

@luoye520ww luoye520ww commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

The GUI could treat a delayed exit from an older Kun child as a crash of the current child. Expected settings, provider, health, update, and application shutdowns also lacked a stable reason, making recovery noisy and causing stale callbacks to race with a newly started runtime.

Root cause

Process lifecycle state was tracked by child presence and boolean intentional-stop flags. That could not distinguish generations or classify the reason that initiated a stop. The Linux packaged desktop smoke also dispatched a click while the Xvfb workbench was not necessarily foregrounded, so the extension guest was never created.

Scope

This PR adds generation-aware exit classification and fixes the packaged desktop smoke click race. It does not add Supervisor crash-loop policy; that remains a separate follow-up.

Changes

  • Track each managed child with a monotonic generation, readiness, stop reason, exit code, and signal.
  • Ignore duplicate and stale exit callbacks before they reach Supervisor recovery.
  • Thread explicit stop reasons through app quit, settings/provider changes, health recovery, and update relaunch.
  • Focus the packaged workbench before the CDP mouse click so Linux Xvfb reliably creates the extension guest target.
  • Keep the PR relationship to the broader issue as Part of #885.

Behavior before

An old child exit could trigger recovery for the current child, and expected restarts were reported as unexpected exits. Linux desktop smoke could time out after a visually successful click with only the workbench target present.

Behavior after

Only the active, ready generation with no explicit stop reason can report an unexpected exit. Duplicate and stale callbacks are ignored. The desktop smoke brings the workbench to the foreground before dispatching the contribution click.

Typecheck

npm.cmd run typecheck

Passed locally.

Tests

node --test scripts/smoke-packaged-extension-desktop.test.cjs
npm.cmd exec vitest run src/main/runtime/kun-process-controller.test.ts src/main/kun-runtime-supervisor.test.ts src/main/kun-process.test.ts
npm.cmd run lint -- --quiet
npm.cmd run build

Results: 16 desktop smoke tests passed; 3 Runtime test files / 63 tests passed; lint and build passed.

Actual validation

  • Runtime generation classification, expected stop reasons, stale callbacks, and duplicate exits were exercised with the Runtime controller and Supervisor tests.
  • The packaged desktop smoke helper and its fixture/resource checks were executed locally.
  • A real Linux AppImage launch cannot be executed on this Windows host; the Linux package job remains the authoritative platform validation.

Review performed

  • Functional correctness
  • Generation and shutdown lifecycle
  • Stale callback and duplicate event handling
  • Cross-platform packaging smoke behavior
  • Scope and backward compatibility

Issue

Part of #885

@luoye520ww

Copy link
Copy Markdown
Collaborator Author

The remaining macOS packaged failure is isolated to the desktop smoke guest-target wait; the packaged resource smoke passed, and the same smoke focus change is green on #888. I reran the failed checks to distinguish runner flakiness from a deterministic regression.

@luoye520ww

Copy link
Copy Markdown
Collaborator Author

Correction: GitHub does not allow me to rerun this workflow because the fork token lacks repository admin rights. The failure remains isolated to the macOS desktop guest-target wait; the packaged resource smoke passed, and the same smoke focus change is green on #888.

@luoye520ww

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated runtime recovery PR #947, which passed Typecheck, Linux, macOS, and Windows packaged checks. Closing this duplicate to keep the review surface focused.

@luoye520ww luoye520ww closed this Jul 14, 2026
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.

1 participant