Skip to content

refactor: v2 - ai assistant - introduce agentthread primitive#2355

Merged
maxy-shpfy merged 1 commit into
masterfrom
06-02-refactor_v2_-_ai_assistant_-_introduce_agentthread_primitive
Jun 11, 2026
Merged

refactor: v2 - ai assistant - introduce agentthread primitive#2355
maxy-shpfy merged 1 commit into
masterfrom
06-02-refactor_v2_-_ai_assistant_-_introduce_agentthread_primitive

Conversation

@maxy-shpfy

@maxy-shpfy maxy-shpfy commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Description

The AI chat agent client has been refactored from a global singleton into a per-thread model. A new AgentThread primitive encapsulates a single conversation's Web Worker, MobX state (messages, thinking text, pending status), and lifecycle. AiChatStore now owns a collection of AgentThread instances and tracks an active thread ID, with newThread() disposing the previous thread and spinning up a fresh one.

A "New chat" button has been added to the chat UI header, allowing users to explicitly start a fresh conversation. The AiChatStoreProvider now calls ensureActiveThread() on mount and disposeAll() on unmount, correctly handling React StrictMode's mount → unmount → mount cycle which previously left the store in an empty state.

The threadId is now owned by AgentThread and injected into every worker request directly, rather than being tracked as a response value and passed back on subsequent messages.

Related Issue and Pull requests

Type of Change

  • Bug fix
  • New feature
  • Improvement
  • Cleanup/Refactor
  • Breaking change
  • Documentation update

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Screenshots (if applicable)

Demo of AI multi thread.mov (uploaded via Graphite)

Test Instructions

  1. Open the AI chat panel and verify a conversation can be sent and receives a response as normal.
  2. Click the "New chat" (pencil) button in the chat header and confirm the message history is cleared and a fresh conversation begins.
  3. Verify that navigating away and back to the chat panel does not leave the store in an empty/broken state.
  4. Confirm that under React StrictMode (development builds) the chat initialises correctly after the double-mount cycle.

Additional Comments

The AgentThread class includes a placeholder comment for a future persist() method to support snapshotting and restoring threads across page reloads, which is out of scope for this change.

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

🎩 Preview

A preview build has been created at: 06-02-refactor_v2_-_ai_assistant_-_introduce_agentthread_primitive/a19dc61

maxy-shpfy commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

@maxy-shpfy maxy-shpfy force-pushed the 06-02-refactor_v2_-_ai_assistant_-_basic_chat_in_runview branch from d70a0e6 to 4dcf8e7 Compare June 11, 2026 06:01
@maxy-shpfy maxy-shpfy force-pushed the 06-02-refactor_v2_-_ai_assistant_-_introduce_agentthread_primitive branch from e8e1dc3 to 2a72379 Compare June 11, 2026 06:01
@maxy-shpfy maxy-shpfy changed the base branch from 06-02-refactor_v2_-_ai_assistant_-_basic_chat_in_runview to graphite-base/2355 June 11, 2026 06:06
@maxy-shpfy maxy-shpfy changed the base branch from graphite-base/2355 to master June 11, 2026 06:11
@maxy-shpfy maxy-shpfy force-pushed the 06-02-refactor_v2_-_ai_assistant_-_introduce_agentthread_primitive branch from 2a72379 to a19dc61 Compare June 11, 2026 06:12
@maxy-shpfy maxy-shpfy merged commit d4e2c35 into master Jun 11, 2026
17 checks passed
@maxy-shpfy maxy-shpfy deleted the 06-02-refactor_v2_-_ai_assistant_-_introduce_agentthread_primitive branch June 11, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants