Skip to content

fix: complete only the open entry for a reused requestId - #250

Merged
easyhooon merged 1 commit into
mainfrom
fix/response-overwrites-shared-request-id
Oct 27, 2026
Merged

easyhooon merged 1 commit into
mainfrom
fix/response-overwrites-shared-request-id

Conversation

@easyhooon

@easyhooon easyhooon commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Close #248

Problem

A response completed every entry that shared its requestId, tag and direction. Bridges that pass a callback name as the id (getToken("onTokenResult") twice) had all earlier entries rewritten with the latest response, status and timestamp.

Cause

MessageRepository.update() transformed every matching entry in memory, and MessageDao.updateByRequestId did the same in SQL.

Fix

  • A response now completes one entry per direction: the latest IN_PROGRESS match, or else the latest match with no response yet (keeps recording late responses for fire-and-forget entries). With neither, it updates nothing, so a late or duplicate response no longer rewrites a completed call.
  • Latest rather than oldest, so a request that never got an answer (page navigated away, or left open by a previous session) doesn't take the next call's response. Concurrent calls sharing one id still can't be told apart.
  • The DB row is updated by primary key (MessageDao.updateResponse, replacing updateByRequestId). A temp id resolves to its DB id through wireIds.
  • addEntry's insert and update's write are now queued while holding lock, so a response arriving on another thread can't queue its DB update before the insert and get dropped.

Public API is unchanged; the DAO is internal and the Room schema is the same.

Verification

  • New MessageRepositoryReusedIdTest (Robolectric, in-memory Room), checked in memory and in the DB: serial calls keep their own responses; an unanswered request doesn't take the next response; a late duplicate leaves completed calls alone; a fire-and-forget entry still records its response; a row left open by a previous repository instance doesn't take the new call's response.
  • The first three fail on main.
  • ./gradlew :dari-runtime:testDebugUnitTest passes (28 tests), and the pre-push detekt + ktlintCheck pass. androidTest was not run.

Summary by CodeRabbit

  • Bug Fixes
    • Responses are now recorded against the correct call when request IDs are reused, including when calls finish in sequence or an earlier call remains unanswered.
    • Late duplicate responses no longer overwrite completed calls, and responses can still be recorded for calls that begin in a completed state.
    • Call updates are saved consistently, keeping displayed entries and stored history in sync.

Bridges that pass a callback name as the id had every past entry rewritten by each response. Closes #248.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between fbbca27 and 3b96335.

Files selected for processing: 3
  • dari-runtime/src/main/kotlin/com/easyhooon/dari/data/MessageRepository.kt
  • dari-runtime/src/main/kotlin/com/easyhooon/dari/data/local/MessageDao.kt
  • dari-runtime/src/test/kotlin/com/easyhooon/dari/data/MessageRepositoryReusedIdTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

MessageRepository now selects a single response target per direction and updates persisted rows by entry ID. New tests cover reused request IDs, unanswered entries, duplicate responses, fire-and-forget entries, and calls left open across repository sessions.

Changes: Response Matching

Layer / File(s) Summary
Response target selection and persistence
dari-runtime/src/main/kotlin/com/easyhooon/dari/data/MessageRepository.kt, dari-runtime/src/main/kotlin/com/easyhooon/dari/data/local/MessageDao.kt, dari-runtime/src/test/kotlin/com/easyhooon/dari/data/MessageRepositoryReusedIdTest.kt
MessageRepository selects the latest matching IN_PROGRESS entry per direction, or the latest entry without a response timestamp if none is IN_PROGRESS. It emits updates for selected entries and queues database updates by persisted ID. Tests compare in-memory entries with persisted results across reused-ID scenarios.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant MessageRepository
  participant MessageDao
  participant RoomDatabase
  MessageRepository->>MessageRepository: Select response targets and resolve persisted IDs
  MessageRepository->>MessageDao: Queue response updates by entry ID
  MessageDao->>RoomDatabase: Update row by ID
Loading

Possibly related issues

Merge Risk: Minimal · up to 3b963

The response-matching change has no identified issue that needs resolution before merging. Concurrent calls sharing an ID remain an acknowledged limitation.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Issue #248 requires a response to update only the latest matching IN_PROGRESS entry. If no matching entry is IN_PROGRESS, the response must be dropped. MessageRepository.responseTargets() instea… Remove the no-response fallback from responseTargets() so it returns no target when no matching entry is IN_PROGRESS. Update the affected fire-and-forget test and behavior to match issue #248.
Docstring Coverage Warning Docstring coverage is 26.32% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: completing only the open entry when a request ID is reused. It matches the repository and test changes.
Out of Scope Changes check Passed The changes stay within the reused-requestId response handling in issue #248. The repository selection logic, primary-key DAO update, lock-ordered writes, and focused tests support correct response ta…
Full details: Out of Scope Changes check

Explanation

The changes stay within the reused-requestId response handling in issue #248. The repository selection logic, primary-key DAO update, lock-ordered writes, and focused tests support correct response targeting and persistence. No unrelated product or public API changes are shown.

Full details: Linked Issues check

Explanation

Issue #248 requires a response to update only the latest matching IN_PROGRESS entry. If no matching entry is IN_PROGRESS, the response must be dropped. MessageRepository.responseTargets() instead falls back to matches.lastOrNull { responseTimestamp == null }. The new fire-and-forget test confirms this behavior, so the implementation does not meet the linked issue requirement.

Resolution

Remove the no-response fallback from responseTargets() so it returns no target when no matching entry is IN_PROGRESS. Update the affected fire-and-forget test and behavior to match issue #248.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@easyhooon
easyhooon merged commit 1d6afae into main Oct 27, 2026
4 checks passed
@easyhooon
easyhooon deleted the fix/response-overwrites-shared-request-id branch October 27, 2026 02:31
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.

fix: a response overwrites every entry that shares its requestId

1 participant