Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@davidguttman
Copy link
Contributor

@davidguttman davidguttman commented Jan 13, 2026

What this fixes

Discord autoThread previously replied into newly-created threads while keeping the parent channel session/context, so concurrent threads polluted each other.

Changes

  • When autoThread creates a new thread, re-key SessionKey (and From/To) to the created thread channel so each thread has isolated context.
  • In autoThread launcher channels, skip parent-channel rolling history for top-level messages (the parent behaves like an index/launcher; rolling history is usually unrelated thread starters).

Expected behavior

  • Thread A and Thread B no longer share conversational context.
  • Thread messages still include the thread starter via existing ThreadStarterBody handling.

- Re-key SessionKey to the created thread when autoThread creates a thread, preventing cross-thread context bleed.\n- Avoid parent-channel rolling history when autoThread is enabled and message is top-level (parent acts as launcher/index).\n- Small formatting cleanup.
@davidguttman davidguttman force-pushed the fix/discord-autothread-context branch from 6172dc2 to cde802b Compare January 14, 2026 02:47
@davidguttman
Copy link
Contributor Author

Updated branch after rebasing onto latest upstream/main and resolving conflicts from refactor. Should be up to date now.

@thewilloftheshadow
Copy link
Member

@codex review

Copy link

@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: cde802b55b

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +302 to +306
From: `group:${createdThreadId}`,
To: `channel:${createdThreadId}`,
OriginatingTo: `channel:${createdThreadId}`,
SessionKey: autoThreadKeys.sessionKey,
ParentSessionKey: autoThreadKeys.parentSessionKey,

Choose a reason for hiding this comment

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

P2 Badge Avoid forking autoThread sessions from parent context

In the autoThread branch you now set ParentSessionKey to the parent channel. initSessionState in src/auto-reply/reply/session.ts uses ParentSessionKey to forkSessionFromParent, so a newly created thread still inherits the parent channel’s session history (which often contains context from other threads). That undermines the intended isolation for autoThread launcher channels and can still pollute thread context. Consider leaving ParentSessionKey unset (or skipping the fork) for auto-created threads so each thread starts clean.

Useful? React with 👍 / 👎.

@davidguttman
Copy link
Contributor Author

Replying to #856 (comment)

Thanks — you’re right that ParentSessionKey flows into initSessionState (src/auto-reply/reply/session.ts) and triggers forkSessionFromParent, so an auto-created thread inherits the launcher channel’s session transcript.

Concrete example of the “pollution” risk:

  • 09:00 In an earlier thread we discuss tennis and the launcher channel transcript ends up containing “topspin drills” and/or “keep replies very short”.
  • 10:00 A new autoThread is created from #general for a different topic (e.g. “PS5 roguelikes”).
  • Because autoThread sets ParentSessionKey=#general, the new thread session is forked from the parent transcript, so the “PS5 roguelikes” thread can start out influenced by tennis/brevity instructions even though none of that appears in the thread messages.

What this does not do: it does not cause live mixing between concurrently active threads; ongoing messages are isolated because each thread has its own SessionKey, and Discord “chat history since last reply” context is keyed by message.channelId (threads are separate channelIds).

Tradeoff:

  • Advantage: inherits launcher “room memory” → fewer cold starts.
  • Disadvantage: parent transcript noise can be baked into the new thread at creation time (even though ongoing thread isolation is maintained).

@thewilloftheshadow
Copy link
Member

Squashed and merged to main.

steipete added a commit that referenced this pull request Jan 14, 2026
Build reply/session context once (no post-hoc ctx mutation) and type into the actual delivery target.

Thanks @davidguttman.

Co-authored-by: David Guttman <[email protected]>
@steipete
Copy link
Contributor

Landed on main via direct commits (not GitHub merge), then cleaned up + added coverage.

Gate: pnpm lint && pnpm build && pnpm test (all green).

Thanks @davidguttman!

@steipete steipete closed this Jan 14, 2026
steipete pushed a commit to mneves75/clawdbot that referenced this pull request Jan 15, 2026
steipete added a commit to mneves75/clawdbot that referenced this pull request Jan 15, 2026
Build reply/session context once (no post-hoc ctx mutation) and type into the actual delivery target.

Thanks @davidguttman.

Co-authored-by: David Guttman <[email protected]>
steipete added a commit to mneves75/clawdbot that referenced this pull request Jan 15, 2026
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.

3 participants