Skip to content

fix(workspaces): await lifecycle agent lookups#676

Merged
urjitc merged 1 commit into
mainfrom
codex/await-deletion-purge
Jul 26, 2026
Merged

fix(workspaces): await lifecycle agent lookups#676
urjitc merged 1 commit into
mainfrom
codex/await-deletion-purge

Conversation

@urjitc

@urjitc urjitc commented Jul 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Await getAgentByName() before invoking user and workspace lifecycle methods.
  • Fix the nested anonymous-user lookup used during account linking.
  • Remove the as unknown as casts that hid Promise/stub type mismatches.

Why

getAgentByName() returns a Promise and has done so since the repository's original Agents 0.17.x integration. The lifecycle helpers cast that Promise to narrow agent interfaces, so deletion attempted to call purgeForDeletion() on the Promise itself.

Those calls threw before Durable Object or R2 cleanup began. The purge wrappers recorded the failure and returned a failed result, allowing the database deletion to complete while backing storage could remain orphaned.

The workspace regression was introduced when commit f4d1022b replaced the previously awaited getWorkspaceKernel() path with the unawaited lifecycle helper. It was not caused by the later Agents 0.18.0 upgrade.

Changes

  • Make both lifecycle lookup helpers async with explicit Promise return types.
  • Await those helpers in workspace deletion, account deletion, and account-link transfer paths.
  • Await the anonymous UserAIStore lookup inside mergeLinkedAnonymousUser().
  • Keep the existing best-effort purge and operational-event behavior unchanged.

Testing

  • pnpm vp check
  • pnpm test -- --run — 29 files, 102 tests passed
  • git diff --check

Review Notes

The important review boundary is the removal of all three unsafe lifecycle casts. With explicit awaited assignments, TypeScript will reject the same missing-await pattern in these paths.


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

Summary by CodeRabbit

  • Bug Fixes
    • Improved account linking and workspace lifecycle operations by ensuring background agent actions complete reliably.
    • Increased reliability when purging user data and transferring resources during account or workspace cleanup.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 75d81354-8e39-4085-9727-89e46a0daeda

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/await-deletion-purge

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit a67c2b8.

@urjitc
urjitc marked this pull request as ready for review July 26, 2026 07:00
@cursor

cursor Bot commented Jul 26, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Auto-approved: Fixes missing awaits on agent lifecycle lookups that caused runtime errors; removes unsafe casts. A focused, bounded bug fix with no new behavior or tradeoffs.

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR corrects asynchronous Durable Object agent resolution.

  • Awaits user and workspace lifecycle-agent lookups before invoking purge or account-link operations.
  • Awaits the anonymous-user store lookup before exporting and transferring AI threads.
  • Replaces unsafe double casts with explicit Promise-based lifecycle interfaces.

Confidence Score: 5/5

The PR appears safe to merge, with the changed lifecycle paths now resolving agent stubs before invoking their methods.

The awaited lookups match the asynchronous getAgentByName contract while preserving existing purge aggregation, failure recording, and account-link transfer ordering.

T-Rex T-Rex Logs

What T-Rex did

  • Ran the contract-validation suite and static checks to exercise lifecycle-agent-resolution and anonymous-agent-resolution flows.
  • Compared lifecycle-agent-resolution-01-before.log against lifecycle-agent-resolution-02-after.log to confirm the before-state prevented purge calls for unresolved promises and the after-state shows all three paths passing.
  • Compared anonymous-agent-resolution-01-before.log against anonymous-agent-resolution-02-after.log to verify the after-state carries lookup resolution followed by export and purge.
  • Reviewed the captured suite and static-check outputs to verify that the exact commands, working directories, and exit codes were recorded for audit.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/features/workspaces/ai/user-ai-agents.ts Correctly awaits the anonymous UserAIStore lookup before exporting, importing, and purging linked-account resources.
src/features/workspaces/durable-object-lifecycle.ts Correctly makes lifecycle lookups asynchronous and awaits their resolved RPC stubs at all affected deletion and transfer call sites.

Reviews (1): Last reviewed commit: "fix(workspaces): await lifecycle agent l..." | Re-trigger Greptile

@urjitc
urjitc merged commit fa8fb7e into main Jul 26, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Dev Board Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant