Skip to content

refactor(sdk): drop unused incrementedUnread payload from ChatMessageAppendOutcome#121

Merged
variablefate merged 2 commits into
mainfrom
refactor/drop-unread-payload
May 12, 2026
Merged

refactor(sdk): drop unused incrementedUnread payload from ChatMessageAppendOutcome#121
variablefate merged 2 commits into
mainfrom
refactor/drop-unread-payload

Conversation

@variablefate
Copy link
Copy Markdown
Owner

Re-opening: original PR #119 was auto-closed by GitHub when its base branch (`chore/renumber-adr-chat-message-store`) was deleted on PR #118 merge. Rebased cleanly onto main.

Summary

The `.inserted(incrementedUnread:)` payload was a hypothetical-haptic-decision feature that turned out unused. `ChatCoordinator.handleChatEvent` only matches `case .inserted` — it never reads the payload. Tests that exercised the unread side effect also assert `store.unreadCount` directly, which is the canonical source.

Drop the payload. The enum becomes:

```swift
public enum ChatMessageAppendOutcome: Equatable, Sendable {
case duplicate
case inserted
}
```

First-principles

State changes should be observable through their canonical source, not via return-value side channels. `unreadCount` IS the canonical source. The payload was duplicating it. Dropping it eliminates duplication without losing information.

Changes

  • `ChatMessageStore.swift`: enum simplified; `append(_:)` returns `.inserted` unconditionally on insert (the unread update logic itself is unchanged).
  • `ChatMessageStoreTests.swift`: every `.inserted(incrementedUnread: ...)` rewritten to `.inserted`. `unreadCutoffSuppressesReplayedHistory` gets an explicit `store.unreadCount == 0` check after the stale append so the suppression assertion isn't implicit through the final-count math.
  • `decisions/0020-chat-message-store.md`: Decision item 5 reframed; Rationale's "Append outcome enum" section rewritten; Alternatives-Considered gets a new bullet covering the dropped payload.

Test plan

  • `swift test --filter ChatMessageStoreTests` — 21/21 pass
  • `xcodebuild test -scheme RoadFlareTests` — TEST SUCCEEDED (all app + SDK tests)
  • Confirmed `ChatCoordinator.handleChatEvent` haptic semantics unchanged

No protocol-surface impact (Kind 3178 wire format unchanged).

…AppendOutcome

The .inserted associated value was added to support a haptic-decision use
case that turned out not to need it. ChatCoordinator.handleChatEvent only
ever pattern-matches on `case .inserted` for the haptic — it never reads
the payload. Tests that exercised the unread side effect also assert
store.unreadCount directly (the canonical source).

Per the project's YAGNI guidance ("Don't design for hypothetical future
requirements"), drop the payload. The enum becomes:

  case duplicate
  case inserted

If a future consumer genuinely needs a fresh-unread signal it can be
added back as an associated value at that time.

Updated ADR-0020 rationale and alternatives-considered section to reflect
the actual motivation for the enum shape (readable named cases at call
sites vs Bool) and the reason for dropping the payload.

Tests rewritten: every `.inserted(incrementedUnread: ...)` simplified to
`.inserted`, with explicit `store.unreadCount` assertions added where the
payload was the sole carrier of the unread-side-effect check
(specifically `unreadCutoffSuppressesReplayedHistory`).

All 21 ChatMessageStore tests pass; full xcodebuild RoadFlareTests scheme
passes.
The phrase implied .claude/CLAUDE.md contains a YAGNI principle, but it
does not — its Project Conventions section covers SDK/app split, build
verification, and concurrency only. Reword the justification to stand
on its own ("the payload was dead public surface") so a future reader
chasing the citation does not come up empty.
@variablefate variablefate marked this pull request as ready for review May 12, 2026 09:29
@variablefate
Copy link
Copy Markdown
Owner Author

Code review (full ritual)

No issues found. 5-agent pass on the rebased HEAD:

  • CLAUDE.md: no violations; existing ADR-0020 update is the correct scope (per "Keep ADRs focused").
  • Bug scan: no leftover .inserted(incrementedUnread: patterns; ChatCoordinator.handleChatEvent haptic check compiles against the new no-payload .inserted; test coverage of the unread side effect is preserved via the explicit store.unreadCount assertions.
  • Git history: incrementedUnread was never consumed by any caller and was not specifically requested at design time.
  • Prior PR feedback: the YAGNI-citation fix from PR refactor(sdk): drop unused incrementedUnread payload from ChatMessageAppendOutcome #119 review is preserved in this rebased branch; no other carry-over.
  • Doc consistency: enum doc, ADR-0020 (Decision, Rationale, Alternatives), and ChatCoordinator class doc all accurately describe the new shape.

🤖 Generated with Claude Code

@variablefate variablefate merged commit 3c93f6a into main May 12, 2026
@variablefate variablefate deleted the refactor/drop-unread-payload branch May 12, 2026 09: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.

1 participant