Skip to content

docs: Expand ADR 003 with internal state machine documentation#525

Merged
yewreeka merged 7 commits into
devfrom
docs/inbox-lifecycle-architecture
Feb 25, 2026
Merged

docs: Expand ADR 003 with internal state machine documentation#525
yewreeka merged 7 commits into
devfrom
docs/inbox-lifecycle-architecture

Conversation

@yewreeka

@yewreeka yewreeka commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Expand the existing ADR 003 (Inbox Lifecycle Management) with documentation of the internal state machines, rather than creating a duplicate ADR.

What's Added to ADR 003

  • Architecture overview diagram showing component relationships (InboxLifecycleManager, MessagingService, state machines, UnusedConversationCache)
  • InboxStateMachine state diagram (idle → authorizing → ready → backgrounded → deleting)
  • ConversationStateMachine state diagram (uninitialized → creating/validating → joining → ready)
  • Edge cases section documenting race condition handling:
    • Re-wake during sleep
    • Duplicate registration prevention
    • Concurrent eviction
    • Stale data cleanup
  • Additional related files references

Also Includes

  • docs/plans/tech-debt-1.1.0.md - Tech debt tracking for post-1.1.0 release

Context

Between 1.0.6 and 1.1.0 we had 6+ fixes related to inbox lifecycle edge cases. This documentation will help engineers understand the system and reduce future bugs.

Note

Expand ADR 003 to document internal per-inbox and per-conversation state machines in docs/adr/003-inbox-lifecycle-management.md

Add an 'Internal State Machines' section with architecture and state diagrams for InboxStateMachine and ConversationStateMachine, include edge cases with Swift snippets, and update related file links in docs/adr/003-inbox-lifecycle-management.md.

📍Where to Start

Start at the new 'Internal State Machines' section in docs/adr/003-inbox-lifecycle-management.md.

Macroscope summarized e6abd98.

Comprehensive documentation of the inbox lifecycle management system including:
- Component overview and relationships
- State diagrams for InboxLifecycleManager, InboxStateMachine, ConversationStateMachine
- Capacity management and LRU eviction
- Pending invite protection rules
- Key flows (open conversation, create new, app launch)
- Edge cases and race condition handling

Part of tech debt paydown plan for post-1.1.0 release.
@claude

claude Bot commented Feb 25, 2026

Copy link
Copy Markdown

Claude finished @yewreeka's task —— View job


Code Review

  • Read modified ADR file
  • Read new tech debt plan file
  • Provide review feedback

Review Summary

This PR adds valuable documentation with clear, comprehensive state machine diagrams and architectural context. The writing is excellent and the content will significantly help engineers understand the inbox lifecycle system.

Strengths

ADR 003 Expansion:

  • State machine diagrams are clear and follow standard notation (idle → authorizing → ready flow)
  • Architecture overview diagram effectively shows component relationships
  • Edge cases section documents real issues encountered (re-wake during sleep, duplicate registration)
  • File references with line numbers make it easy to find implementation details
  • Mermaid-style ASCII diagrams work well for markdown rendering

Tech Debt Plan:

  • Honest retrospective showing most items were non-issues (2 of 6 required work)
  • Evidence-based approach (audit before acting)
  • Clear outcome tracking with status indicators
  • Good lesson learned section

Suggestions

Minor improvements for ADR 003:

  1. State diagram notation (lines 301-329): Consider adding legend for transition conditions:

    ┌─────────┐
    │  idle   │
    └────┬────┘
         │ Event: authorize() or register()
         │ Condition: Has clientId
    
  2. Architecture diagram (lines 271-294): Could benefit from showing data flow direction. For example:

    MessagingService ──queries──> InboxActivityRepository
    InboxLifecycleManager ──evicts──> MessagingService
    
  3. Edge cases section (lines 366-400): Great content, but could add cross-references to related test files:

    ### Re-wake During Sleep
    
    **Tests:** `InboxLifecycleManagerTests.swift:456-478`
    
  4. Line number references: Some references like line 95, 394-417 may drift over time. Consider using method names instead:

    **Location:** `InboxLifecycleManager.wake(clientId:reason:)` and `evictLRUInbox()`
    

Tech Debt Plan:

  1. Item 6 (line 135): "Review Agent POC architecture" - Could add more context about what specifically needs review (security model, user permissions, API design, etc.)

Code Quality

Not applicable - documentation-only PR with no source code changes.

Performance

Not applicable - documentation-only PR.

