Skip to content

feat(desktop): /clear a finished cloud run without booting a sandbox - #82950

Merged
trunk-io[bot] merged 5 commits into
masterfrom
posthog/clear-command-desktop
Aug 19, 2026
Merged

feat(desktop): /clear a finished cloud run without booting a sandbox#82950
trunk-io[bot] merged 5 commits into
masterfrom
posthog/clear-command-desktop

Conversation

@haacked

@haacked haacked commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Typing /clear on a finished cloud run in the desktop app boots a whole sandbox: resume the run, rebuild the conversation, clear it, idle. A full run's cost to clear a conversation the next run rebuilds from the log anyway.

#76943 added the backend boundary endpoint and the web composer support. The desktop app still pays the sandbox.

Changes

  • The session service routes a /clear on a finished cloud run to POST runs/{id}/clear_conversation instead of resuming.
  • After the POST, the client repaints the thread from the updated run log.
  • The repainted pair carries the backend's timestamps, so a later resume folds it instead of rendering the /clear and divider twice.
  • If the log read lags the append, the repaint retries briefly, then paints a local fallback so the clear stays visible.
  • A repeat /clear on an already-cleared run does nothing and sends nothing.
  • The path is gated on the agent's conversationClear capability from the run log. An older agent gets today's behavior: an ordinary resume, and the agent performs the clear itself.

Note

Depends on #76943's endpoint, now live (verified in US production, 2026-08-14). Against an older backend, /clear on a finished run surfaces "Couldn't clear the conversation." and paints nothing.

No visible change outside the /clear flow.

How did you test this code?

  • sessionServiceCloudClear.test.ts (new, 8 tests) pins the contract:
    • The painted frames come from the persisted log and carry the backend's timestamps.
    • A repeat /clear short-circuits with no second POST.
    • A lagging log read retries before painting the local fallback.
    • A backend rejection propagates and paints nothing.
    • Prompts without the capability, or that are not /clear, fall through to an ordinary resume.
    • Reconciliation folds a log-derived pair on resume; a locally stamped pair duplicates. That duplication is the regression the repaint exists to prevent.
  • Manual test in the dev app against US production:
    • /clear on a finished run painted the message and divider with no sandbox boot and no new run.
    • A second /clear changed nothing.
    • The pair survived a full app reload with the server's timestamp, so it came from the persisted log, not the fallback.
    • A follow-up message resumed into a new run. The thread kept exactly one pair through the resume and another reload.
    • The resumed agent reported no pre-clear context.
  • Not run: desktop e2e. The old-agent fallback and the stale-read retry are not reachable manually; the unit tests above cover them.

Automatic notifications

  • Publish to changelog?

Docs update

None. No user-facing docs cover /clear yet.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Split out of #76943 by Claude Code (PostHog Desktop session) after the "Desktop backend coupling" check required separating desktop from backend changes; the commit content matches what charlesvien approved there. The duplicate-pair fix, review follow-ups, and the CDP-driven manual test were agent-executed with human approval at each decision. Skills invoked across the sessions: /stacking-prs, /writing-tests, /writing-code-comments, /writing-pr-descriptions, /resolve-conflicts, /address-pr-reviews, /simplify, /review-code, /squash, test-electron-app.


Created with PostHog Desktop

@haacked haacked self-assigned this Aug 13, 2026
@trunk-io

trunk-io Bot commented Aug 13, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

React Doctor found 9 issues in 4 files · 9 warnings.

9 warnings

packages/ui/src/features/canvas/components/ChannelsList.tsx

packages/ui/src/features/canvas/hooks/useOrgMembers.ts

packages/ui/src/features/command/CommandMenu.tsx

packages/ui/src/features/sidebar/components/items/TaskIcon.tsx

Reviewed by React Doctor for commit 5716fe0.

@hosthog

hosthog Bot commented Aug 13, 2026

Copy link
Copy Markdown

HostHog preview — posthog-desktop-web

The previews for this PR have been torn down and no longer serve.

@trunk-io

trunk-io Bot commented Aug 13, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@haacked
haacked force-pushed the posthog/clear-command-desktop branch from b237ecd to 12252ee Compare August 15, 2026 19:34
@haacked haacked added the reviewhog ($$$) Reviews pull requests before humans do label Aug 15, 2026
@posthog

posthog Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦔 ReviewHog reviewed this pull request

Found 0 must fix, 0 should fix, 1 consider.

Published 1 finding (view the review).

@posthog

posthog Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

ReviewHog Alpha 🦔 If you find any issues helpful - please reply "valid", "invalid", etc., for evaluation purposes 🙏

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ReviewHog Report

Found 1 consider.

Comment thread products/desktop/packages/core/src/sessions/sessionService.ts
@posthog posthog Bot removed the reviewhog ($$$) Reviews pull requests before humans do label Aug 15, 2026
@haacked
haacked force-pushed the posthog/clear-command-desktop branch from 12252ee to 7648ebc Compare August 15, 2026 19:56
@haacked
haacked marked this pull request as ready for review August 16, 2026 19:21
Copilot AI lite review requested due to automatic review settings August 16, 2026 19:22
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team August 16, 2026 19:22
@greptile-apps

greptile-apps Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
products/desktop/packages/shared/src/slash-commands.ts:14-18
**Use the standard absence sentinel**

