Skip to content

Conversation

@galligan
Copy link
Contributor

@galligan galligan commented Jan 23, 2026

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

Contributes to #56

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Implements comprehensive IPC communication infrastructure with Unix socket server/client for daemon processes
  • Adds parallel health check execution system with status aggregation and dynamic registration
  • Creates structured daemon package API with proper TypeScript contracts and TDD-first implementation approach

Important Files Changed

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.ts message 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"
Loading

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

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);
Copy link

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" });
Copy link

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 }

Suggested change
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.

Comment on lines 394 to 433
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();
});
Copy link

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.

},

close(): void {
if (!isConnected && !socket) return;
Copy link

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

Suggested change
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.

@galligan galligan changed the base branch from p3-21/daemon/types-lifecycle to graphite-base/84 January 23, 2026 21:55
@galligan galligan force-pushed the p3-22/daemon/ipc-health branch from 445f46f to c054bed Compare January 23, 2026 21:58
@galligan galligan changed the base branch from graphite-base/84 to p3-21/daemon/types-lifecycle January 23, 2026 21:58
@galligan
Copy link
Contributor Author

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.

@galligan galligan force-pushed the p3-21/daemon/types-lifecycle branch from 2f370ee to a1e44c2 Compare January 23, 2026 23:09
@galligan galligan force-pushed the p3-22/daemon/ipc-health branch from c054bed to 4ea0f4d Compare January 23, 2026 23:09
@galligan
Copy link
Contributor Author

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>
@galligan galligan changed the base branch from p3-21/daemon/types-lifecycle to graphite-base/84 January 24, 2026 03:08
@galligan galligan force-pushed the p3-22/daemon/ipc-health branch from 4ea0f4d to 1bf4162 Compare January 24, 2026 03:14
@galligan galligan changed the base branch from graphite-base/84 to p3-21/daemon/types-lifecycle January 24, 2026 03:14
@galligan
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants