Skip to content

harden threadReducer status helpers against unknown future statuses - #14133

Closed
kvnloo wants to merge 1 commit into
pingdotgg:mainfrom
kvnloo:muse/thread-reducer-unknown-status
Closed

kvnloo wants to merge 1 commit into
pingdotgg:mainfrom
kvnloo:muse/thread-reducer-unknown-status

Conversation

@kvnloo

@kvnloo kvnloo commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

Added explicit default branches to the two status-mapping switches in packages/client-runtime/src/state/threadReducer.ts:

  • settledTurnStateForSessionStatus: unknown future session statuses return null — a running turn stays unsettled; only known-terminal statuses may settle a turn.
  • checkpointStatusToTurnState: unknown future checkpoint statuses return "completed" — the turn is known done at every call site, matching the existing "missing" precedent.

Why

Without a default, a session or checkpoint status the client release doesn't know about (newer server) fell off the switch and returned undefined, silently corrupting latestTurn.state in violation of its declared type. This is the client-side forward-compat counterpart to the server's capability-gated event streams.

Validation

  • Added two forward-compat tests: unknown session status keeps the turn running; unknown checkpoint status settles it completed.
  • Red on base (2 failed with expected undefined to be 'running'/'completed'), green with the fix (52/52 in packages/client-runtime/src/state/threadReducer.test.ts).

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No UI changes

Authored with AI assistance (Muse, Meta's Muse Spark) under the contributor's direction.

Summary by CodeRabbit

  • Bug Fixes
    • Running turns remain active when the app encounters an unfamiliar session status.
    • Completed turn updates are now recognized as completed even when their checkpoint status is unfamiliar.

…tuses

settledTurnStateForSessionStatus and checkpointStatusToTurnState had no
default branch, so a session or checkpoint status the client release does
not know about (newer server) fell off the switch and returned undefined,
silently corrupting latestTurn.state in violation of its declared type.

- settledTurnStateForSessionStatus: default returns null, so unknown future
  statuses keep a running turn unsettled; only known-terminal statuses may
  settle a turn.
- checkpointStatusToTurnState: default returns "completed", since the turn
  is known done at every call site (matches the existing "missing"
  precedent).

Tests: added two forward-compat cases (unknown session status keeps the
turn running; unknown checkpoint status settles it completed). Verified red
on base (2 failed, "expected undefined to be 'running'/'completed'") and
green with the fix (52/52).

---
Authored with AI assistance (Muse, Meta's Muse Spark) under the contributor's direction.
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Sep 28, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Sep 28, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 4e5cd62

Macroscope's review found this PR approvable — This is a narrowly scoped forward-compatibility fix in an existing reducer, preserving known behavior while preventing invalid turn states for unknown statuses. Both fallback paths are covered by focused tests, with no schema, deployment, security, or product-default changes.

Notes:

  • Diff unchanged. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 76cd36c9-380f-4974-8027-4c07eb5d8da6

📥 Commits

Reviewing files that changed from the base of the PR and between ed57bed and 4e5cd62.

📒 Files selected for processing (2)
  • packages/client-runtime/src/state/threadReducer.test.ts
  • packages/client-runtime/src/state/threadReducer.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The reducer defines fallback behavior for unrecognized session and checkpoint statuses. Tests verify that an unknown session status preserves a running turn and an unknown checkpoint status completes it.

Changes

Status fallback handling

Layer / File(s) Summary
Unknown status fallbacks and reducer tests
packages/client-runtime/src/state/threadReducer.ts, packages/client-runtime/src/state/threadReducer.test.ts
Unknown session statuses return null and do not settle a running turn. Unknown checkpoint statuses map to "completed". Tests verify both outcomes.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: t3dotgg

Merge Risk: ⚪ Minimal · up to 4e5cd

The status fallbacks have no identified merge-blocking issue; the PR is mergeable after normal checks.

Architecture Summary

Architecture risk: 🔵 Low · up to 4e5cd

The change affects 1 system.

Changed systems: packages/client-runtime

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/client-runtime (library) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/client-runtime/src/state/threadReducer.test.ts: The test imports OrchestrationSession alongside OrchestrationThread for typing the forward-compatible session status.
  • observed — Modified behavior in packages/client-runtime/src/state/threadReducer.test.ts: Adds a thread.session-set test with an unknown newer session status and an existing running turn; it expects the reducer result to retain the turn’s running state.
  • observed — Modified behavior in packages/client-runtime/src/state/threadReducer.test.ts: Adds a completed-turn diff test with an unknown newer checkpoint status; it expects the reducer result to mark the existing running turn completed.
  • observed — Modified behavior in packages/client-runtime/src/state/threadReducer.ts: The comment now states that unknown future session statuses, like starting or running, leave a turn unsettled; only known terminal statuses settle it. No implementation logic changed.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. 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 clearly identifies the main change: hardening threadReducer status helpers against unknown future statuses.
Description check ✅ Passed The description explains what changed, why the fallback behavior is required, how the change was validated, and confirms that the PR is small and has no UI changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 1, 2026 — with ChatGPT Codex Connector
@macroscopeapp
macroscopeapp Bot dismissed their stale review October 1, 2026 04:01

Dismissing prior approval to re-evaluate 4e5cd62

@juliusmarminge

Copy link
Copy Markdown
Member

Thanks for working on this. We merged the orchestrator V2 rewrite in #2829, and we are closing this PR as part of that transition.

This change touches threadReducer.ts, which the V2 merge removed. The shared client now consumes V2 snapshots and projections.

Sorry for the extra work this creates. If the change is still needed on V2, please rebuild it on current main, verify it there, and open a new PR linking back here. We're closing the current implementation without assuming the underlying request is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:XS 0-9 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants