Skip to content

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

Closed
variablefate wants to merge 2 commits into
chore/renumber-adr-chat-message-storefrom
refactor/drop-unread-payload
Closed

refactor(sdk): drop unused incrementedUnread payload from ChatMessageAppendOutcome#119
variablefate wants to merge 2 commits into
chore/renumber-adr-chat-message-storefrom
refactor/drop-unread-payload

Conversation

@variablefate
Copy link
Copy Markdown
Owner

Summary

Stacked on top of #118 (renumber ADR). When #118 merges, GitHub will rebase this onto main.

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.

Per CLAUDE.md's "Don't design for hypothetical future requirements" guidance, drop the payload. The enum becomes:

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

First-principles check

The principle: state changes are observable through their canonical source, not via return-value side channels. `unreadCount` IS the canonical source. The payload was a side channel duplicating it. Dropping it eliminates the duplication without losing information.

If a future consumer (driver app, badge-pulse UI, push routing) genuinely needs a "did this append bump unread" signal that's race-free from polling `unreadCount`, the payload can be added back at that point with the actual use case driving the shape.

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 to reflect the actual motivation (readable named cases at call sites) and document why the payload was dropped; 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: `if case .inserted = store.append(message), !message.isMine` matches the new enum shape identically

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
Copy link
Copy Markdown
Owner Author

Code review

One issue found and fixed in 1b050d1:

  • ADR-0020 Rationale cited "the project's YAGNI guidance" as if `.claude/CLAUDE.md` contained a YAGNI principle, but that file's Project Conventions cover SDK/app split, build verification, and concurrency only — no YAGNI section. Reworded 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.

Other checks clean: all call sites swept (no remaining `incrementedUnread` or `.inserted(` patterns), `ChatCoordinator.handleChatEvent` pattern-match still compiles against the no-payload `.inserted`, test semantic coverage preserved (the explicit `unreadCount == 0` after the stale append in `unreadCutoffSuppressesReplayedHistory` is strictly equivalent to the dropped payload-based assertion), ADR-0020 internal consistency confirmed.

**Append outcome enum.** The enum's named cases (`.duplicate`, `.inserted`)
read more clearly at call sites than a `Bool` would — the haptic decision
in `ChatCoordinator.handleChatEvent` becomes a self-describing
`if case .inserted = store.append(message), !message.isMine`. An earlier
revision attached an `incrementedUnread: Bool` payload to `.inserted`,
motivated by a hypothetical caller that needed to know whether the badge
just bumped (e.g. for a "fresh-unread pulse" UI). The actual coordinator
never read the payload — it only checks the case — and every test that
exercised the unread side effect also asserts `store.unreadCount` directly,
which is the canonical source. The payload was therefore dead public surface
and was dropped; if a future consumer genuinely needs a fresh-unread signal
it can be added back as an associated value at that time.

🤖 Generated with Claude Code

@variablefate variablefate marked this pull request as ready for review May 12, 2026 03:56
@variablefate variablefate deleted the branch chore/renumber-adr-chat-message-store May 12, 2026 09:28
variablefate added a commit that referenced this pull request May 12, 2026
…AppendOutcome (#121)

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

Drop the payload. The enum becomes:
  case duplicate
  case inserted

Updated ADR-0020 rationale + alternatives.

(Re-opens the auto-closed PR #119; rebased onto main after PR #118 merged.)
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