Skip to content

feat: implement WebSocket manager#104

Open
2witstudios wants to merge 3 commits intomainfrom
ppg/issue-79-ws-manager
Open

feat: implement WebSocket manager#104
2witstudios wants to merge 3 commits intomainfrom
ppg/issue-79-ws-manager

Conversation

@2witstudios
Copy link
Owner

Summary

  • Adds WebSocketManager class with URLSessionWebSocketTask for real-time server communication
  • Connection states: disconnected, connecting, connected, reconnecting(attempt: Int)
  • Auto-reconnect with exponential backoff (1s, 2s, 4s, 8s, 16s, 30s max)
  • Keepalive ping every 30s via DispatchSourceTimer
  • Event parsing into typed WebSocketEvent enum: manifest updates, agent/worktree status changes
  • Terminal commands: subscribe, unsubscribe, and input via WebSocketCommand enum
  • Integrates with existing patterns: NotificationCenter, GCD, @unchecked Sendable

Closes #79

Test plan

  • Verify type-checks cleanly with swiftc -typecheck (confirmed)
  • Verify connection lifecycle: connect → connected → disconnect
  • Verify auto-reconnect fires with exponential backoff on connection drop
  • Verify keepalive pings sent every 30s while connected
  • Verify event parsing for manifest_updated, agent_status_changed, worktree_status_changed
  • Verify send commands (subscribe, unsubscribe, terminal_input) serialize correctly
  • Verify intentional disconnect does not trigger reconnect

Observable WebSocket manager using URLSessionWebSocketTask with:
- Connection states: disconnected, connecting, connected, reconnecting
- Exponential backoff reconnect (1s→30s max)
- Keepalive ping every 30s
- Event parsing into typed enums (manifest updates, agent/worktree status)
- Terminal subscribe/unsubscribe/input commands
- NotificationCenter integration matching existing app patterns

Closes #79
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Warning

Rate limit exceeded

@2witstudios has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 34deb69 and 583e545.

📒 Files selected for processing (3)
  • PPG CLI/PPG CLI/WebSocketManager.swift
  • PPG CLI/PPG CLITests/WebSocketManagerTests.swift
  • src/commands/spawn.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ppg/issue-79-ws-manager

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- B2: fix doConnect() guard to reject double-connect (was tautological)
- B1: remove unused closure callbacks (onStateChange/onEvent) for
  consistency with codebase's NotificationCenter-only pattern
- B3: synchronous cleanup in deinit instead of unreliable async dispatch
- T1: thread-safe state reads via queue.sync backing store
- Security: replace manual JSON string interpolation with JSONSerialization
  to prevent injection in channel/agentId fields
- Make parseEvent() internal for testability
- Add WebSocketManagerTests (21 tests covering event parsing, command
  serialization, connection state, and edge cases)
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.

Implement WebSocket manager

1 participant