Skip to content

Comments

fix: await async assemblyApi() factory with lazy init pattern#1130

Merged
foleyatwork merged 2 commits intofeature/client-associationfrom
fix/assembly-sdk-lazy-init
Feb 18, 2026
Merged

fix: await async assemblyApi() factory with lazy init pattern#1130
foleyatwork merged 2 commits intofeature/client-associationfrom
fix/assembly-sdk-lazy-init

Conversation

@foleyatwork
Copy link
Contributor

Summary

  • The @assembly-js/node-sdk assemblyApi() factory is async and returns Promise<AssemblyAPI>, but was being assigned synchronously in the CopilotAPI constructor — causing all SDK method calls to operate on a Promise object instead of the resolved client.
  • Uses lazy init pattern: store the promise in the constructor, await it in each method. Zero changes to external call sites (new CopilotAPI(token) still works as before).
  • Renamed internal this.copilot references to assembly to reflect the company rename.

Test plan

  • Deploy to a preview environment and verify SDK calls (token payload, client retrieval, notifications, etc.) work correctly
  • Verify no regressions in task creation, comment notifications, and webhook dispatch

🤖 Generated with Claude Code

The @assembly-js/node-sdk assemblyApi() factory is async and returns a
Promise<AssemblyAPI>, but was being assigned synchronously in the
constructor. This caused all SDK method calls to operate on a Promise
object instead of the resolved client.

Uses lazy init (store the promise, await in each method) to fix this
with zero changes to external call sites.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Feb 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tasks-app Ready Ready Preview, Comment Feb 18, 2026 6:45pm

Request Review

@foleyatwork
Copy link
Contributor Author

@rrojan @arpandhakal My apologies, I was so focused on the token logic I completely forgot about this other necessary change to make assemblyApi an async function. I published a migration guide here.
https://www.notion.so/copilotplatforms/Migrating-from-copilot-node-sdk-to-assembly-js-node-sdk-30a5ddd81ef4819e82ebdfd6272ef6ff

@foleyatwork foleyatwork marked this pull request as ready for review February 17, 2026 23:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug where the assemblyApi() async factory function from @assembly-js/node-sdk was being assigned synchronously, causing all SDK method calls to operate on an unresolved Promise instead of the actual client. The fix implements a lazy initialization pattern that maintains the existing synchronous constructor interface while properly handling async initialization.

Changes:

  • Implemented lazy initialization pattern: store the Promise in the constructor, await it in each method
  • Renamed internal variable from this.copilot to assembly to reflect the company rebrand
  • Updated comment on line 79 to reference "assembly request token" instead of "copilot request token"

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
yarn.lock Added lockfile entry for copilot-node-sdk package dependency resolution
src/utils/CopilotAPI.ts Implemented lazy initialization pattern for async factory and renamed internal references from copilot to assembly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aschwartz91 aschwartz91 self-requested a review February 18, 2026 18:16
Use ReturnType<typeof assemblyApi> instead of explicit Promise<SDK>
so the type stays correct regardless of whether the SDK exports a
sync or async factory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@foleyatwork foleyatwork merged commit 5d151d5 into feature/client-association Feb 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants