fix(cli): clarify asyncTaskId vs generationId in gen status/download + better error message (#14230)

* 🔖 chore(release): release version v2.1.53 [skip ci]

* fix(cli): improve gen status/download error message for wrong asyncTaskId

* docs(cli-skill): clarify asyncTaskId vs generationId in gen status/download

* fix(builtin-skills): clarify asyncTaskId vs generationId in gen status/download

* fix(cli): distinguish asyncTaskId not found vs generationId not found in error message

* Update package.json

---------

Co-authored-by: lobehubbot <i@lobehub.com>
This commit is contained in:
Arvin Xu
2026-04-27 23:16:05 +08:00
committed by GitHub
parent a4235d3f68
commit ef5be7e17c
3 changed files with 176 additions and 51 deletions
+60 -35
View File
@@ -8,16 +8,20 @@ Generate text, images, videos, speech, and transcriptions.
```
lh generate (alias: gen)
├── text <prompt> # Text generation
├── image <prompt> # Image generation
├── video <prompt> # Video generation
├── tts <text> # Text-to-speech
├── asr <audioFile> # Audio-to-text (speech recognition)
├── download <genId> <taskId> # Wait & download generation result
├── status <genId> <taskId> # Check async task status
└── list # List generation topics
├── text <prompt> # Text generation
├── image <prompt> # Image generation
├── video <prompt> # Video generation
├── tts <text> # Text-to-speech
├── asr <audioFile> # Audio-to-text (speech recognition)
├── download <generationId> <asyncTaskId> # Wait & download generation result
├── status <generationId> <asyncTaskId> # Check async task status
└── list # List generation topics
```
> ⚠️ **Important**: `status` and `download` require an `asyncTaskId` (UUID format, e.g.
> `7ad0eb13-e9a5-4403-8070-1f7fe95b2f95`), **not** the generation ID (`gen_xxx`).
> The asyncTaskId is printed after "→ Task" in the `video` / `image` command output.
---
## `lh generate text <prompt>` / `lh gen text <prompt>`
@@ -54,7 +58,7 @@ cat README.md | lh gen text "summarize this" --pipe
## `lh generate image <prompt>` / `lh gen image <prompt>`
Generate images from text prompt. This is an async operation — the command submits the task and returns a generation ID + task ID for tracking.
Generate images from text prompt. This is an async operation — the command submits the task and returns a generation ID + async task ID for tracking.
**Source**: `apps/cli/src/commands/generate/image.ts`
@@ -80,17 +84,22 @@ lh gen image "A cute cat" --model dall-e-3 --provider openai --json
✓ Image generation started
Batch ID: gb_xxx
1 image(s) queued
Generation gen_xxx → Task <taskId>
Generation gen_xxx → Task 7ad0eb13-xxxx-xxxx-xxxx-xxxxxxxxxxxx
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the asyncTaskId — use this for status/download
Use "lh generate status <generationId> <taskId>" to check progress.
Use "lh generate status <generationId> <asyncTaskId>" to check progress.
```
**Typical workflow**:
```bash
# Generate image, then wait & download
# 1. Submit generation — note down BOTH IDs from the output
lh gen image "A cute cat"
lh gen download <generationId> <taskId> -o cat.png
# Generation gen_abc123 → Task 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95
# 2. Wait & download using generationId + asyncTaskId (the UUID)
lh gen download gen_abc123 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95 -o cat.png
```
---
@@ -102,7 +111,7 @@ Generate video from text prompt. This is an async operation.
**Source**: `apps/cli/src/commands/generate/video.ts`
```bash
lh gen video "A cat playing piano" -m < model > -p < provider > [options]
lh gen video "A cat playing piano" -m <model> -p <provider> [options]
```
| Option | Description | Required |
@@ -122,9 +131,26 @@ lh gen video "A cat playing piano" -m < model > -p < provider > [options]
```
✓ Video generation started
Batch ID: gb_xxx
Generation gen_xxx → Task <taskId>
Generation gen_xxx → Task 7ad0eb13-xxxx-xxxx-xxxx-xxxxxxxxxxxx
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the asyncTaskId — use this for status/download
Use "lh generate status <generationId> <taskId>" to check progress.
Use "lh generate status <generationId> <asyncTaskId>" to check progress.
```
**Typical workflow**:
```bash
# 1. Find available video models for a provider
lh model list volcengine --json | grep -i seedance
# 2. Submit generation — note down BOTH IDs from the output
lh gen video "A cat on a runway" -m doubao-seedance-2-0-260128 -p volcengine \
--aspect-ratio 9:16 --duration 5 --resolution 1080p
# Generation gen_abc123 → Task 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95
# 3. Wait & download using generationId + asyncTaskId (the UUID)
lh gen download gen_abc123 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95 -o result.mp4 --timeout 600
```
---
@@ -153,15 +179,18 @@ lh gen asr recording.wav [options]
---
## `lh generate download <generationId> <taskId>`
## `lh generate download <generationId> <asyncTaskId>`
Wait for an async generation task to complete and download the result file.
**Source**: `apps/cli/src/commands/generate/index.ts`
> ⚠️ `<asyncTaskId>` is the UUID printed after "→ Task" in the video/image output.
> Do **not** pass the generation ID (`gen_xxx`) here — that will cause a server error.
```bash
lh gen download <generationId> <taskId> [-o output.png]
lh gen download gen_xxx task_xxx -o ~/Desktop/result.mp4 --timeout 600
lh gen download <generationId> <asyncTaskId> [-o output.png]
lh gen download gen_xxx 7ad0eb13-xxxx-xxxx-xxxx-xxxxxxxxxxxx -o ~/Desktop/result.mp4 --timeout 600
```
| Option | Description | Default |
@@ -175,30 +204,21 @@ lh gen download gen_xxx task_xxx -o ~/Desktop/result.mp4 --timeout 600
1. Polls `generation.getGenerationStatus` at the specified interval
2. Shows live progress: `⋯ Status: processing... (42s)`
3. On success: downloads asset URL to local file
4. On error: displays error message and exits
4. On error / wrong ID: displays a clear message pointing to the correct ID format
5. On timeout: suggests using `lh gen status` to check later
**Typical workflow**:
```bash
# One-shot: generate and download
lh gen image "A sunset"
# Copy the generation ID and task ID from output
lh gen download gen_xxx taskId_xxx -o sunset.png
# Video (longer timeout)
lh gen video "A cat running" -m model -p provider
lh gen download gen_xxx taskId_xxx -o cat.mp4 --timeout 600
```
---
## `lh generate status <generationId> <taskId>`
## `lh generate status <generationId> <asyncTaskId>`
Check the status of an async generation task.
> ⚠️ `<asyncTaskId>` is the UUID printed after "→ Task" in the video/image output.
> Do **not** pass the generation ID (`gen_xxx`) here — that will cause a server error.
```bash
lh gen status <generationId> <taskId> [--json]
lh gen status <generationId> <asyncTaskId> [--json]
lh gen status gen_xxx 7ad0eb13-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```
| Option | Description |
@@ -235,12 +255,17 @@ Image and video generation use an async task pattern:
- Triggers async background task (image via `createAsyncCaller`, video via `initModelRuntimeFromDB`)
- Returns `{ data: { batch, generations }, success }` with `asyncTaskId` in each generation
3. **Poll status**`generation.getGenerationStatus`
- Input: `{ generationId, asyncTaskId }` — both are required, and `asyncTaskId` must be the
UUID from the `async_tasks` table, not `gen_xxx`
- Returns `{ status, error, generation }` (generation includes asset URLs on success)
- Before querying, calls `checkTimeoutTasks` which marks tasks as `error` if they have been
`pending` or `processing` for more than ~5 minutes (`ASYNC_TASK_TIMEOUT = 298s`)
**Server routes**:
- `src/server/routers/lambda/image/index.ts` — image creation (uses `authedProcedure` + `serverDatabase`)
- `src/server/routers/lambda/video/index.ts` — video creation (uses `authedProcedure` + `serverDatabase`)
- `src/server/routers/lambda/generation.ts` — status checking
- `packages/database/src/models/asyncTask.ts``AsyncTaskModel` including `checkTimeoutTasks`
**Note**: Image/video routes do NOT use the `keyVaults` middleware — they read API keys from the database via `initModelRuntimeFromDB` or `createAsyncCaller`.
+89 -13
View File
@@ -9,6 +9,61 @@ import { registerTextCommand } from './text';
import { registerTtsCommand } from './tts';
import { registerVideoCommand } from './video';
/**
* Parse a tRPC/server error and return a user-friendly message for gen status/download.
*
* getGenerationStatus throws NOT_FOUND in two distinct cases:
* 1. "Async task not found" → asyncTaskId is wrong (user passed gen_xxx instead of UUID)
* 2. "Generation not found" → generationId is wrong
*
* INTERNAL_SERVER_ERROR with a message mentioning "async_tasks" also indicates a bad asyncTaskId
* (e.g. the server SQL query fails when a non-UUID is passed).
*/
function parseGenStatusError(
err: any,
generationId: string,
asyncTaskId: string,
command: 'status' | 'download',
): string | null {
const code = err?.data?.code || err?.shape?.data?.code;
const message: string = err?.message || err?.shape?.message || '';
const isAsyncTaskNotFound =
(code === 'NOT_FOUND' && message.includes('Async task not found')) ||
(code === 'INTERNAL_SERVER_ERROR' && message.includes('async_tasks'));
const isGenerationNotFound = code === 'NOT_FOUND' && message.includes('Generation not found');
if (isAsyncTaskNotFound) {
return (
`${pc.red('✗')} Async task not found: ${pc.bold(asyncTaskId)}\n` +
`\n` +
` The second argument must be the ${pc.bold('asyncTaskId')} — the UUID printed after\n` +
` "→ Task" in the video/image output, not the generation ID (gen_xxx).\n` +
`\n` +
` Example output from "lh gen video":\n` +
` Generation ${pc.bold('gen_abc123')} → Task ${pc.dim('7ad0eb13-e9a5-4403-8070-1f7fe95b2f95')}\n` +
`\n` +
` Correct usage:\n` +
` ${pc.cyan(`lh gen ${command} gen_abc123 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95`)}`
);
}
if (isGenerationNotFound) {
return (
`${pc.red('✗')} Generation not found: ${pc.bold(generationId)}\n` +
`\n` +
` The first argument must be the ${pc.bold('generationId')} (gen_xxx) from the\n` +
` video/image output.\n` +
`\n` +
` Correct usage:\n` +
` ${pc.cyan(`lh gen ${command} <generationId> <asyncTaskId>`)}`
);
}
return null;
}
export function registerGenerateCommand(program: Command) {
const generate = program
.command('generate')
@@ -23,15 +78,26 @@ export function registerGenerateCommand(program: Command) {
// ── status ──────────────────────────────────────────
generate
.command('status <generationId> <taskId>')
.command('status <generationId> <asyncTaskId>')
.description('Check generation task status')
.option('--json', 'Output raw JSON')
.action(async (generationId: string, taskId: string, options: { json?: boolean }) => {
.action(async (generationId: string, asyncTaskId: string, options: { json?: boolean }) => {
const client = await getTrpcClient();
const result = await client.generation.getGenerationStatus.query({
asyncTaskId: taskId,
generationId,
});
let result: any;
try {
result = await client.generation.getGenerationStatus.query({
asyncTaskId,
generationId,
});
} catch (err: any) {
const msg = parseGenStatusError(err, generationId, asyncTaskId, 'status');
if (msg) {
console.error(msg);
process.exit(1);
}
throw err;
}
if (options.json) {
console.log(JSON.stringify(result, null, 2));
@@ -53,7 +119,7 @@ export function registerGenerateCommand(program: Command) {
// ── download ──────────────────────────────────────────
generate
.command('download <generationId> <taskId>')
.command('download <generationId> <asyncTaskId>')
.description('Wait for generation to complete and download the result')
.option('-o, --output <path>', 'Output file path (default: auto-detect from asset)')
.option('--interval <sec>', 'Polling interval in seconds', '5')
@@ -61,7 +127,7 @@ export function registerGenerateCommand(program: Command) {
.action(
async (
generationId: string,
taskId: string,
asyncTaskId: string,
options: { interval?: string; output?: string; timeout?: string },
) => {
const client = await getTrpcClient();
@@ -73,10 +139,20 @@ export function registerGenerateCommand(program: Command) {
// Poll for completion
while (true) {
const result = (await client.generation.getGenerationStatus.query({
asyncTaskId: taskId,
generationId,
})) as any;
let result: any;
try {
result = await client.generation.getGenerationStatus.query({
asyncTaskId,
generationId,
});
} catch (err: any) {
const msg = parseGenStatusError(err, generationId, asyncTaskId, 'download');
if (msg) {
console.error(`\n${msg}`);
process.exit(1);
}
throw err;
}
if (result.status === 'success' && result.generation) {
const gen = result.generation;
@@ -125,7 +201,7 @@ export function registerGenerateCommand(program: Command) {
console.log(
`${pc.red('✗')} Timed out after ${options.timeout}s. Task still ${result.status}.`,
);
console.log(pc.dim(`Run "lh gen status ${generationId} ${taskId}" to check later.`));
console.log(pc.dim(`Run "lh gen status ${generationId} ${asyncTaskId}" to check later.`));
process.exit(1);
}
@@ -6,11 +6,11 @@ Generate text, images, videos, and audio. Alias: \`lh generate\`.
- \`lh gen text <prompt> [-m <model>] [-p <provider>] [--stream] [--temperature <t>]\` - Generate text
- \`lh gen image <prompt> [-m <model>] [-n <count>] [--width <w>] [--height <h>]\` - Generate image
- \`lh gen video <prompt> [-m <model>] [--aspect-ratio <r>] [--duration <d>]\` - Generate video
- \`lh gen video <prompt> -m <model> -p <provider> [--aspect-ratio <r>] [--duration <d>] [--resolution <res>]\` - Generate video
- \`lh gen tts <text> [-o <output>] [--voice <v>] [--speed <s>]\` - Text-to-speech
- \`lh gen asr <audioFile> [--model <m>] [--language <l>]\` - Speech-to-text
- \`lh gen status <generationId> <taskId>\` - Check generation task status
- \`lh gen download <generationId> <taskId> [-o <output>]\` - Wait and download result
- \`lh gen status <generationId> <asyncTaskId>\` - Check generation task status
- \`lh gen download <generationId> <asyncTaskId> [-o <output>]\` - Wait and download result
- \`lh gen list\` - List generation topics
## Tips
@@ -18,6 +18,30 @@ Generate text, images, videos, and audio. Alias: \`lh generate\`.
- Image/video generation is async; use \`status\` or \`download\` to get results
- \`--stream\` for text generation outputs tokens as they arrive
- \`--pipe\` for text generation outputs only the raw text (no formatting)
## ⚠️ asyncTaskId vs generationId
\`gen status\` and \`gen download\` require TWO different IDs:
- \`<generationId>\` — prefixed with \`gen_\`, e.g. \`gen_abc123\`
- \`<asyncTaskId>\` — a UUID printed after \`→ Task\` in the \`gen image\` / \`gen video\` output,
e.g. \`7ad0eb13-e9a5-4403-8070-1f7fe95b2f95\`
Passing \`gen_xxx\` as \`<asyncTaskId>\` will cause a server error. Always use the UUID.
Example output from \`lh gen video\`:
\`\`\`
✓ Video generation started
Batch ID: gb_xxx
Generation gen_abc123 → Task 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ← this is asyncTaskId
\`\`\`
Correct usage:
\`\`\`bash
lh gen status gen_abc123 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95
lh gen download gen_abc123 7ad0eb13-e9a5-4403-8070-1f7fe95b2f95 -o result.mp4
\`\`\`
`;
export default content;