-
Notifications
You must be signed in to change notification settings - Fork 0
feat(daemon): add IPC communication and health checks #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: p3-21/daemon/types-lifecycle
Are you sure you want to change the base?
Conversation
c4267ec to
e7c2227
Compare
08412d8 to
8754855
Compare
e7c2227 to
7cb5483
Compare
7cb5483 to
77259f9
Compare
2c791c5 to
dfbbb85
Compare
77259f9 to
445f46f
Compare
Greptile Summary
|
| Filename | Overview |
|---|---|
| packages/daemon/src/ipc.ts | Implements Unix socket IPC communication with message buffering, request-response protocol, and connection lifecycle management |
| packages/daemon/src/health.ts | Health checking framework with parallel execution, error aggregation, and dynamic registration capabilities |
Confidence score: 4/5
- This PR is safe to merge with only minor risks related to IPC implementation complexity
- Score reflects comprehensive test coverage (52 tests) and adherence to project standards, but Unix socket message buffering and error handling logic requires careful review
- Pay close attention to
packages/daemon/src/ipc.tsmessage buffering logic and connection cleanup mechanisms
Sequence Diagram
sequenceDiagram
participant Client as IpcClient
participant Socket as Unix Socket
participant Server as IpcServer
participant Handler as MessageHandler
Client->>Socket: "connect()"
Socket->>Server: "open connection"
Server->>Socket: "accept connection"
Socket->>Client: "connection established"
Client->>Socket: "send(message)"
Socket->>Server: "data received"
Server->>Server: "parse JSON message"
Server->>Handler: "call handler(payload)"
Handler->>Server: "return response"
Server->>Socket: "write JSON response"
Socket->>Client: "response received"
Client->>Client: "resolve pending request"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6 files reviewed, 4 comments
| expect(daemon.state).toBe("stopped"); | ||
| // The daemon should have handled the timeout gracefully | ||
| // Either returning an error or completing anyway | ||
| expect(result.isOk() || result.isErr()).toBe(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: This assertion doesn't verify the expected behavior - should check for specific timeout error rather than accepting any result
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/daemon/src/__tests__/lifecycle.test.ts
Line: 382:382
Comment:
**logic:** This assertion doesn't verify the expected behavior - should check for specific timeout error rather than accepting any result
How can I resolve this? If you propose a fix, please make it concise.| const client = createIpcClient(socketPath); | ||
| await client.connect(); | ||
|
|
||
| const response = await client.send<{ echo: string }>({ hello: "world" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Type annotation inconsistent - expecting { echo: string } but receiving { echo: object }
| const response = await client.send<{ echo: string }>({ hello: "world" }); | |
| const response = await client.send<{ echo: object }>({ hello: "world" }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/daemon/src/__tests__/ipc.test.ts
Line: 216:216
Comment:
**logic:** Type annotation inconsistent - expecting `{ echo: string }` but receiving `{ echo: object }`
```suggestion
const response = await client.send<{ echo: object }>({ hello: "world" });
```
How can I resolve this? If you propose a fix, please make it concise.| it("handles malformed messages gracefully", async () => { | ||
| const socketPath = join(testDir, "test.sock"); | ||
| const server = createIpcServer(socketPath); | ||
|
|
||
| server.onMessage(async (msg) => { | ||
| return { received: msg }; | ||
| }); | ||
|
|
||
| await server.listen(); | ||
|
|
||
| // Server should handle invalid JSON without crashing | ||
| // This test verifies robustness | ||
|
|
||
| const client = createIpcClient(socketPath); | ||
| await client.connect(); | ||
|
|
||
| // Valid message should still work | ||
| const response = await client.send<{ received: unknown }>({ valid: true }); | ||
| expect(response.received).toEqual({ valid: true }); | ||
|
|
||
| client.close(); | ||
| await server.close(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Test doesn't actually verify malformed message handling - only sends valid JSON. Should this test send actual malformed JSON to verify the server handles it gracefully?
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/daemon/src/__tests__/ipc.test.ts
Line: 394:416
Comment:
**logic:** Test doesn't actually verify malformed message handling - only sends valid JSON. Should this test send actual malformed JSON to verify the server handles it gracefully?
How can I resolve this? If you propose a fix, please make it concise.
packages/daemon/src/ipc.ts
Outdated
| }, | ||
|
|
||
| close(): void { | ||
| if (!isConnected && !socket) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Logic should use OR (||) instead of AND (&&) - function should return early if already disconnected
| if (!isConnected && !socket) return; | |
| if (!isConnected || !socket) return; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/daemon/src/ipc.ts
Line: 412:412
Comment:
**logic:** Logic should use OR (||) instead of AND (&&) - function should return early if already disconnected
```suggestion
if (!isConnected || !socket) return;
```
How can I resolve this? If you propose a fix, please make it concise.dfbbb85 to
2f370ee
Compare
445f46f to
c054bed
Compare
|
IPC framing is buffered per-connection: server/client accumulate into a buffer, split on newlines, and only JSON.parse complete frames. Pre-push tests passed. |
2f370ee to
a1e44c2
Compare
c054bed to
4ea0f4d
Compare
|
Restacked after downstack update (formatRelative test stabilization); no additional changes in this PR. |
Add daemon communication and monitoring infrastructure: - createIpcServer(): Unix socket server with JSON protocol - createIpcClient(): Client for sending requests to daemon - createHealthChecker(): Parallel health check execution - Request/response protocol with timeouts - Handler registration for custom IPC commands - Health status aggregation with pass/fail thresholds - Comprehensive test coverage (52 tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
a1e44c2 to
19a7f81
Compare
4ea0f4d to
1bf4162
Compare
|
Addressed greptile notes: tightened shutdown timeout assertion, corrected typed IPC response shape, added malformed JSON coverage via raw socket, and fixed client close guard to return when disconnected. Restacked and resubmitted. |

Add daemon communication and monitoring infrastructure:
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
Contributes to #56