Security

Not applicable - documentation-only PR.

Test Coverage

Not applicable - documentation-only PR. However, the tech debt plan effectively documents that test coverage for inbox state machines is already comprehensive (4,341 lines).

Overall Assessment

Approve with minor suggestions. This is exactly the kind of documentation that prevents future bugs - it captures hard-won knowledge about edge cases and state transitions. The fact that 6+ fixes were required between 1.0.6 and 1.1.0 validates the need for this documentation.

The only improvements needed are minor formatting enhancements that would make the diagrams and references even more maintainable over time.


macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Feb 25, 2026

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

This PR only adds documentation files (ADR and tech debt plan) with no code changes. Documentation changes don't affect runtime behavior and are safe to approve.

Merge new state machine documentation into existing ADR 003 instead of
creating a separate ADR 011.

Added to ADR 003:
- Architecture overview diagram showing component relationships
- InboxStateMachine state diagram (idle → authorizing → ready → backgrounded)
- ConversationStateMachine state diagram (uninitialized → creating/joining → ready)
- Edge cases section (re-wake during sleep, duplicate registration, stale data)
- Additional related files

Removed:
- ADR 011 (duplicate/overlapping content)
@macroscopeapp macroscopeapp Bot dismissed their stale review February 25, 2026 16:37

Dismissing my prior approval and re-evaluating approvability for db37987

@yewreeka yewreeka changed the title docs: Add ADR 011 - Inbox Lifecycle Architecture docs: Expand ADR 003 with internal state machine documentation Feb 25, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Feb 25, 2026

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

This PR only adds documentation files (ADR updates and a tech debt plan). No source code is changed and there is no runtime impact, making it safe to approve.

- Mark items 1, 2, 4 as complete
- Add audit findings for UnusedConversationCache (no issues found)
- Link PRs #525 and #526
@macroscopeapp macroscopeapp Bot dismissed their stale review February 25, 2026 16:49

Dismissing my prior approval and re-evaluating approvability for 4b5f7d9

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Feb 25, 2026

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

This PR only adds documentation (ADR expansion and a tech debt plan). No runtime code is changed, making it safe to approve.

Audit found 4,341 lines of existing test coverage across:
- InboxLifecycleManagerTests (1,596 lines)
- InboxStateMachineTests (869 lines)
- ConversationStateMachineTests (1,876 lines)
- SleepingInboxMessageCheckerIntegrationTests (Docker-based)

The flaky test fixes were about test isolation and timing,
not missing coverage.
@macroscopeapp macroscopeapp Bot dismissed their stale review February 25, 2026 16:53

Dismissing my prior approval and re-evaluating approvability for df12c2c

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Feb 25, 2026

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

This PR only adds documentation files (expanding an ADR with state machine diagrams and adding a tech debt planning doc). No code changes, no runtime impact. Safe to approve.

Final tally: 2 of 6 items actually needed work
- Item 3 dropped (photo extraction risk > benefit)
- Items 4, 5 were already in good shape
- Item 6 deferred (still behind feature flag)

Added retrospective with lessons learned.
@macroscopeapp macroscopeapp Bot dismissed their stale review February 25, 2026 17:10

Dismissing my prior approval and re-evaluating approvability for 54da047

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Feb 25, 2026

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

This PR only adds documentation (ADR expansion and a tech debt planning doc). No source code is modified and there's no runtime impact.

Item 6 is about the assistant/agent feature (#476, #503), not the QA
automation server which was confusingly named AgentServer.
@macroscopeapp macroscopeapp Bot dismissed their stale review February 25, 2026 17:19

Dismissing my prior approval and re-evaluating approvability for 5b594fa

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Feb 25, 2026

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

This PR only adds documentation - expanding an ADR with state machine diagrams and creating a tech debt planning document. No runtime code is changed, making it safe to approve.

@macroscopeapp macroscopeapp Bot dismissed their stale review February 25, 2026 18:06

Dismissing my prior approval and re-evaluating approvability for e6abd98

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

This PR only adds documentation to an existing ADR file (architecture decision record). No runtime code is modified - the changes are ASCII diagrams and explanatory text about internal state machines. Documentation-only changes don't impact runtime behavior and are safe to approve.

@yewreeka yewreeka merged commit 6a47d6e into dev Feb 25, 2026
9 of 10 checks passed
@yewreeka yewreeka deleted the docs/inbox-lifecycle-architecture branch February 25, 2026 18:33
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