`leadingSlashCommand` introduces `undefined` as an intentional absent result and codifies it across the shared API, callers, and tests. Use `null` for the no-command result to follow the repository convention and avoid a broader cleanup later.

### Issue 2
products/desktop/packages/core/src/sessions/sessionServiceCloudClear.test.ts:76-111
**Preserve dependency mock type safety**

The new harness double-casts an incomplete dependency object through `unknown`, preventing TypeScript from checking it against `SessionServiceDeps`. This allows required dependency changes to produce runtime-only test failures instead of identifying an incomplete mock during type checking.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "feat(desktop): /clear a finished cloud r..." | Re-trigger Greptile

Comment thread products/desktop/packages/shared/src/slash-commands.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Routes /clear on terminal (finished) cloud runs in the PostHog Desktop app through the backend “clear conversation boundary” endpoint, avoiding the cost of resuming/booting a sandbox just to clear a conversation that will be rebuilt from logs anyway.

Changes:

  • Added a shared leadingSlashCommand helper so the desktop client and agent adapter use the same “leading /command token” detection.
  • Updated SessionService to call the cloud clear_conversation endpoint (when the run is terminal and the capability is present) and repaint the thread from persisted logs, with a small retry budget for S3-read lag.
  • Added targeted tests for the finished-cloud-run /clear path, including retry/fallback behavior and dedupe on later resume hydration.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
products/desktop/packages/shared/src/slash-commands.ts Introduces shared leading slash-command tokenizer for dispatch parity.
products/desktop/packages/shared/src/slash-commands.test.ts Unit tests for the shared slash-command tokenizer behavior.
products/desktop/packages/shared/src/index.ts Re-exports leadingSlashCommand from the shared package.
products/desktop/packages/core/src/sessions/sessionServiceCloudClear.test.ts Adds a focused test suite covering /clear on finished cloud runs (endpoint call, repaint, retry, fallback, dedupe).
products/desktop/packages/core/src/sessions/sessionService.ts Adds terminal-run /clear routing to clear_conversation + repaint logic, with retry/fallback.
products/desktop/packages/core/src/sessions/sessionEvents.ts Adds local fallback event creation for “conversation cleared” frames and documents log promotion behavior.
products/desktop/packages/api-client/src/posthog-client.ts Adds clearTaskRunConversation API client method for the new backend endpoint.
products/desktop/packages/agent/src/adapters/claude/claude-agent.ts Switches adapter command detection to use shared leadingSlashCommand for parity.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread products/desktop/packages/api-client/src/posthog-client.ts
The session service routes a /clear on a finished cloud run to POST
runs/{id}/clear_conversation instead of resuming into a sandbox. After
the call succeeds, it rehydrates the session from the updated run log,
so the painted /clear message and the cleared divider carry the
backend's persisted timestamps; that lets resume-time reconciliation
fold them into a single copy instead of rendering the pair twice. A
locally stamped fallback pair covers the rare case where the log fetch
cannot confirm the boundary landed.

The path is gated on the agent's conversationClear capability from the
run log. An older agent ignores the marker and resumes the
conversation itself, so an ordinary resume is the honest degradation
when the capability is absent.

A shared tokenizer (leadingSlashCommand in @posthog/shared) keeps the
desktop client's /clear detection identical to the agent adapter's,
and clear_conversation errors surface through the existing
extractRequestErrorMessage helper.

Generated-By: PostHog Desktop
Task-Id: 2578f561-b94e-46ac-8546-d3368f5098bb
@haacked
haacked force-pushed the posthog/clear-command-desktop branch from 7648ebc to 5efd513 Compare August 16, 2026 19:33
@haacked

haacked commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

/trunk merge

@github-actions

Copy link
Copy Markdown
Contributor

🤖 CI report

Trunk lane — does not run backend Python tests

This PR is assigned to a lane that does not run backend Python tests.

extractRequestErrorMessage passed through any non-empty error/detail
string from the backend, including Django's generic {"detail":"Not
found."} for an unmatched route. On a pre-#76943 backend without the
clear_conversation endpoint, that surfaced /clear's failure as a bare
"Not found." with no indication a clear was attempted or what to do
next. Treat that literal DRF placeholder as non-actionable and fall
through to the endpoint's own fallback message plus status code.

Generated-By: PostHog Desktop
Task-Id: 2578f561-b94e-46ac-8546-d3368f5098bb
hydrateCloudTaskSessionFromLogs probes getTaskRunSessionLogsPage before
falling back to getTaskRunSessionLogsResult. The harness only stubbed
the latter, so the probe threw, the hydration bailed early, and the
repaint assertions never saw a call.

Generated-By: PostHog Desktop
Task-Id: 2578f561-b94e-46ac-8546-d3368f5098bb
@trunk-io
trunk-io Bot merged commit 18faff8 into master Aug 19, 2026
194 checks passed
@trunk-io
trunk-io Bot deleted the posthog/clear-command-desktop branch August 19, 2026 12:28
@deployment-status-posthog

deployment-status-posthog Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-08-19 13:09 UTC Run
prod-us ✅ Deployed 2026-08-19 13:30 UTC Run
prod-eu ✅ Deployed 2026-08-19 13:27 UTC Run

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

Labels

feature/desktop Feature Tag: Desktop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants