Skip to content

fix(server): preserve historical latest turn#4402

Open
D3OXY wants to merge 1 commit into
pingdotgg:mainfrom
D3OXY:fix/4399-preserve-latest-turn
Open

fix(server): preserve historical latest turn#4402
D3OXY wants to merge 1 commit into
pingdotgg:mainfrom
D3OXY:fix/4399-preserve-latest-turn

Conversation

@D3OXY

@D3OXY D3OXY commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #4399

Summary

  • Keep session active-turn state and thread historical latest-turn state as separate concepts.
  • Preserve projection_threads.latest_turn_id when thread.session-set carries a null activeTurnId.
  • Continue replacing the historical pointer when a new non-null active turn arrives.

Why it was intermittent

ProjectionSnapshotQuery joins the latest turn through projection_threads.latest_turn_id. A terminal session event could clear that pointer, while a later thread.turn-diff-completed event restored it. Event ordering therefore determined whether shell snapshots retained the completed turn.

Commit 501ce27 correctly clears stale session active-turn state for inactive sessions and should remain. This fix changes only the thread projection so historical latest-turn state survives that correct session transition.

Tests

  • Added a running-to-ready regression with no later diff/checkpoint event, asserting null session activity, retained latest_turn_id, and a completed shell latestTurn with completedAt.
  • Covered idle, stopped, interrupted, error, and starting states with null active turns.
  • Covered new running turns replacing the pointer and threads with no prior turn remaining null.

Commands run:

  • vp test run apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts
  • vp fmt --check apps/server/src/orchestration/Layers/ProjectionPipeline.ts apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts
  • vp lint --report-unused-disable-directives apps/server/src/orchestration/Layers/ProjectionPipeline.ts apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts
  • vp run --filter t3 typecheck

Note

Preserve latestTurnId on threads when thread.session-set has no active turn

When a thread.session-set event carries a null activeTurnId (e.g. on session transitions to idle, stopped, or ready), the projection previously cleared threads.latestTurnId. The fix in ProjectionPipeline.ts uses activeTurnId ?? existingRow.value.latestTurnId so the last known turn is retained. New tests in ProjectionPipeline.test.ts cover completed-turn preservation, no-active-turn session statuses, and sequential turn replacement.

Macroscope summarized 4bf18f1.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c57683be-d883-4c1d-8c28-918387c7e5db

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Jul 23, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Single-line bug fix using null coalescing to preserve latestTurnId when activeTurnId is null, with comprehensive test coverage (288 lines of tests). Clear intent, limited scope, and obvious resolution.

You can customize Macroscope's approvability policy. Learn more.

@D3OXY
D3OXY force-pushed the fix/4399-preserve-latest-turn branch 2 times, most recently from 07e326a to 1309294 Compare July 24, 2026 10:22
@D3OXY
D3OXY force-pushed the fix/4399-preserve-latest-turn branch from 1309294 to 4bf18f1 Compare July 24, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Inactive session clears historical latest turn from thread shell

1 participant