-
Notifications
You must be signed in to change notification settings - Fork 262
Fix 12 documentation accuracy issues across API reference, foundations, and AI docs #1200
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
Changes from all commits
ea66ca7
e380cfb
cd4015d
d447507
9fe76fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,7 @@ export async function GET(req: Request) { | |
| Cancel a running workflow: | ||
|
|
||
| ```typescript lineNumbers | ||
| import { getWorld } from "workflow/runtime"; | ||
| import { getWorld, cancelRun } from "@workflow/core/runtime"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As pranaygp noted in the earlier thread, this should use the public API: import { getRun } from "workflow/runtime";
export async function POST(req: Request) {
const { runId } = await req.json();
// ...
const run = getRun(runId);
await run.cancel();
return Response.json({ status: "cancelled" });
}
|
||
|
|
||
| export async function POST(req: Request) { | ||
| const { runId } = await req.json(); | ||
|
|
@@ -79,9 +79,9 @@ export async function POST(req: Request) { | |
|
|
||
| try { | ||
| const world = getWorld(); // [!code highlight] | ||
| const run = await world.runs.cancel(runId); // [!code highlight] | ||
| await cancelRun(world, runId); // [!code highlight] | ||
|
|
||
| return Response.json({ status: run.status }); | ||
| return Response.json({ status: "cancelled" }); | ||
| } catch (error) { | ||
| return Response.json( | ||
| { error: "Failed to cancel workflow run" }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,10 +34,13 @@ A World connects workflows to the infrastructure that powers them. The World int | |
| ```typescript | ||
| interface World extends Storage, Queue, Streamer { | ||
| start?(): Promise<void>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified: the |
||
| close?(): Promise<void>; | ||
| getEncryptionKeyForRun?(run: WorkflowRun): Promise<Uint8Array | undefined>; | ||
| getEncryptionKeyForRun?(runId: string, context?: Record<string, unknown>): Promise<Uint8Array | undefined>; | ||
| } | ||
| ``` | ||
|
|
||
| The optional `start()` method initializes any background tasks needed by your World (e.g., queue polling). | ||
| The optional `start()` method initializes background tasks (for example, queue polling). The optional `close()` method releases resources like connection pools and listeners. The optional `getEncryptionKeyForRun()` method returns the AES-256 key used to encrypt data for a run; if it is not implemented, encryption is disabled. | ||
|
|
||
| ## The Event Log Model | ||
|
|
||
|
|
@@ -63,8 +66,8 @@ interface Storage { | |
| }; | ||
|
|
||
| events: { | ||
| // Create a new workflow run (runId must be null - server generates it) | ||
| create(runId: null, data: RunCreatedEventRequest, params?: CreateEventParams): Promise<EventResult>; | ||
| // Create a new workflow run (runId may be client-provided or null for server generation) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: The source code doc comment (interfaces.ts:130) says: "The runId may be provided by the client or left as null for the server to generate." Consider matching this wording exactly for consistency between source and docs. |
||
| create(runId: string | null, data: RunCreatedEventRequest, params?: CreateEventParams): Promise<EventResult>; | ||
|
|
||
| // Create an event for an existing run | ||
| create(runId: string, data: CreateEventRequest, params?: CreateEventParams): Promise<EventResult>; | ||
|
|
@@ -88,7 +91,7 @@ interface Storage { | |
| 2. Atomically update the affected entity (run, step, or hook) | ||
| 3. Return both the created event and the updated entity | ||
|
|
||
| **Run Creation:** For `run_created` events, the `runId` parameter is `null`. Your World generates and returns a new `runId`. | ||
| **Run Creation:** For `run_created` events, the `runId` parameter may be a client-provided string or `null`. When `null`, your World generates and returns a new `runId`. | ||
|
|
||
| **Hook Tokens:** Hook tokens must be unique. If a `hook_created` event conflicts with an existing token, return a `hook_conflict` event instead. | ||
|
|
||
|
|
@@ -165,13 +168,19 @@ The Streamer interface enables real-time data streaming: | |
| interface Streamer { | ||
| writeToStream( | ||
| name: string, | ||
| runId: string | Promise<string>, | ||
| runId: string, | ||
| chunk: string | Uint8Array | ||
| ): Promise<void>; | ||
|
|
||
| writeToStreamMulti?( | ||
| name: string, | ||
| runId: string, | ||
| chunks: (string | Uint8Array)[] | ||
| ): Promise<void>; | ||
|
|
||
| closeStream( | ||
| name: string, | ||
| runId: string | Promise<string> | ||
| runId: string | ||
| ): Promise<void>; | ||
|
|
||
| readFromStream( | ||
|
|
@@ -184,6 +193,7 @@ interface Streamer { | |
| ``` | ||
|
|
||
| Streams are identified by a combination of `runId` and `name`. Each workflow run can have multiple named streams. | ||
| `writeToStreamMulti()` is an optional optimization for batching multiple writes. | ||
|
|
||
| ## Reference Implementations | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah the correct way to programmatically cancel a run is
await getRun(runId).cancel()- notcancelRunfrom world. We don't adequately document it though so good call on making this. We should include an example ingetRunapi reference for cancelling a run so that it's searchable by AI. right now it's not well documentedAlso users should almost never be importing from
@workflow/corefor normal usage.workflow/apishould be what people use for normal behavior. usinggetWorldis an advanced/low level features that will break often as we change things around and not meant to be relied onThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least once we actually have a different way of querying the same data, which we won't for a while? In which case it wouldn't hurt to document. Users could already be relying on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should document it and then have to support it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also like I said, for now the fix is simple. we have
run.cancel(). let's document that instead of telling people to use@workflow/core/runtimewhich is never meant to be user facing