Skip to content

fix(app): cache detached todo updates for fresh sessions - #484

Merged
Astro-Han merged 2 commits into
devfrom
codex/i480-todo-dock-refresh
May 6, 2026
Merged

fix(app): cache detached todo updates for fresh sessions#484
Astro-Han merged 2 commits into
devfrom
codex/i480-todo-dock-refresh

Conversation

@Astro-Han

@Astro-Han Astro-Han commented May 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Cache todo.updated events into globalSync.data.session_todo even when the directory child store is not mounted yet.
  • Clear detached todo cache entries when detached session.deleted or archived session.updated events arrive.
  • Add focused coverage for fresh-session first todowrite dock visibility and detached todo event handling.

Why

Issue #480 reports that a brand-new session can receive its first todo update without the composer todo dock appearing until the user switches away and back. The backend already publishes complete todo.updated payloads, and #472 already fixed reconnect replay. The missing path was app-side live sync: directory-scoped events were dropped when the matching child store did not exist yet, so the dock cache never received the fresh todo snapshot.

Related Issue

Closes #480

Human Review Status

Pending. A human should make the final merge decision after reviewing the final diff and verification evidence.

Review Focus

Risk Notes

Low. This writes the existing session todo cache from complete todo.updated payloads before a directory child store exists, then clears that cache if the same detached path later receives session delete/archive events. It does not change replay whitelist behavior, dock rendering, todo machine state, message/permission/question handling, or add polling.

How To Verify

Fresh/replay E2E: 2 passed
  bun --cwd packages/app test:e2e session/session-composer-dock.spec.ts --grep "todo dock appears for the first todowrite in a fresh session|todo dock recovers after missed todowrite via SSE replay"

Todo app units: 50 passed
  bun test --preload ./happydom.ts src/context/global-sync/event-reducer.test.ts src/pages/session/todos/todo-dock-machine.test.ts src/pages/session/todos/todo-source.test.ts src/pages/session/todos/todo-model.test.ts

Replay unit: 19 passed
  bun test test/server/event-replay.test.ts

App typecheck: ok
  bun --cwd packages/app typecheck

Diff check: no whitespace errors
  git diff --check

Screenshots or Recordings

Not attached. This PR changes data sync behavior, not visual styling or copy. The rendered dock path is covered by the targeted Playwright E2E above.

Checklist

  • Human review status is stated above as pending, approved, or not required
  • I linked the related issue, or stated why there is no issue
  • This PR has type, primary area, and priority labels, or I requested maintainer labeling
  • I described the review focus and any meaningful risks
  • I listed the relevant verification steps and the key result for each
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant
  • I reviewed the final diff for unrelated changes and suspicious dependency changes
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

Summary by CodeRabbit

  • New Features

    • Added support for handling events in detached directory contexts, including todo updates and session management.
  • Tests

    • Added comprehensive test coverage for session todo dock behavior with detached directories.
    • Extended event handler tests to validate detached directory event workflows, caching, and session cleanup.

@Astro-Han Astro-Han added bug Something isn't working P1 High priority app Application behavior and product flows ui Design system and user interface labels May 6, 2026
@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

This PR fixes a bug where the todo dock does not refresh when creating the first todo in a fresh session. It adds handling for events arriving before a directory child store exists via a new applyDetachedDirectoryEvent function, integrates this into the global sync event listener, and validates the fix with a new end-to-end test.

Changes

Detached Directory Event Handling

Layer / File(s) Summary
Core Event Handler
packages/app/src/context/global-sync/event-reducer.ts
New applyDetachedDirectoryEvent function validates input and processes todo.updated, session.deleted, and session.updated events for non-existent directories, updating or clearing session todos via setSessionTodo callback.
Unit Tests
packages/app/src/context/global-sync/event-reducer.test.ts
Tests cover detached todo update caching, event filtering for directory-dependent operations, malformed update handling, and cache clearing on session deletion or archival. Imports updated to include Todo type and new function.
Global Sync Integration
packages/app/src/context/global-sync.tsx
Global event listener imports applyDetachedDirectoryEvent and invokes it when no child store exists for a directory, passing event and setSessionTodo callback before returning.
End-to-End Test
packages/app/e2e/session/session-composer-dock.spec.ts
New test helper readPromptSend reads prompt submission state from window. New test validates that todo dock reflects todos created in fresh session without navigating away, using todowrite tool and polling for prompt submission.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Astro-Han/pawwork#386: Modifies the same global-sync event reducer and test infrastructure for directory/session event handling.
  • Astro-Han/pawwork#381: Modifies session-composer-dock E2E tests with related changes to todo dock visibility behavior.
  • Astro-Han/pawwork#325: Updates session-composer-dock E2E test helpers and fixtures.

Poem

🐰 A dock that once stayed blank and bare,
Now springs to life with todos fair!
Fresh sessions bloom without delay,
No switching needed—todos play!
Events arrive before they're born,
The detached path welcomes morn! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(app): cache detached todo updates for fresh sessions' clearly and concisely describes the main change: caching todo updates when directory stores are not yet mounted, which directly addresses the fresh session todo dock issue.
Description check ✅ Passed The PR description comprehensively follows the template with all major sections completed: Summary, Why, Related Issue, Review Focus, Risk Notes, verification steps, and completed checklist items.
Linked Issues check ✅ Passed The code changes directly address issue #480 by implementing detached todo caching to prevent directory-scoped events from being dropped when child stores are unmounted, matching the issue's requirement for real-time dock updates in fresh sessions.
Out of Scope Changes check ✅ Passed All changes align with stated scope: adding detached event handler, caching todo updates, clearing cache on session deletion/archival, and adding focused test coverage. No unrelated refactors, dependencies, or extraneous file modifications detected.

✏️ 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 codex/i480-todo-dock-refresh

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 and usage tips.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces the ability to handle "detached" todo update events, which occur before a directory child store is fully initialized. This ensures that the todo dock can correctly display todos for the first todowrite action in a fresh session. Key changes include the implementation of applyDetachedDirectoryEvent in the event reducer, its integration into the global sync logic, and the addition of both unit and E2E tests to verify the fix. I have no feedback to provide as there were no review comments.

@Astro-Han
Astro-Han merged commit fb8d05c into dev May 6, 2026
23 checks passed
@Astro-Han
Astro-Han deleted the codex/i480-todo-dock-refresh branch May 6, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app Application behavior and product flows bug Something isn't working P1 High priority ui Design system and user interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] New-session todo dock does not refresh until session switch (follow-up to #472)

1 participant