Skip to content

fix(client): a re-pair drops the last person's thread state kept in memory - #1156

Merged
Jacksondr5 merged 2 commits into
j5/mainfrom
j5code/fix-1147-repair-retained-thread
Nov 22, 2026
Merged

Jacksondr5 merged 2 commits into
j5/mainfrom
j5code/fix-1147-repair-retained-thread

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Problem

A thread's last state is retained in memory (ThreadResumeCache in packages/client-runtime/src/state/threads.ts), so a reopen paints at once. That object is keyed by environment and thread, not by credential, and it outlived a re-pair. After an Owner phone re-paired as a narrower person, opening one of the Owner's threads by link could briefly paint the Owner's retained state of it. Closes #1147.

What changed

J5-owned dropReplacedRetainedState (packages/client-runtime/src/j5/replacedCredential.ts) reuses #1146's replaced-credential count. It records the count each retained state was last read under, and drops the state when a re-pair has bumped the count since.

threads.ts calls it at the two places the retained state is read: makeEnvironmentThreadState, which seeds a new thread state from it, and the thread atom, which paints it before the live stream. Dropping a state also clears its owner, so upstream's owner checks refuse the old thread state's writes from the drop onward, before the successor takes ownership.

Web shares threads.ts, so its saved remote servers get the same behaviour.

UI changes

None captured. The leak is a single paint before the server refuses the new credential, and reproducing it on a device needs a re-pair followed by a deep link to one of the previous person's threads within the same launch. Per the Captain, the test is the proof here.

Upstream impact

  • packages/client-runtime/src/state/threads.ts: FORK.md case 125, whose row this file already has. Two calls plus the import.

Council review

Delegate Round 1 (728756f) Round 2 (3d1c08f)
Claude Opus 10/10 10/10
GPT Sol 7/10 (old state could write back before the successor owned it) 9/10

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests): threads-sync.test.ts, "does not recreate a cache a re-pair cleared from its finalizer", now checks that the successor starts with no retained data; it fails on j5/main
  • UI changes: before/after screenshots above, and a video for motion or interaction (no capture, see UI changes)
  • Live testing: the section above says what ran live and what did not (not exercised live)
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR
  • Upstream product: any change to what upstream's product does has a human decision linked above and a register entry in docs/j5/product/upstream.md (none: upstream's credentials all read the whole server)
  • Surfaces: entry points, clients, providers, contracts, reverse states, connection modes (see AGENTS.md): web and mobile share threads.ts
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them (no change needed)

Built by Claude Opus 5.5 in Claude Code (J5 Code Crew builder seat).

🤖 Generated with Claude Code

…emory

A thread's last state is retained in memory so a reopen paints at once, and
that object outlived a re-pair: opening one of the last person's threads by link
could briefly show it. A state retained before the credential was replaced is
now dropped where it is read.

Fixes #1147

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Nov 22, 2026 4:59pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 4 billable files and costs up to $1.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 49 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 3 included reviews currently available. Your 48 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0adbc92 and 3d1c08f.

Files selected for processing: 4

  • FORK.md
  • packages/client-runtime/src/j5/replacedCredential.ts
  • packages/client-runtime/src/state/threads-sync.test.ts
  • packages/client-runtime/src/state/threads.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 effective changed lines (test files excluded in mixed PRs). labels Nov 22, 2026
…'s ownership

The old thread state could write its snapshot back between the thread atom's
early drop and the successor taking ownership. The drop now clears the owner
with the snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jacksondr5
Jacksondr5 enabled auto-merge (squash) November 22, 2026 16:59
@github-actions github-actions Bot added size:M 30-99 effective changed lines (test files excluded in mixed PRs). and removed size:S 10-29 effective changed lines (test files excluded in mixed PRs). labels Nov 22, 2026
@Jacksondr5
Jacksondr5 merged commit 01a8086 into j5/main Nov 22, 2026
34 checks passed
@Jacksondr5
Jacksondr5 deleted the j5code/fix-1147-repair-retained-thread branch November 22, 2026 17:15

This branch was successfully deployed

1 active deployment
Preview — 3d1c08f8 Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A thread's in-memory state survives a re-pair, so a link can briefly show the last person's thread

1 participant