From 358487135ffb2a5518f2a0e4be529916216fb964 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Sun, 17 Nov 2024 13:26:09 +0530 Subject: [PATCH 1/4] fix: global execution queue added --- app/lib/runtime/action-runner.ts | 11 +++++++++-- app/lib/stores/workbench.ts | 28 +++++++++++++++++++++------- diff.txt | 0 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 diff.txt diff --git a/app/lib/runtime/action-runner.ts b/app/lib/runtime/action-runner.ts index f94390b..e38a8ce 100644 --- a/app/lib/runtime/action-runner.ts +++ b/app/lib/runtime/action-runner.ts @@ -94,7 +94,7 @@ export class ActionRunner { this.#updateAction(actionId, { ...action, ...data.action, executed: !isStreaming }); - this.#currentExecutionPromise = this.#currentExecutionPromise + return this.#currentExecutionPromise = this.#currentExecutionPromise .then(() => { return this.#executeAction(actionId, isStreaming); }) @@ -119,7 +119,14 @@ export class ActionRunner { break; } case 'start': { - await this.#runStartAction(action) + // making the start app non blocking + + this.#runStartAction(action).then(()=>this.#updateAction(actionId, { status: 'complete' })) + .catch(()=>this.#updateAction(actionId, { status: 'failed', error: 'Action failed' })) + // adding a delay to avoid any race condition between 2 start actions + // i am up for a better approch + await new Promise(resolve=>setTimeout(resolve,2000)) + return break; } } diff --git a/app/lib/stores/workbench.ts b/app/lib/stores/workbench.ts index 8589391..b176141 100644 --- a/app/lib/stores/workbench.ts +++ b/app/lib/stores/workbench.ts @@ -42,7 +42,7 @@ export class WorkbenchStore { modifiedFiles = new Set(); artifactIdList: string[] = []; #boltTerminal: { terminal: ITerminal; process: WebContainerProcess } | undefined; - + #globalExecutionQueue=Promise.resolve(); constructor() { if (import.meta.hot) { import.meta.hot.data.artifacts = this.artifacts; @@ -52,6 +52,10 @@ export class WorkbenchStore { } } + addToExecutionQueue(callback: () => Promise) { + this.#globalExecutionQueue=this.#globalExecutionQueue.then(()=>callback()) + } + get previews() { return this.#previewsStore.previews; } @@ -255,8 +259,10 @@ export class WorkbenchStore { this.artifacts.setKey(messageId, { ...artifact, ...state }); } - - async addAction(data: ActionCallbackData) { + addAction(data: ActionCallbackData) { + this.addToExecutionQueue(()=>this._addAction(data)) + } + async _addAction(data: ActionCallbackData) { const { messageId } = data; const artifact = this.#getArtifact(messageId); @@ -265,10 +271,18 @@ export class WorkbenchStore { unreachable('Artifact not found'); } - artifact.runner.addAction(data); + return artifact.runner.addAction(data); } - async runAction(data: ActionCallbackData, isStreaming: boolean = false) { + runAction(data: ActionCallbackData, isStreaming: boolean = false) { + if(isStreaming) { + this._runAction(data, isStreaming) + } + else{ + this.addToExecutionQueue(()=>this._runAction(data, isStreaming)) + } + } + async _runAction(data: ActionCallbackData, isStreaming: boolean = false) { const { messageId } = data; const artifact = this.#getArtifact(messageId); @@ -293,11 +307,11 @@ export class WorkbenchStore { this.#editorStore.updateFile(fullPath, data.action.content); if (!isStreaming) { - this.resetCurrentDocument(); await artifact.runner.runAction(data); + this.resetCurrentDocument(); } } else { - artifact.runner.runAction(data); + await artifact.runner.runAction(data); } } diff --git a/diff.txt b/diff.txt new file mode 100644 index 0000000..e69de29 From 17cfc16d4694dada77961b26aff1baf1f3af54c7 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Sun, 17 Nov 2024 13:27:27 +0530 Subject: [PATCH 2/4] chor: clean up unnecesary files --- diff.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 diff.txt diff --git a/diff.txt b/diff.txt deleted file mode 100644 index e69de29..0000000 From c0873bc552d8e2c92b09fda1641b0df208db860f Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Sun, 17 Nov 2024 14:15:40 +0530 Subject: [PATCH 3/4] excluded the action from execution pipeline --- app/lib/stores/workbench.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/lib/stores/workbench.ts b/app/lib/stores/workbench.ts index b176141..3e9806c 100644 --- a/app/lib/stores/workbench.ts +++ b/app/lib/stores/workbench.ts @@ -260,7 +260,8 @@ export class WorkbenchStore { this.artifacts.setKey(messageId, { ...artifact, ...state }); } addAction(data: ActionCallbackData) { - this.addToExecutionQueue(()=>this._addAction(data)) + this._addAction(data) + // this.addToExecutionQueue(()=>this._addAction(data)) } async _addAction(data: ActionCallbackData) { const { messageId } = data; From 49f9d8b760bd0cee500070fb0dfc02a259c11456 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Sun, 17 Nov 2024 14:24:29 +0530 Subject: [PATCH 4/4] chore: ui fix --- app/lib/stores/workbench.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/stores/workbench.ts b/app/lib/stores/workbench.ts index 3e9806c..1dbfc5b 100644 --- a/app/lib/stores/workbench.ts +++ b/app/lib/stores/workbench.ts @@ -309,7 +309,7 @@ export class WorkbenchStore { if (!isStreaming) { await artifact.runner.runAction(data); - this.resetCurrentDocument(); + this.resetAllFileModifications(); } } else { await artifact.runner.runAction(data);