Skip to content

getWorkspace: return a lazy client synchronously #254

Closed

Description

@mattzcarey

getWorkspace(stub) is async, so it can't be assigned to a class field. Think's workspace is a class field, which is why @cloudflare/think 0.21.0 briefly shipped a lazyWorkspace(async () => getWorkspace(stub)) wrapper. We're removing that from Think in a patch; the laziness belongs here.

Today the remote path awaits __getWorkspaceStub(), then useThink, runtime.backends() and hasAssets, before returning a client. Callers often have a promise of the stub too (agents' parentAgent() is async).

Proposal:

  • getWorkspace(handle) returns a WorkspaceClient synchronously and accepts handle | Promise<handle>. The remote stub is fetched on first use; RPC promise pipelining means fs calls don't need to wait for it.
  • The metadata that's fetched up front becomes lazy. runtime.backends() is the one that matters: createAITools reads it synchronously to build exec, so a lazy client gets no exec today. Making backends() async (and createAITools await it, or build tools from an async factory) would give shared workspaces exec too.
  • await getWorkspace(...) keeps working, since awaiting a non-thenable returns it.

Then a Think agent can write:

override workspace = getWorkspace(this.parentAgent(Directory));

Callers today: agents' agent-think and examples/assistant carry a private lazyWorkspace copy until this lands.

Activity

  1. github-actions commented on Oct 20, 2026

    @github-actions
    Contributor

    Triage summary: this proposes making getWorkspace return a WorkspaceClient synchronously, accepting a handle or a promise of one. The remote stub and metadata would load lazily. runtime.backends() would become async, so createAITools could build exec for shared workspaces. The work is likely in the workspace client, runtime backends and createAITools. No similar open issues were found.

  2. added a commit that references this issue on Oct 20, 2026
    9cc3119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions