Skip to content

fix: save chat with correct project ID during project switch#2309

Open
Emt-lin wants to merge 3 commits intomasterfrom
fix/project-switch-chat-save
Open

fix: save chat with correct project ID during project switch#2309
Emt-lin wants to merge 3 commits intomasterfrom
fix/project-switch-chat-save

Conversation

@Emt-lin
Copy link
Copy Markdown
Collaborator

@Emt-lin Emt-lin commented Mar 17, 2026

Issues

Summary

  • Fix chat history being saved with wrong project ID when switching projects in the chat UI dropdown
  • Route all project switching through ProjectManager.switchProject() instead of direct setCurrentProject() atom mutation, ensuring autosave completes before the atom updates
  • Add serialization lock (switchLock) to prevent rapid A→B→C clicks from interleaving save/load operations
  • Add pre-lock and post-lock ID-equality guards for subscription re-entry and duplicate request safety
  • Fix duplicate chat files on load→save cycle by restoring frontmatter epoch (millisecond precision) to loaded messages, preventing findFileByEpoch mismatch caused by second-precision body timestamps

Test plan

  • In project chat, send a message in test1 → switch to test2 via dropdown → verify conversations/ has no file with test2 ID containing test1 messages
  • Click history icon in test2 → should not show test1 chats
  • Close project → should not create unprefixed duplicate file
  • Leave project mode via mode switcher → should not create duplicate
  • Send message → new chat → load history → close project → verify no duplicate file created
  • Rapid project switching (A→B→C quickly) → verify no interleaved/duplicate saves
  • TypeScript compiles, lint passes, all tests pass

@Emt-lin Emt-lin requested a review from logancyang March 17, 2026 04:26
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f8ab84089

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/chat-components/ChatControls.tsx Outdated
Comment thread src/components/chat-components/ProjectList.tsx Outdated
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f664ca96ca

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/LLMProviders/projectManager.ts
Comment thread src/components/chat-components/ProjectList.tsx Outdated
@Emt-lin Emt-lin force-pushed the fix/project-switch-chat-save branch from f664ca9 to 821c247 Compare March 17, 2026 07:29
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 821c2476c6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/LLMProviders/projectManager.ts Outdated
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

@Emt-lin Emt-lin force-pushed the fix/project-switch-chat-save branch from 821c247 to c2e33b5 Compare March 17, 2026 07:53
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

1 similar comment
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef95120b87

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/LLMProviders/projectManager.ts
@Emt-lin Emt-lin force-pushed the fix/project-switch-chat-save branch from ef95120 to f351ebe Compare March 17, 2026 08:09
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f351ebedd3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/LLMProviders/projectManager.ts
Emt-lin added 2 commits March 17, 2026 17:31
…ch failure

- Thread projectOverride through save pipeline so chat persists under
  the correct project identity during switches
- Serialize concurrent switches with a Promise lock to prevent interleaving
- Roll back project state (ID, atom, repo, chain, view) when switch fails
- Propagate save errors through the full autosave chain so switchProject
  can abort on failure
- Fire-and-forget autosave calls use .catch() to avoid unhandled rejections
- ProjectList close button awaits switchProject before updating UI
@Emt-lin Emt-lin force-pushed the fix/project-switch-chat-save branch from f351ebe to 7766943 Compare March 17, 2026 09:35
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 776694369c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/Chat.tsx
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b16e288cd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/Chat.tsx
handleSaveAsNote intentionally rethrows so that the programmatic
autosaveCurrentChat path can detect failures and abort project switches.
However, two UI-driven callers (handleNewChat and the manual Save
button) did not catch the rethrown error, producing unhandled rejections.

Wrap both with .catch(() => {}) since the error is already logged and
noticed inside handleSaveAsNote itself.
@Emt-lin Emt-lin force-pushed the fix/project-switch-chat-save branch from 1b16e28 to 8d982c4 Compare March 17, 2026 10:50
@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 17, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@logancyang
Copy link
Copy Markdown
Owner

Was there an issue or bug report for this one? Can you link it pls?

@Emt-lin
Copy link
Copy Markdown
Collaborator Author

Emt-lin commented Mar 20, 2026

Was there an issue or bug report for this one? Can you link it pls?

This is the issue I discovered. #2315

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants