Skip to content

fix(workspaces): await getAgentByName so deletion actually purges storage#675

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/await-getagentbyname-purge
Draft

fix(workspaces): await getAgentByName so deletion actually purges storage#675
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/await-getagentbyname-purge

Conversation

@posthog

@posthog posthog Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

The agents 0.18.0 upgrade (commit 7e579707) made getAgentByName async — it now returns a Promise. The workspace/account deletion lifecycle helpers called it without await and papered over the type with as unknown as, so callers ended up invoking .purgeForDeletion() / .mergeLinkedAnonymousUser() on a Promise. That threw on every invocation of the resource-purge path. The error was caught and recorded as an operational failure rather than crashing the request, so deletions appeared to succeed while the backing Durable Object storage and R2 files were never purged — leaving orphaned data, storage cost, and a data-retention problem.

This restores the awaited usage that ai/auth.ts and kernel/workspace-kernel-auth.ts already use correctly.

Changes

  • Make getUserAIStoreLifecycleAgent / getWorkspaceKernelLifecycleAgent async and await getAgentByName(...), then await them at their call sites.
  • Fix the same missing await in ai/user-ai-agents.ts (mergeLinkedAnonymousUser).
  • Drop the as unknown as casts that hid the Promise type. The DO namespaces are typed as DurableObjectNamespace<Agent>, so the awaited stub is directly assignable to the narrow lifecycle interfaces — TypeScript now catches this class of missing-await bug.

Why

Every workspace and account deletion silently failed to purge its backing storage after the 0.18.0 upgrade, and the failure was swallowed as a logged operational event — making it a quiet data-retention / orphaned-storage regression.

Test plan

  • tsc --noEmit passes with no casts (confirms the awaited stub is assignable to the interfaces, so a future missing await would fail to compile).
  • vp lint clean on the changed files.

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

getAgentByName became async in the agents 0.18.0 upgrade (commit 7e57970). The lifecycle helpers in durable-object-lifecycle.ts called it without await and hid the Promise behind `as unknown as` casts, so callers invoked purgeForDeletion()/mergeLinkedAnonymousUser() on a Promise. That threw on every invocation of the workspace/account deletion resource-purge path; the error was caught and logged as an operational failure, so deletions appeared to succeed while Durable Object storage and R2 files were never purged.

Make the two lifecycle helpers async and await getAgentByName before returning, await them at their call sites, and fix the same missing await in user-ai-agents.ts. The DO namespaces are typed as DurableObjectNamespace<Agent>, so the awaited stub is directly assignable to the narrow interfaces — dropping the `as unknown as` casts lets TypeScript catch this class of missing-await bug going forward.

Generated-By: PostHog Code
Task-Id: 9758fa8c-b4ad-444a-a67c-37ef58c46fc8
@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 2dc8004.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

0 participants