Skip to content

fix: make unregister idempotent - #25

Merged
johnnyluo merged 2 commits into
mainfrom
fix/websocket-origin-and-stream
Apr 27, 2026
Merged

fix: make unregister idempotent#25
johnnyluo merged 2 commits into
mainfrom
fix/websocket-origin-and-stream

Conversation

@rcoderdev

@rcoderdev rcoderdev commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Treat unregister operations as idempotent: no matching row returns success (aligned with 200 OK in API).
  • Document idempotent 200 OK for unregister in README.

Summary by CodeRabbit

  • Bug Fixes

    • Device unregistration endpoints are now idempotent; repeated deletion calls succeed even when no matching device exists.
  • Documentation

    • Updated DELETE /unregister endpoint documentation to clarify the idempotent 200 OK response behavior.

@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown

Walkthrough

The pull request updates the unregister functionality to be idempotent. The API documentation is revised to explicitly note that DELETE /unregister returns 200 OK even when no matching device exists. The corresponding implementation changes remove error returns for "no rows deleted" scenarios in three unregistration methods.

Changes

Cohort / File(s) Summary
Documentation Update
README.md
Updated DELETE /unregister endpoint description to explicitly document idempotent behavior where repeated calls succeed regardless of device existence.
Unregistration Methods
storage/database.go
Modified UnregisterDevice, UnregisterDeviceByParty, and UnregisterDeviceByPartyAndToken to return nil (success) when no rows are deleted instead of returning "no device found" errors. Database operation errors are still reported normally.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: make unregister idempotent' directly and accurately describes the main change: modifying unregister operations to be idempotent by treating no matching rows as success.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/websocket-origin-and-stream

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

@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.

🧹 Nitpick comments (1)
storage/database.go (1)

102-103: Add regression tests for no-row delete paths across all unregister variants.

Given this semantic change, add tests that assert success when nothing matches for UnregisterDevice, UnregisterDeviceByParty, and UnregisterDeviceByPartyAndToken.

Also applies to: 123-124, 148-149

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@storage/database.go` around lines 102 - 103, Add regression tests that
exercise the "no-row" delete paths for UnregisterDevice,
UnregisterDeviceByParty, and UnregisterDeviceByPartyAndToken: for each function
call it against a non-existent device/party/token (ensure DB pre-state has no
matching row) and assert the call returns success (no error) and leaves DB
unchanged; reuse existing test helpers/fixtures to create a clean DB or
transaction, call
UnregisterDevice/UnregisterDeviceByParty/UnregisterDeviceByPartyAndToken with
values that won't match any row, and add assertions that error == nil and row
counts remain the same to prevent regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@storage/database.go`:
- Around line 102-103: Add regression tests that exercise the "no-row" delete
paths for UnregisterDevice, UnregisterDeviceByParty, and
UnregisterDeviceByPartyAndToken: for each function call it against a
non-existent device/party/token (ensure DB pre-state has no matching row) and
assert the call returns success (no error) and leaves DB unchanged; reuse
existing test helpers/fixtures to create a clean DB or transaction, call
UnregisterDevice/UnregisterDeviceByParty/UnregisterDeviceByPartyAndToken with
values that won't match any row, and add assertions that error == nil and row
counts remain the same to prevent regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ac9d665d-3f86-4668-afd3-96b917133a7c

📥 Commits

Reviewing files that changed from the base of the PR and between 08ea47c and 0c9c80c.

📒 Files selected for processing (2)
  • README.md
  • storage/database.go

@rcoderdev
rcoderdev marked this pull request as draft April 25, 2026 06:43
@rcoderdev
rcoderdev marked this pull request as ready for review April 27, 2026 03:52

@johnnyluo johnnyluo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@johnnyluo
johnnyluo merged commit d00489b into main Apr 27, 2026
2 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