Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(posthog-ai): hide the Slack context wrapper and align the card's copy icon (#99427)

Jake Ruth77c6dd934ffc
diff --git a/products/posthog_ai/frontend/components/RunAlertActivity.tsx b/products/posthog_ai/frontend/components/RunAlertActivity.tsx
index 252159bfd7dc..e8c20b0b9fad 100644
--- a/products/posthog_ai/frontend/components/RunAlertActivity.tsx
+++ b/products/posthog_ai/frontend/components/RunAlertActivity.tsx
@@ -1,4 +1,4 @@
-import { IconWarning } from '@posthog/icons'
+import { IconCopy, IconWarning } from '@posthog/icons'
import { LemonButton, Spinner } from '@posthog/lemon-ui'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
@@ -67,7 +67,18 @@ export function RunAlertActivity({
>
<div className="flex items-center gap-2 font-semibold">
<IconWarning className="size-4 shrink-0 text-danger" />
- <span>{TITLES[kind]}</span>
+ <span className="grow">{TITLES[kind]}</span>
+ {copyDetails && (
+ <LemonButton
+ type="tertiary"
+ size="xsmall"
+ className="-my-1 -mr-1"
+ icon={<IconCopy />}
+ tooltip="Copy run details for support"
+ onClick={() => void copyToClipboard(copyDetails, 'run details')}
+ data-attr="run-error-copy-details"
+ />
+ )}
</div>
<div className="pl-6 flex flex-col gap-1 text-secondary">
{message ? <MarkdownMessage content={message} id={`${activityId}-message`} /> : null}
@@ -75,18 +86,6 @@ export function RunAlertActivity({
<div>Your last message was not delivered.</div>
) : null}
</div>
- {copyDetails && (
- <div className="pl-6 flex items-center">
- <LemonButton
- type="tertiary"
- size="xsmall"
- onClick={() => void copyToClipboard(copyDetails, 'run details')}
- data-attr="run-error-copy-details"
- >
- Copy details
- </LemonButton>
- </div>
- )}
</div>
)
}
diff --git a/products/posthog_ai/frontend/logics/runStreamLogic.test.ts b/products/posthog_ai/frontend/logics/runStreamLogic.test.ts
index 7f24eb3124f4..a11a71013367 100644
--- a/products/posthog_ai/frontend/logics/runStreamLogic.test.ts
+++ b/products/posthog_ai/frontend/logics/runStreamLogic.test.ts
@@ -1221,9 +1221,20 @@ describe('runStreamLogic', () => {
expect(logic.values.threadItems[0]).toMatchObject({ type: 'human_message', text: 'first second' })
})
- it('strips the posthog_context wrapper so a replayed prompt matches the live one', async () => {
- const wrapped =
- '<posthog_context>\nThe user attached the following PostHog entities.\n- Insight #1\n</posthog_context>\n\nWhy did signups drop?'
+ it.each([
+ [
+ 'legacy posthog_context',
+ '<posthog_context>\nThe user attached the following PostHog entities.\n- Insight #1\n</posthog_context>\n\nWhy did signups drop?',
+ ],
+ [
+ 'slack thread context on a task started from Slack',
+ '<slack_thread_context>\nSlack thread leading up to the request.\n<@U1|Someone>:\n it is broken\n</slack_thread_context>\n\nWhy did signups drop?',
+ ],
+ [
+ 'slack thread update on a follow-up from Slack',
+ '<slack_thread_context_update>\nMessages posted since you last spoke.\n</slack_thread_context_update>\n\nWhy did signups drop?',
+ ],
+ ])('strips a leading %s wrapper from a replayed human message', async (_name, wrapped) => {
const frames: StoredLogEntry[] = [notification('_posthog/user_message', { content: wrapped })]
jest.spyOn(api.tasks.runs, 'getLogEntries').mockResolvedValue(frames as any)
jest.spyOn(api.tasks.runs, 'get').mockResolvedValue({ status: 'completed' } as any)
diff --git a/products/posthog_ai/frontend/logics/runStreamLogic.ts b/products/posthog_ai/frontend/logics/runStreamLogic.ts
index 6f54295b0fd1..3865aadba9f6 100644
--- a/products/posthog_ai/frontend/logics/runStreamLogic.ts
+++ b/products/posthog_ai/frontend/logics/runStreamLogic.ts
@@ -292,10 +292,18 @@ export function mapHttpStatusToStreamError(status: number | undefined): StreamEr
* prepend context blocks when attachments are present — `<posthog_trusted_context>` and/or
* `<posthog_untrusted_context>` from the frontend builder (`utils/posthogContextBlock.ts`), or the
* legacy `<posthog_context>` wrapper from the deprecated backend `context_wrapper.py` path and old
- * persisted history. Stripping every leading block keeps a replayed prompt identical to the one the
- * live send path echoed via `pushHumanMessage`.
+ * persisted history. A task started from Slack carries the thread as `<slack_thread_context>`, and
+ * each Slack follow-up as `<slack_thread_context_update>` (products/slack_app). Stripping every
+ * leading block keeps a replayed prompt identical to the one the live send path echoed via
+ * `pushHumanMessage`.
*/
-const CONTEXT_BLOCK_TAGS = ['posthog_trusted_context', 'posthog_untrusted_context', 'posthog_context']
+const CONTEXT_BLOCK_TAGS = [
+ 'posthog_trusted_context',
+ 'posthog_untrusted_context',
+ 'posthog_context',
+ 'slack_thread_context',
+ 'slack_thread_context_update',
+]
export interface SplitUserMessageContent {
/** The user's own text, with every leading context block removed. */