Skip to content

Add connection-pool observability, release 0.6.0 - #28

Merged
callumreid merged 2 commits into
mainfrom
callum/sdk-connection-observability
Jul 30, 2026
Merged

Add connection-pool observability, release 0.6.0#28
callumreid merged 2 commits into
mainfrom
callum/sdk-connection-observability

Conversation

@callumreid

Copy link
Copy Markdown
Collaborator

Makes the SDK's connection reuse visible, so the next report of intermittent timeouts can be answered with evidence instead of inference.

Why

A request that dies in transit never reaches API Gateway, so there is no server-side trace of it. During the Upstart investigation that left us diagnosing from a single log correlation plus a locally reconstructed repro. If they report another timeout on 0.5.0 today, we still cannot tell whether idle expiry engaged.

What

Countersclient.connection_stats:

coval.connection_stats.as_dict()
# {'opened': 1, 'reused': 12, 'expired': 3}

opened = new connection created, reused = pooled connection still inside the idle bound, expired = discarded for being too old. Thread-safe, and repr() is formatted for pasting into a ticket.

Debug log on each expiry, naming the host and the exact idle duration:

coval_sdk.client DEBUG coval-sdk: discarding pooled connection to 127.0.0.1 after 1.51s idle (max_idle_seconds=1.00)

Enabled with logging.getLogger("coval_sdk.client").setLevel(logging.DEBUG).

Counters are None when max_idle_seconds=None, since the pool is then left entirely to urllib3.

Verified end to end

Against a local keep-alive server:

step connection_stats
three rapid requests {'opened': 1, 'reused': 2, 'expired': 0}
after 1.5s idle, one more (bound 1.0s) {'opened': 1, 'reused': 2, 'expired': 1}

The counters track reality in both directions — reuse when warm, expiry when stale.

Also

README gains a "Connection reuse" and a "Diagnosing timeouts" section, since none of this helps if customers don't know it exists.

Version bumped to 0.6.0 in this PR rather than a follow-up. #26 shipped without a bump and needed #27 purely to make it releasable.

31 tests passing. New coverage: counters start at zero, absent when expiry is disabled, count each outcome correctly, and the debug log fires with the right idle duration.

Note

No Linear issue — the Linear MCP isn't reachable from this session and there's no API key on disk, so I couldn't file one. Worth attaching a ticket before merge if you want it tracked.

A request that dies in transit never reaches the server, so when a customer
reports intermittent timeouts there is nothing on our side to look at. That was
the position we were in with the Upstart investigation -- the diagnosis rested
on one log correlation and a local reconstruction.

Adds counters (client.connection_stats -> opened / reused / expired) and a debug
log naming the host and exact idle duration each time a connection is discarded.
Enough for support to ask "paste your connection_stats" and know immediately
whether idle expiry is engaging.

Counters are thread-safe and only present when expiry is enabled; with
max_idle_seconds=None the pool is left entirely to urllib3.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@callumreid, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b95a4c3-3bbc-4730-a156-c0bdf3447cf6

📥 Commits

Reviewing files that changed from the base of the PR and between 09d69f2 and e65f461.

📒 Files selected for processing (3)
  • python-sdk/README.md
  • python-sdk/src/coval_sdk/client.py
  • python-sdk/tests/test_client.py

Walkthrough

The Python SDK now records pooled connection outcomes as opened, reused, or expired when idle expiry is enabled. Statistics are thread-safe, exposed through the client, and accompanied by debug logging and documentation for diagnosing timeouts. Tests cover counter behavior, disabled expiry, and eviction logs. Package metadata, version constants, user-agent text, and debug output are updated to version 0.6.0.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: connection-pool observability and the 0.6.0 release bump.
Description check ✅ Passed The description is directly about the SDK connection-pool observability, timeout diagnostics, and version bump.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python-sdk/src/coval_sdk/client.py`:
- Around line 104-121: Count the replacement connection created after an expired
pooled connection as opened: update the expiry branch in _ConnectionPool.get to
record both expired and opened while preserving the existing close behavior.
Update the expiry-related assertions in python-sdk/tests/test_client.py lines
223-241 and revise the connection-statistics wording in python-sdk/README.md
lines 77-78 to reflect that opened counts these replacement physical
connections.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: df96fa39-2bd0-4dcc-9dbd-47f693e207a5

📥 Commits

Reviewing files that changed from the base of the PR and between feb489f and 09d69f2.

📒 Files selected for processing (7)
  • python-sdk/README.md
  • python-sdk/pyproject.toml
  • python-sdk/src/coval_sdk/__init__.py
  • python-sdk/src/coval_sdk/api_client.py
  • python-sdk/src/coval_sdk/client.py
  • python-sdk/src/coval_sdk/configuration.py
  • python-sdk/tests/test_client.py

Comment thread python-sdk/src/coval_sdk/client.py
CodeRabbit correctly spotted that `opened` under-reports physical connections:
an expired connection is closed and then transparently reconnects, so it costs a
handshake that no counter surfaced. Confirmed against a real server -- one
expiry produced two accepted sockets while `opened` read 1.

Kept the three counters as disjoint per-checkout outcomes rather than folding
replacements into `opened`, so exactly one is incremented per pool checkout and
they still total the number of checkouts. Added `connections_established`
(opened + expired) for the physical count, and corrected the README, which
described `opened` as "connections created".

The new test asserts against sockets the server actually accepted, not just the
counters agreeing with themselves.
@callumreid
callumreid merged commit 152e133 into main Jul 30, 2026
5 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.

1 participant