-
Notifications
You must be signed in to change notification settings - Fork 106
[Coda] Add structured workspace command action #2972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
George Ng (GeorgeNgMsft)
merged 8 commits into
main
from
georgengmsft-structured-command-execution
Sep 5, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2bef1f1
Add structured workspace command action
GeorgeNgMsft 2d7cf40
style: apply prettier formatting and policy fixes
typeagent-bot[bot] 04c487a
Reduce command action complexity
GeorgeNgMsft e768f3b
Address structured command review feedback
GeorgeNgMsft 27d39c1
Fix workspace command error shape, action ordering, and executionId c…
GeorgeNgMsft 2eec0f1
Extract and test cancellation control routing; tighten docs and test …
GeorgeNgMsft fe0661d
Document the dispatcher lock and the cancel transport bypass
GeorgeNgMsft 82151bd
Accept Windows-style command switches
GeorgeNgMsft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| .cert/ | ||
| prod/ | ||
| coverage/ | ||
| packages/coda/dist-test/ | ||
|
|
||
| # Playwright | ||
| /test-results/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // Routing table for cancellation requests that arrive from a control client | ||
| // (the Command Executor) and must be forwarded to a Coda workspace client. | ||
| // The forwarded message carries an internally allocated call id so responses | ||
| // can be matched, then mapped back to the id the requester used. | ||
| // | ||
| // Every entry must be removed exactly once, on one of: a response, the target | ||
| // disconnecting, the requester disconnecting, a delivery failure, the timeout, | ||
| // or server teardown. A leaked entry hangs the requester until its own | ||
| // timeout, so the invariant worth testing is that the table returns to empty. | ||
|
|
||
| // How long a forwarded cancellation may sit unanswered by the Coda workspace | ||
| // before the requester is told it failed. Unrelated to the runner's | ||
| // STOP_FALLBACK_MS in the Coda extension. | ||
| export const CANCELLATION_CONTROL_TIMEOUT_MS = 5_000; | ||
|
|
||
| // Only the piece of CodeAgentWebSocketServer this table needs, so the routing | ||
| // can be exercised without a live websocket server. | ||
| export interface CancellationControlTarget { | ||
| sendToClient(clientId: string, message: string): boolean; | ||
| } | ||
|
|
||
| type CancellationControlCall = { | ||
| clientId: string; | ||
| targetClientId: string; | ||
| responseId: unknown; | ||
| executionId: string; | ||
| timeout: NodeJS.Timeout; | ||
| }; | ||
|
|
||
| const cancellationControlCalls = new Map<number, CancellationControlCall>(); | ||
|
|
||
| export function cancellationControlCallCount(): number { | ||
| return cancellationControlCalls.size; | ||
| } | ||
|
|
||
| function deleteCancellationControlCall( | ||
| callId: number, | ||
| ): CancellationControlCall | undefined { | ||
| const call = cancellationControlCalls.get(callId); | ||
| if (call !== undefined) { | ||
| clearTimeout(call.timeout); | ||
| cancellationControlCalls.delete(callId); | ||
| } | ||
| return call; | ||
| } | ||
|
|
||
| export function sendCancellationControlFailure( | ||
| server: CancellationControlTarget, | ||
| call: { clientId: string; responseId: unknown; executionId: string }, | ||
| error: string, | ||
| ): void { | ||
| server.sendToClient( | ||
| call.clientId, | ||
| JSON.stringify({ | ||
| id: call.responseId, | ||
| result: JSON.stringify({ | ||
| success: false, | ||
| error, | ||
| cancelled: false, | ||
| pendingCancellation: false, | ||
| executionId: call.executionId, | ||
| }), | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| // Drops entries without answering the requester. Only correct when the server | ||
| // is going away, since the requester's connection is going away with it. | ||
| export function clearCancellationControlCalls(): void { | ||
| for (const callId of [...cancellationControlCalls.keys()]) { | ||
| deleteCancellationControlCall(callId); | ||
| } | ||
| } | ||
|
|
||
| export function forwardCancellationControlRequest( | ||
| server: CancellationControlTarget, | ||
| request: { | ||
| callId: number; | ||
| clientId: string; | ||
| targetClientId: string; | ||
| responseId: unknown; | ||
| executionId: string; | ||
| method: string; | ||
| params: Record<string, unknown>; | ||
| // Overridable so tests can exercise the timeout without waiting. | ||
| timeoutMs?: number; | ||
| }, | ||
| ): void { | ||
| const { callId } = request; | ||
| const timeout = setTimeout(() => { | ||
| const call = deleteCancellationControlCall(callId); | ||
| if (call !== undefined) { | ||
| sendCancellationControlFailure( | ||
| server, | ||
| call, | ||
| "The Coda workspace did not respond to the cancellation request.", | ||
| ); | ||
| } | ||
| }, request.timeoutMs ?? CANCELLATION_CONTROL_TIMEOUT_MS); | ||
| timeout.unref(); | ||
| cancellationControlCalls.set(callId, { | ||
| clientId: request.clientId, | ||
| targetClientId: request.targetClientId, | ||
| responseId: request.responseId, | ||
| executionId: request.executionId, | ||
| timeout, | ||
| }); | ||
| if ( | ||
| !server.sendToClient( | ||
| request.targetClientId, | ||
| JSON.stringify({ | ||
| id: callId, | ||
| method: request.method, | ||
| params: { ...request.params, allowPendingCancellation: true }, | ||
| }), | ||
| ) | ||
| ) { | ||
| const call = deleteCancellationControlCall(callId); | ||
| if (call !== undefined) { | ||
| sendCancellationControlFailure( | ||
| server, | ||
| call, | ||
| "The Coda workspace disconnected before the cancellation request could be delivered.", | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Returns true when the message was a forwarded cancellation response and has | ||
| // been routed back to the requester under its original id. | ||
| export function resolveCancellationControlResponse( | ||
| server: CancellationControlTarget, | ||
| data: { id?: unknown; result?: unknown }, | ||
| ): boolean { | ||
| const call = deleteCancellationControlCall(Number(data.id)); | ||
| if (call === undefined) { | ||
| return false; | ||
| } | ||
| server.sendToClient( | ||
| call.clientId, | ||
| JSON.stringify({ ...data, id: call.responseId }), | ||
| ); | ||
| return true; | ||
| } | ||
|
|
||
| export function handleCancellationControlDisconnect( | ||
| server: CancellationControlTarget, | ||
| clientId: string, | ||
| ): void { | ||
| for (const [callId, call] of [...cancellationControlCalls]) { | ||
| if (call.clientId !== clientId && call.targetClientId !== clientId) { | ||
| continue; | ||
| } | ||
| deleteCancellationControlCall(callId); | ||
| // Only the requester is still around to hear about it. | ||
| if (call.targetClientId === clientId && call.clientId !== clientId) { | ||
| sendCancellationControlFailure( | ||
| server, | ||
| call, | ||
| "The Coda workspace disconnected before responding to the cancellation request.", | ||
| ); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.