fix(auth): stop stale chat threads after signup#1192
fix(auth): stop stale chat threads after signup#1192senamakel merged 2 commits intotinyhumansai:mainfrom
Conversation
- Purge pre-login workspace conversation JSONL on first session activation so onboarding/demo threads do not linger under users/local. - When auth identity changes without a restart flip, clear thread Redux and reload from core so the UI cannot show pre-auth thread rows. Closes tinyhumansai#1157 Co-authored-by: Cursor <cursoragent@cursor.com>
📝 WalkthroughWalkthroughAdds cross-layer cleanup on identity activation: Rust purges pre-login workspace threads on first activation, and the React provider clears the Redux thread slice and reloads threads when identity hydrates (non-flip, non-logout) within the same process. ChangesCross-Layer Thread & Workspace Cleanup
Sequence DiagramsequenceDiagram
participant User as User/SignUp
participant Rust as Rust Core
participant FS as Filesystem
participant Redux as Redux Store
participant Provider as CoreStateProvider
User->>Rust: Login / attach session
Note over Rust: store_session() called
Rust->>Rust: read_active_user_id(&root_dir)
alt First activation (no previous active user)
Rust->>FS: purge pre_login_user_dir/.../workspace
Rust->>Rust: log purge stats or debug on error
Rust->>FS: write active_user.toml
else Subsequent activation
Rust->>FS: write active_user.toml
end
Rust->>Redux: trigger refreshCore / identity snapshot update
Redux->>Provider: notify identity changed
Provider->>Provider: detect shouldClearScopedCaches && !isFlip && !isLogout && nextIdentity
Provider->>Redux: dispatch clearAllThreads()
Provider->>Redux: dispatch loadThreads()
Redux->>Provider: threads reloaded
Provider->>User: updated (clean) thread state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 4/5 reviews remaining, refill in 12 minutes. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/src/providers/CoreStateProvider.tsx`:
- Around line 244-255: The thread-clear/reload branch can run for a stale auth
snapshot; capture the current snapshotRequestIdRef (e.g. const currentSnapshotId
= snapshotRequestIdRef.current) and only perform
store.dispatch(clearAllThreads()) and store.dispatch(loadThreads()) if
snapshotRequestIdRef.current === currentSnapshotId, and similarly skip the
loadThreads error handler if the snapshot id has changed; reference
snapshotRequestIdRef, clearAllThreads, loadThreads (and commitState for context)
when making this guard so stale/outsourced refreshes do not mutate the committed
identity's thread slice.
In `@src/openhuman/credentials/ops.rs`:
- Around line 191-214: The purge can race with concurrent thread listing because
purge_threads (conversations::purge_threads) uses a write lock while the
read/list path in the conversations store is not synchronized; serialize the
operation by acquiring the same conversation store lock around the purge call or
by invoking a store-level API that performs both listing and removal under the
same lock (e.g., use the store's write-locked purge method instead of calling
purge_threads directly, or wrap pre_login workspace listing/removal in
conversations::with_store_write_lock(|store|
store.purge_pre_login_workspace(pre_ws))). Ensure you reference and use the same
lock mechanism implemented in src/openhuman/memory/conversations/store.rs (the
conversation store's read/write lock and its list/remove methods) so the purge
fully completes before any read/list (frontend loadThreads) can run.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e186ff05-b7fe-4c0a-a9e9-51846b42a772
📒 Files selected for processing (3)
app/src/providers/CoreStateProvider.tsxapp/src/providers/__tests__/CoreStateProvider.identityFlip.test.tsxsrc/openhuman/credentials/ops.rs
| if previous_active.is_none() { | ||
| let pre_ws = pre_login_user_dir(&root_dir).join("workspace"); | ||
| let pre_ws_log = pre_ws.display().to_string(); | ||
| match conversations::purge_threads(pre_ws) { | ||
| Ok(stats) => { | ||
| tracing::info!( | ||
| pre_login_workspace = %pre_ws_log, | ||
| threads = stats.thread_count, | ||
| messages = stats.message_count, | ||
| "[credentials] purged pre-login conversation threads after first session activation" | ||
| ); | ||
| logs.push(format!( | ||
| "purged pre-login conversation history (threads={}, messages={})", | ||
| stats.thread_count, stats.message_count | ||
| )); | ||
| } | ||
| Err(e) => { | ||
| tracing::debug!( | ||
| error = %e, | ||
| pre_login_workspace = %pre_ws_log, | ||
| "[credentials] pre-login conversation purge skipped (non-fatal)" | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Serialize the pre-login purge with thread listing.
This new purge runs during login while the frontend now immediately calls loadThreads() on the no-restart path. purge_threads is write-locked, but the read/list side in src/openhuman/memory/conversations/store.rs is not, so thread listing can race with remove_dir_all() and observe an empty or partially deleted workspace. Please put the list/read path behind the same lock, or otherwise guarantee the purge finishes before any reload can run.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openhuman/credentials/ops.rs` around lines 191 - 214, The purge can race
with concurrent thread listing because purge_threads
(conversations::purge_threads) uses a write lock while the read/list path in the
conversations store is not synchronized; serialize the operation by acquiring
the same conversation store lock around the purge call or by invoking a
store-level API that performs both listing and removal under the same lock
(e.g., use the store's write-locked purge method instead of calling
purge_threads directly, or wrap pre_login workspace listing/removal in
conversations::with_store_write_lock(|store|
store.purge_pre_login_workspace(pre_ws))). Ensure you reference and use the same
lock mechanism implemented in src/openhuman/memory/conversations/store.rs (the
conversation store's read/write lock and its list/remove methods) so the purge
fully completes before any read/list (frontend loadThreads) can run.
- Gate post-identity thread clear/reload on snapshot request id so superseded refreshes cannot mutate thread state after a newer snapshot commits. - Skip error logging when the loadThreads promise loses to a newer refresh. - Document that conversation purge shares the process-wide store mutex with list_threads (no cross-RPC race in-process). Refs tinyhumansai#1157 Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openhuman/credentials/ops.rs`:
- Around line 211-216: The Err branch that currently calls tracing::debug! when
the pre-login conversation purge fails should be changed to tracing::warn! so
failures are visible in production logs; update the call that logs error = %e
and pre_login_workspace = %pre_ws_log (the Err(e) branch in the pre-login purge
logic) to use warn level and keep the same structured fields and message
("[credentials] pre-login conversation purge skipped (non-fatal)").
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 14bfb15e-4ba2-41e5-976e-bd49cacc99f8
📒 Files selected for processing (2)
app/src/providers/CoreStateProvider.tsxsrc/openhuman/credentials/ops.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- app/src/providers/CoreStateProvider.tsx
| Err(e) => { | ||
| tracing::debug!( | ||
| error = %e, | ||
| pre_login_workspace = %pre_ws_log, | ||
| "[credentials] pre-login conversation purge skipped (non-fatal)" | ||
| ); |
There was a problem hiding this comment.
Promote purge-failure logging to warn for production visibility.
This cleanup directly protects against stale/shared pre-login thread carryover; keeping failures at debug makes incidents easy to miss in normal ops logs. Keep it non-fatal, but log at warning level.
Suggested patch
- tracing::debug!(
+ tracing::warn!(
error = %e,
pre_login_workspace = %pre_ws_log,
"[credentials] pre-login conversation purge skipped (non-fatal)"
);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| Err(e) => { | |
| tracing::debug!( | |
| error = %e, | |
| pre_login_workspace = %pre_ws_log, | |
| "[credentials] pre-login conversation purge skipped (non-fatal)" | |
| ); | |
| Err(e) => { | |
| tracing::warn!( | |
| error = %e, | |
| pre_login_workspace = %pre_ws_log, | |
| "[credentials] pre-login conversation purge skipped (non-fatal)" | |
| ); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openhuman/credentials/ops.rs` around lines 211 - 216, The Err branch that
currently calls tracing::debug! when the pre-login conversation purge fails
should be changed to tracing::warn! so failures are visible in production logs;
update the call that logs error = %e and pre_login_workspace = %pre_ws_log (the
Err(e) branch in the pre-login purge logic) to use warn level and keep the same
structured fields and message ("[credentials] pre-login conversation purge
skipped (non-fatal)").
* feat(remotion): Ghosty character library with transparent MOV variants (tinyhumansai#1059) Co-authored-by: WOZCODE <contact@withwoz.com> * feat(composio/gmail): sync into memory tree (Slack-parity) (tinyhumansai#1056) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(scheduler-gate): throttle background AI on battery / busy CPU (tinyhumansai#1062) * fix(core,cef): run core in-process and stop orphaning CEF helpers on Cmd+Q (tinyhumansai#1061) * ci: add dedicated staging release workflow (tinyhumansai#1066) * fix(sentry): Rust source context + per-release deploy marker (tinyhumansai#405) (tinyhumansai#1067) * fix(welcome): re-enable OAuth buttons with focus/timeout recovery (tinyhumansai#1049) (tinyhumansai#1069) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore(dependencies): update pnpm-lock.yaml and Cargo.lock for package… (tinyhumansai#1082) * fix(onboarding): personalize welcome agent greeting with user identity (tinyhumansai#1078) * fix(chat): make agent message bubbles fit content width (tinyhumansai#1083) * Feat/dmg checks (tinyhumansai#1084) * fix(linux): Add X11 platform flags to .deb package launcher (tinyhumansai#1087) Co-authored-by: unn-Known1 <unn-known1@users.noreply.github.com> * fix(sentry): auto-send React events; collapse core→tauri for desktop (tinyhumansai#1086) Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai> * fix(cef): run blank reload guard on the CEF UI thread (tinyhumansai#1092) * fix(app): reload webview instead of restart_app in dev mode (tinyhumansai#1068) (tinyhumansai#1071) * fix(linux): deliver X11 ozone flags via custom .desktop template (tinyhumansai#1091) * fix(webview-accounts): retry data-dir purge so CEF handle race doesn't leak cookies (tinyhumansai#1076) (tinyhumansai#1081) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai> * fix(webview/slack): media perms + deep-link isolation (tinyhumansai#1074) (tinyhumansai#1080) Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai> * ci(release): split staging vs production workflows; promote staging tags (tinyhumansai#1094) * Update release-staging.yml (tinyhumansai#1097) * chore(staging): v0.53.5 * chore(staging): v0.53.6 * ci(staging): cut staging from main; add act local-debug helper (tinyhumansai#1099) * chore(staging): v0.53.7 * fix(ci): correct sentry-cli download URL and trap scope (tinyhumansai#1100) * chore(staging): v0.53.8 * feat(chat): forward thread_id to backend for KV cache locality (tinyhumansai#1095) * fix(ci): bump pinned sentry-cli to 3.4.1 (2.34.2 was never published) (tinyhumansai#1102) * chore(staging): v0.53.9 * fix(ci): drop bash trap in upload_sentry_symbols.sh; inline cleanup (tinyhumansai#1103) * chore(staging): v0.53.10 * refactor(session): flatten session_raw/, switch md to YYYY_MM_DD (tinyhumansai#1098) * Add full Composio managed-auth toolkit catalog (tinyhumansai#1093) * ci: add diff-aware 80% coverage gate (Vitest + cargo-llvm-cov) (tinyhumansai#1104) * feat(scripts): pnpm work + pnpm debug for agent-driven workflows (tinyhumansai#1105) * ci: pull pnpm into CI image, drop redundant setup steps (tinyhumansai#1107) * docs: add Cursor Cloud specific instructions to AGENTS.md (tinyhumansai#1106) Co-authored-by: Cursor Agent <cursoragent@cursor.com> * chore(staging): v0.53.11 * docs: surface 80% coverage gate and scripts/debug runners (tinyhumansai#1108) * feat(app): show Composio integrations as sorted icon grid on Skills (tinyhumansai#1109) Co-authored-by: Cursor Agent <cursoragent@cursor.com> * feat(composio): client-side trigger enable/disable toggles (tinyhumansai#1110) * feat(skills): channels grid + integrations card polish; tolerant Composio trigger decode (tinyhumansai#1112) * chore(staging): v0.53.12 * feat(home): early-bird banner + assistant→agent terminology (tinyhumansai#1113) * feat(updater): in-app auto-update with auto-download + restart prompt (tinyhumansai#677) (tinyhumansai#1114) * chore(claude): add ship-and-babysit slash command (tinyhumansai#1115) * feat(home): EarlyBirdyBanner + agent terminology + LinkedIn enrichment model pin (tinyhumansai#1118) * fix(chat): single onboarding thread in sidebar after wizard (tinyhumansai#1116) Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Steven Enamakel <senamakel@users.noreply.github.com> * fix: filter out global namespace from citation chips (tinyhumansai#1124) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: senamakel-droid <281415773+senamakel-droid@users.noreply.github.com> * feat(nav): enable Memory tab in BottomTabBar (tinyhumansai#1125) * feat(memory): singleton ingestion + status RPC + UI pill (tinyhumansai#1126) * feat(human): mascot tab with viseme-driven lipsync (staging only) (tinyhumansai#1127) * Fix CEF zombie processes on full app close and restart (tinyhumansai#1128) Co-authored-by: senamakel-droid <281415773+senamakel-droid@users.noreply.github.com> Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai> * Update issue templates for GitHub issue types (tinyhumansai#1146) * feat(human): expand mascot expressions and tighten reply-speech state machine (tinyhumansai#1147) * feat(memory): ingestion pipeline + tree-architecture docs + ops/schemas split (tinyhumansai#1142) * feat(threads): surface live subagent work in parent thread (tinyhumansai#1122) (tinyhumansai#1159) * fix(human): keep mascot mouth animating when TTS ships no viseme data (tinyhumansai#1160) * feat(composio): consume backend markdownFormatted for LLM output (tinyhumansai#1165) * fix(subagent): lazy-register toolkit actions filtered out of fuzzy top-K (tinyhumansai#1162) * feat(memory): user-facing long-term memory window preset (tinyhumansai#1137) (tinyhumansai#1161) * fix(tauri-shell): proactively kill stale openhuman RPC on startup (tinyhumansai#1166) * chore(staging): v0.53.13 * fix(composio): per-action tool consumes backend markdownFormatted (tinyhumansai#1167) * fix(threads): persist selectedThreadId across reloads (tinyhumansai#1168) * feat(memory_tree): switch embed model to bge-m3 (1024-dim, 8K context) (tinyhumansai#1174) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(agent): drop redundant [Memory context] recall injection (tinyhumansai#1173) * chore(memory_tree): drop body-read timeouts on Ollama HTTP calls (tinyhumansai#1171) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(transcript): emit thread_id + fix orchestrator missing cost (tinyhumansai#1169) * fix(composio/gmail): phase out html2md, prefer text/plain MIME part (tinyhumansai#1170) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(tools): markdown output for internal tool results (tinyhumansai#1172) * feat(security): enforce prompt-injection guard before model and tool execution (tinyhumansai#1175) * fix(cef): popup paint dies after first frame — skip blank-page guard for popups (tinyhumansai#1079) (tinyhumansai#1182) Co-authored-by: Steven Enamakel <31011319+senamakel@users.noreply.github.com> * chore(sentry): rename OPENHUMAN_SENTRY_DSN → OPENHUMAN_CORE_SENTRY_DSN (tinyhumansai#1186) * feat(remotion): add yellow mascot character with all animation variants (tinyhumansai#1193) Co-authored-by: Neel Mistry <neelmistry@Neels-MacBook-Pro.local> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(composio): hide raw connection ID, derive friendly label (tinyhumansai#1153) (tinyhumansai#1185) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> * fix(windows): align install.ps1 MSI with per-machine scope (tinyhumansai#913) (tinyhumansai#1187) Co-authored-by: Cursor <cursoragent@cursor.com> * fix(tauri): deterministic CEF teardown on full app close (tinyhumansai#1120) (tinyhumansai#1189) Co-authored-by: Cursor <cursoragent@cursor.com> * fix(composio): cap Gmail HTML body before strip (crash mitigation) (tinyhumansai#1191) Co-authored-by: Cursor <cursoragent@cursor.com> * fix(auth): stop stale chat threads after signup (tinyhumansai#1192) Co-authored-by: Cursor <cursoragent@cursor.com> * feat(sentry): staging-only "Trigger Sentry Test" button (tinyhumansai#1072) (tinyhumansai#1183) * chore(staging): v0.53.14 * chore(staging): v0.53.15 * feat(composio): format trigger slugs into human-readable labels (tinyhumansai#1129) (tinyhumansai#1179) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> * fix(ui): hide unsupported permission UI on non-macOS for Screen Intelligence (tinyhumansai#1194) Co-authored-by: Cursor <cursoragent@cursor.com> * chore(tauri-shell): retire embedded Gmail webview-account flow (tinyhumansai#1181) * feat(onboarding): replace welcome-agent bot with react-joyride walkthrough (tinyhumansai#1180) * chore(release): v0.53.16 * fix(threads): preserve selectedThreadId on cold-boot identity hydration (tinyhumansai#1196) * feat(core): version/shutdown/update RPCs + mid-thread integration refresh (tinyhumansai#1195) * fix(mascot): swap to yellow mascot via @remotion/player (tinyhumansai#1200) * feat(memory_tree): cloud-default LLM, queue priority, entity filter, Memory tab UI (tinyhumansai#1198) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Persist turn state + restore conversation history on cold-boot (tinyhumansai#1202) * feat(mascot): floating desktop mascot via native NSPanel + WKWebView (macOS) (tinyhumansai#1203) * fix(memory/tree): emit summary children as Obsidian wikilinks (tinyhumansai#1210) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(tools): coding-harness baseline primitives (tinyhumansai#1205) (tinyhumansai#1208) * docs: add Codex PR checklist for remote agents --------- Co-authored-by: Steven Enamakel <31011319+senamakel@users.noreply.github.com> Co-authored-by: WOZCODE <contact@withwoz.com> Co-authored-by: sanil-23 <sanil@vezures.xyz> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Cyrus Gray <144336577+graycyrus@users.noreply.github.com> Co-authored-by: CodeGhost21 <164498022+CodeGhost21@users.noreply.github.com> Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com> Co-authored-by: Mega Mind <146339422+M3gA-Mind@users.noreply.github.com> Co-authored-by: Gaurang Patel <ptelgm.yt@gmail.com> Co-authored-by: unn-Known1 <unn-known1@users.noreply.github.com> Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Steven Enamakel <senamakel@users.noreply.github.com> Co-authored-by: Steven Enamakel's Droid <enamakel.agent@tinyhumans.ai> Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: senamakel-droid <281415773+senamakel-droid@users.noreply.github.com> Co-authored-by: YellowSnnowmann <167776381+YellowSnnowmann@users.noreply.github.com> Co-authored-by: Neil <neil@maha.xyz> Co-authored-by: Neel Mistry <neelmistry@Neels-MacBook-Pro.local> Co-authored-by: obchain <167975049+obchain@users.noreply.github.com> Co-authored-by: Jwalin Shah <jshah1331@gmail.com>
Summary
Fixes new signups showing conversation threads from the anonymous (
users/local) workspace or stale Redux thread rows when auth hydrates without a full identity-flip restart.Changes
store_session): After the first activation from signed-out (no prioractive_user.toml), purge local conversation JSONL under the pre-login workspace so onboarding/demo threads are not retained in the shared bucket.CoreStateProvider): When scoped caches clear for an identity change buthandleIdentityFlipdoes not run, dispatchclearAllThreads()andloadThreads()so the thread list re-syncs from the core.Verification
cargo fmt --check,cargo check(root crate)pnpm typecheck,pnpm lint,pnpm format:check,pnpm testcargo test -p openhuman credentials::opsCloses #1157
Made with Cursor
Summary by CodeRabbit
Bug Fixes
Tests