fix(server): mark unvisited thread completions unread #15607
main fromrefs/pull/15607/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/orchestration-v2/Orchestrator.ts line 4422OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4407,3 +4407,16 @@44074407 }44084408 }440944094410+ if (projection.thread.lastVisitedAt === null && !isNativeMaintenanceCommand(command)) {4411+ const now = yield* DateTime.now;4412+ // Null keeps imported history read. The first fresh dispatch establishes4413+ // a read watermark so its completion can be unread on every client.4414+ const event = yield* emit(4415+ events,4416+ command,4417+ )({4418+ type: "thread.metadata-updated",4419+ threadId: command.threadId,4420+ providerInstanceId: projection.thread.providerInstanceId,4421+ occurredAt: now,4422+ payload: { ...projection.thread, lastVisitedAt: now },
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this818c71d
juliusmarminge closed this
Sign in to join this conversation.


No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
35067c5b-62fb-42c9-99ad-e6a9aa685d93📥 Commits
Reviewing files that changed from the base of the PR and between 17c0878941ab8ab19108fb639c5138d92a89e919 and 050e127e4094cd2e517a5773217a2a9993d56aea.
📒 Files selected for processing (5)
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsapps/server/src/orchestration-v2/Orchestrator.control-reads.test.tsapps/server/src/orchestration-v2/Orchestrator.tsapps/server/src/orchestration-v2/ThreadLaunchService.test.tsapps/server/src/orchestration-v2/ThreadLaunchService.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
📝 Walkthrough
The orchestrator initializes a missing read watermark on a thread’s first non-maintenance dispatch. Codex request handlers reorder two emitted events. Branch-rename metadata updates include the expected worktree path, with tests covering these changes.
Changes: Read watermark initialization
apps/server/src/orchestration-v2/Orchestrator.ts,apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts,apps/server/src/orchestration-v2/ThreadLaunchService.test.tslastVisitedAtto one millisecond before the current time. Tests cover rejected and accepted dispatches, completion timestamps, retries, unread marking, explicit visit times, and thread launch state.Codex request event ordering
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsturn_item.updatedbeforeruntime_request.updated. Event payloads and other handler behavior remain unchanged.Worktree branch rename metadata
apps/server/src/orchestration-v2/ThreadLaunchService.ts,apps/server/src/orchestration-v2/ThreadLaunchService.test.tsexpectedWorktreePath. The cancellation test delays branch-name generation and waits for the rename failure log or stored event before checking run and worktree state.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
050e1No actionable merge-blocking risk remains from the reviewed changes; merge after normal checks.
Security architecture risk: 🔵 Low · up to
050e1The changes preserve existing operations and approval controls while improving event ordering and rejecting stale worktree updates. No privilege expansion was established, but some concurrent cancellation and recovery cases remain partially verified.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Pre-merge checks:
3 · 
1
#3131requires newly started background threads to show unread completion while historical threads remain read.Orchestrator.dispatchMessagenow writes a watermark one millisecond before the f…Full details: Linked Issues check
Explanation
Issue
#3131requires newly started background threads to show unread completion while historical threads remain read.Orchestrator.dispatchMessagenow writes a watermark one millisecond before the first non-maintenance dispatch when no visit time exists, then updates the in-memory projection. Completion after that dispatch is newer than the watermark. Existing visit times and maintenance dispatches are unchanged. The added tests cover accepted and rejected dispatches, retries, queued dispatches, and visit-watermark behavior. No change alters the existing handling of settled non-completed turns.Full details: Description check
Explanation
The description explains the problem, implementation, linked issue, verification results, screenshots, test coverage, and known platform limitations. It does not use the template headings or provide an explicit maintainer approval comment, but the required information is otherwise substantially complete.
Full details: Out of Scope Changes check
Explanation
The CodexAdapterV2 changes reorder approval/input timeline updates and actionable requests. The ThreadLaunchService change guards against a late branch rename restoring a cancelled setup worktree. These changes address approval ordering and setup cancellation, not issue
#3131's unread completion status. The PR description connects them to races exposed during implementation, but it does not establish that they are needed for the linked issue.Resolution
Move the CodexAdapterV2 ordering changes and the ThreadLaunchService worktree guard to separately scoped changes, or link issues that require these behaviors.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.