Skip to content

feat(ipc): define safe error envelope#898

Closed
luoye520ww wants to merge 2 commits into
KunAgent:developfrom
luoye520ww:codex/ipc-error-envelope
Closed

feat(ipc): define safe error envelope#898
luoye520ww wants to merge 2 commits into
KunAgent:developfrom
luoye520ww:codex/ipc-error-envelope

Conversation

@luoye520ww

Copy link
Copy Markdown
Collaborator

Problem

IPC handlers currently have no shared, bounded error envelope. Main-process errors can therefore be serialized inconsistently, and future handlers may accidentally expose stacks or arbitrary objects to the renderer.

Root cause

RuntimeError covers Kun HTTP responses, but it is not a contract for Electron IPC boundaries and does not constrain detail payloads.

Scope

This PR defines the shared IPC error contract only. It does not change existing handler behavior; follow-up PRs will adopt it per IPC domain.

Changes

  • Add AppIpcErrorSchema and AppIpcError in src/shared.
  • Allow only bounded code/message, retryability, optional incident ID, and primitive detail values.
  • Reject stacks, nested objects, unknown fields, oversized strings, and oversized detail maps.
  • Add schema tests for accepted and rejected payloads.

Safety

  • No raw Error stack or arbitrary object can satisfy the contract.
  • Detail values and counts are bounded to prevent oversized IPC payloads.
  • This PR does not alter current IPC handlers or persistence.

Typecheck

npm.cmd run typecheck

Result: passed.

Tests

npm.cmd exec vitest run src/shared/ipc-error.test.ts

Result: 1 file, 3 tests passed.

Actual validation

The targeted test parses a real envelope and rejects stack fields, nested objects, unknown fields, oversized identifiers, and oversized detail maps. npm.cmd run lint and npm.cmd run build also passed.

Review performed

  • Functional correctness
  • Cross-process contract compatibility
  • Secret/stack exposure
  • Payload bounds
  • Backward compatibility (no existing handler behavior changed)
  • Test quality and PR scope

PR size

Production files: 1
Test files: 1
Production LOC: 19
Total diff: 68 lines

Follow-ups

Adopt this envelope in individual main/preload/renderer IPC domains with cancellation and contract snapshot tests.

@luoye520ww

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated IPC/SSE reliability PR #945, 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