Skip to content

fix(interfaces): address read queue review feedback - #3965

Draft
EmilyRagan wants to merge 4 commits into
interface_reads_and_metricsfrom
interface_reads_review_fixes
Draft

EmilyRagan wants to merge 4 commits into
interface_reads_and_metricsfrom
interface_reads_review_fixes

Conversation

@EmilyRagan

Copy link
Copy Markdown
Contributor

What changed

Follow-up to #3902 addressing its review comments, in four commits:

  • Timestamp queued reads with arrival time. The read thread now queues the time of each read with the data. Interface#read uses it as the packet received_time when a protocol hasn't set one, and read_interface_base uses it for the raw data time. Before this, both reflected dequeue time and could lag arrival by the full backlog. Ruby and Python.
  • Per-thread cancellation in Ruby. Replaced the shared @raw_read_cancel flag with closing each thread's own queue under the mutex. read_queue_pop only decrements the counters while its queue is still current. This matches Python's per-thread cancel_event and stops a thread that survives kill_thread from reading the new stream.
  • Python ReadQueue.__init__. The read queue is now set up in ReadQueue.__init__. Subclasses no longer need to remember initialize_read_queue().
  • Docs. Added a memory sizing note (the limit applies per queue, and the TCP/IP server has one queue per client) and a note that disconnect can wait up to 2s when a custom stream's disconnect doesn't unblock a pending read.

Why it changed

Review feedback on #3902.

Not addressed here:

Testing strategy

  • New Ruby and Python specs for arrival timestamps and inline reads, plus a Ruby spec for a read thread that survives being stopped.
  • Updated the fixed protocol specs, since unknown packets now carry the read time.
  • Ran bundle exec rspec spec/interfaces spec/utilities: 890 examples, 0 failures.
  • Ran pytest test/interfaces test/utilities test/microservices: 688 passed. One failure, test_raises_a_timeout_when_unable_to_connect, also fails on the base branch locally.

🤖 Generated with Claude Code

EmilyRagan and others added 4 commits September 30, 2026 15:34
The Ruby ReadQueue shared one @raw_read_cancel flag that
start_read_queue_thread reset. A read thread that survived both the join
and kill_thread would see the reset flag, do one more read on the new
stream and lose that data. A late read_queue_pop could also drive the
byte counters negative.

Each thread is now cancelled by closing its own queue under the mutex,
and the pop only decrements the counters while its queue is still
current, matching the per-thread cancel event used by Python.

Addresses PR #3902 review feedback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ReadQueue relied on every subclass remembering to call
initialize_read_queue(). A custom subclass that forgot would only fail
later with an AttributeError on _read_queue_condition. ReadQueue now
initializes the queue in its own __init__, so subclasses only need to
call super().__init__().

Addresses PR #3902 review feedback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the read queue, received_time and the raw data time were set when
data came off the queue, so with up to READ_QUEUE_MAX_SIZE backed up
they could trail the real arrival time by however long the backlog took
to drain.

The read thread now queues the time of each read alongside the data.
Interface#read applies it as the packet received_time (when a protocol
hasn't set one) and read_interface_base uses it for the raw data time.
This makes timestamps more accurate than inline reads while the queue is
backed up. Inline reads (READ_QUEUE_MAX_SIZE 0) are unchanged. Applies to
both Ruby and Python.

Addresses PR #3902 review feedback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
READ_QUEUE_MAX_SIZE applies per queue and the TCP/IP server has one
queue per client, so memory scales with the number of clients and all
interfaces in a container share it. Add a sizing note with an example.

Also document that disconnect waits up to 2 seconds for the read thread
when a custom stream's disconnect doesn't unblock a pending read. In Ruby
the thread is then killed with a warning; in Python it is left blocked
until its read returns. Tell custom stream authors to wake pending reads.

Addresses PR #3902 review feedback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.79%. Comparing base (0d3c237) to head (0e549d2).

Additional details and impacted files
@@                       Coverage Diff                       @@
##           interface_reads_and_metrics    #3965      +/-   ##
===============================================================
- Coverage                        80.29%   79.79%   -0.50%     
===============================================================
  Files                              903      903              
  Lines                            68675    68424     -251     
  Branches                          2645     2686      +41     
===============================================================
- Hits                             55141    54600     -541     
- Misses                           12867    13156     +289     
- Partials                           667      668       +1     
Flag Coverage Δ
frontend 66.59% <ø> (-0.41%) ⬇️
python 79.71% <ø> (-0.56%) ⬇️
ruby-api 82.13% <ø> (-0.38%) ⬇️
ruby-backend 85.41% <100.00%> (-0.51%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
Code smells with severity Critical found (required < Major)

See analysis details on SonarQube Cloud

@EmilyRagan
EmilyRagan requested a review from ryanmelt September 30, 2026 22:26
@EmilyRagan EmilyRagan self-assigned this Sep 30, 2026
@EmilyRagan

Copy link
Copy Markdown
Contributor Author

@ryanmelt the python CI failure here is already addressed in main, so you should update your branch with main

This branch has not been deployed

No deployments
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