Skip to content

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Sep 30, 2025

Summary by CodeRabbit

  • New Features

    • Automatically connects before sending if not already connected.
    • Adds automatic reconnection with a single retry on failed sends.
    • Surfaces clear errors if a second send attempt fails.
  • Bug Fixes

    • Ensures consistent session ID handling across different session formats.
    • Corrects backoff timing for synchronous clients for predictable retries.
    • Validates host and port earlier to prevent invalid connection attempts.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors Client connectivity and I/O flow: inline host/port validation in connect, unified session ID extraction in query, pre-send connectivity check with single retry on failure in send, adjusted backoff casting in receive, and explicit reconnection/error handling alignment across send/receive paths.

Changes

Cohort / File(s) Summary
Client connectivity and I/O flow
src/Client.php
- connect(): Inline host/port checks replace closure-based validation
- query(): Centralized raw-to-hex sessionId conversion for array/object sessions
- send(): Ensure connected before send; on failure close→reconnect→retry once; throw on second failure
- receive(): Sync backoff sleep cast to int; coroutine backoff unchanged
- Added explicit reconnection/error handling aligning send/receive and session handling

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Client
  participant Conn as Transport/Socket

  Caller->>Client: send(payload)
  alt not connected
    Client->>Conn: connect(host, port)
    Note right of Client: Inline host/port validation
  end
  Client->>Conn: write(payload)
  alt write fails
    Client->>Conn: close()
    Client->>Conn: connect(host, port)
    Client->>Conn: write(payload)  %% single retry
    alt retry fails
      Client-->>Caller: throw error
    else retry succeeds
      Client-->>Caller: return
    end
  else write succeeds
    Client-->>Caller: return
  end
Loading
sequenceDiagram
  autonumber
  actor Caller
  participant Client
  participant Conn as Transport/Socket

  Caller->>Client: query(request)
  Client->>Client: extract raw sessionId
  Client->>Client: convert to hex once (array/object)
  Client->>Conn: write(request)
  Client->>Conn: read()
  alt sync client
    Client->>Client: backoff sleep (int cast)
  else coroutine client
    Note over Client: Backoff unchanged
  end
  Client-->>Caller: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my whiskers, tap the wire—
A hop, a drop, a quick re-fire.
If first send slips, I spring anew,
Reconnect trails where packets flew.
Session seeds in hex now gleam,
Backoffs nap in integer dream.
Thump-thump—my client’s back on stream.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-client-updates

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9c9c2e and c38b5c6.

📒 Files selected for processing (1)
  • src/Client.php (4 hunks)

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

@abnegate abnegate marked this pull request as ready for review September 30, 2025 12:45
@abnegate abnegate merged commit c1411c4 into main Sep 30, 2025
3 of 4 checks passed
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.

2 participants