Skip to content

Pubsub: let a queue subscribe to the same topic more than once - #168

Merged
aviator-app[bot] merged 2 commits into
mainfrom
rjh.pubsub-idempotent-subscribe
Sep 14, 2026
Merged

aviator-app[bot] merged 2 commits into
mainfrom
rjh.pubsub-idempotent-subscribe

Conversation

@rjhuijsman

@rjhuijsman rjhuijsman commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Before this PR, PubSub's Topic.Subscribe appended to state.queue_ids without checking whether that queue was already subscribed, so subscribing the same queue to a topic twice left a duplicate entry. Topic.Broker fans out over state.queue_ids, so the duplicate made it call Enqueue on that one queue twice using a single context, which Reboot refuses:

ValueError: To call 'rbt.std.collections.queue.v1.QueueMethods.Enqueue' of 'receiving-queue' more than once using the same context an idempotency alias or key must be specified

The broker then retried with backoff forever, so the topic never drained. Depending on the situation it may be a race — a second Subscribe must land before the topic is drained — so this was seen as a flake in //tests/reboot/std/pubsub/v1:test_pubsub_tests_ts in this CI job on an unrelated PR.

This commit makes it so that a second Subscribe does nothing.

TESTED: new unit test.

@aviator-app

aviator-app Bot commented Sep 11, 2026

Copy link
Copy Markdown

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator (commit 60e8db2).


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@rjhuijsman
rjhuijsman force-pushed the rjh.pubsub-idempotent-subscribe branch from a380f1c to a1bc2a1 Compare September 11, 2026 20:43
@rjhuijsman
rjhuijsman marked this pull request as ready for review September 11, 2026 20:46
@rjhuijsman
rjhuijsman requested review from benh and katfang and removed request for katfang September 11, 2026 20:46
@rjhuijsman rjhuijsman self-assigned this Sep 11, 2026
@rjhuijsman rjhuijsman changed the title Let a queue subscribe to the same topic more than once Pubsub: let a queue subscribe to the same topic more than once Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Comment thread reboot/std/pubsub/v1/pubsub.py Outdated
rjhuijsman and others added 2 commits September 14, 2026 09:24
`Topic.Subscribe` appended to `state.queue_ids` unconditionally, so
subscribing the same queue to the same topic twice left a duplicate
entry. `Topic.Broker` fans out over those ids, so a duplicate made it
call `Enqueue` on one queue twice using a single `context`, which
Reboot refuses:

  ValueError: To call
  'rbt.std.collections.queue.v1.QueueMethods.Enqueue' of
  'receiving-queue' more than once using the same context an
  idempotency alias or key must be specified

The broker then retried with backoff forever and the topic never
drained. That only happened when a second `Subscribe` landed before
the broker had drained the topic, so it surfaced as a timeout under
load: `//tests/reboot/std/pubsub/v1:test_pubsub_tests_ts` hit its
300s deadline in
https://github.com/reboot-dev/reboot/actions/runs/34603229734/job/103275784303

`Subscribe` now skips a queue id the topic already carries, and
`Broker` deduplicates the ids before fanning out, so a topic whose
state accumulated duplicates before this fix drains instead of
retrying forever.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TQxdTEi8qsBfxCcuLxrNmQ
Co-authored-by: Benjamin Hindman <benjamin.hindman@gmail.com>
@aviator-app
aviator-app Bot force-pushed the rjh.pubsub-idempotent-subscribe branch from 99c28c3 to 80bc24d Compare September 14, 2026 09:24
@github-actions

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@aviator-app
aviator-app Bot merged commit 60e8db2 into main Sep 14, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants