Download an execution debug ZIP
When an Ask or webhook run misbehaves, pull the same debug bundle operators get
from Activity / watch: DAG, subscribe replay, and optional judge. Pass the
execution trace_id (from Ask start, subscribe complete, or the session’s
execution list).
| Step | What the SDK does |
|---|---|
| 1. Resolve | You already have trace_id, or call list_executions(session_id=…) |
| 2. Export | POST /guild/api/v1/executions/{traceId}/debug-export |
| 3. Save | Write application/zip bytes to a local path |
Minimal
from stackgen import StackgenClient, StackgenConfig
client = StackgenClient(
StackgenConfig(
base_url="https://app.stackgen.com",
api_token="stackgen_…",
workspace_id="<workspace-uuid>",
)
)
path = client.aiden.download_execution_debug_zip(
"<trace-id>",
"execution-debug.zip",
# Optional: abort a hung cold export (seconds).
# timeout_seconds=180,
)
print(path, path.stat().st_size)import { StackgenClient, StackgenConfig } from "stackgen-sdk";
import { statSync } from "node:fs";
const client = new StackgenClient(
new StackgenConfig({
baseUrl: "https://app.stackgen.com",
apiToken: "stackgen_…",
workspaceId: "<workspace-uuid>",
}),
);
const path = await client.aiden.downloadExecutionDebugZip(
"<trace-id>",
"execution-debug.zip",
// Optional: abort a hung cold export (milliseconds).
// { timeoutMs: 180_000 },
);
console.log(path, statSync(path).size);path, err := client.Aiden.DownloadExecutionDebugZip(ctx, "<trace-id>", "execution-debug.zip")
if err != nil { return err }
info, err := os.Stat(path)
if err != nil { return err }
fmt.Println(path, info.Size())
return nilRunnable CLI
- Python:
examples/ask/download-debug-zip.py - TypeScript:
examples/ask/download-debug-zip.ts - Go:
examples/go/ask/download-debug-zip.go
#!/usr/bin/env python3
"""Download an execution debug ZIP (Activity / watch export) by trace id."""
from __future__ import annotations
import argparse
import os
import sys
from stackgen import StackgenClient, StackgenConfig
def main() -> int:
parser = argparse.ArgumentParser(
description="POST …/executions/{traceId}/debug-export and write the ZIP.",
)
parser.add_argument("--base-url", default=os.environ.get("STACKGEN_URL", ""))
parser.add_argument("--api-token", default=os.environ.get("STACKGEN_TOKEN", ""))
parser.add_argument(
"--workspace-id",
"--org-id",
default=os.environ.get("STACKGEN_WORKSPACE_ID") or os.environ.get("STACKGEN_PROJECT") or os.environ.get("STACKGEN_ORG_ID", ""),
)
parser.add_argument(
"--trace-id",
required=True,
help="Execution trace id (from Ask start / subscribe / Activity)",
)
parser.add_argument(
"--output-path",
default="",
help="Local ZIP path (default: execution-<trace>-debug.zip)",
)
args = parser.parse_args()
if not args.base_url or not args.api_token or not args.workspace_id:
parser.error("set STACKGEN_URL / STACKGEN_TOKEN / STACKGEN_WORKSPACE_ID (or flags)")
out = (args.output_path or "").strip() or f"execution-{args.trace_id[:16]}-debug.zip"
client = StackgenClient(
StackgenConfig(
base_url=args.base_url,
api_token=args.api_token,
workspace_id=args.workspace_id,
)
)
path = client.aiden.download_execution_debug_zip(args.trace_id, out)
print(f"trace_id={args.trace_id} output={path} bytes={path.stat().st_size}")
return 0
if __name__ == "__main__":
raise SystemExit(main())/**
* Download an execution debug ZIP (Activity / watch export) by trace id.
*
* Usage:
* npx tsx examples/ask/download-debug-zip.ts \
* --trace-id <trace> --output-path ./debug.zip
*/
import { statSync } from "node:fs";
import { parseArgs } from "node:util";
import { StackgenClient, StackgenConfig } from "stackgen-sdk";
async function main(): Promise<void> {
const { values } = parseArgs({
options: {
"base-url": { type: "string", default: process.env.STACKGEN_URL || "" },
"api-token": { type: "string", default: process.env.STACKGEN_TOKEN || "" },
"org-id": { type: "string" },
"workspace-id": {
type: "string",
default: process.env.STACKGEN_WORKSPACE_ID || process.env.STACKGEN_PROJECT || process.env.STACKGEN_ORG_ID || "",
},
"trace-id": { type: "string" },
"output-path": { type: "string", default: "" },
},
});
if (!values["trace-id"] || !values["base-url"] || !values["api-token"] || !(values["org-id"] || values["workspace-id"])) {
throw new Error("require --trace-id and STACKGEN_URL / STACKGEN_TOKEN / STACKGEN_WORKSPACE_ID");
}
const tid = values["trace-id"];
const out =
(values["output-path"] || "").trim() || `execution-${tid.slice(0, 16)}-debug.zip`;
const client = new StackgenClient(
new StackgenConfig({
baseUrl: values["base-url"],
apiToken: values["api-token"],
workspaceId: (values["org-id"] || values["workspace-id"]),
}),
);
const path = await client.aiden.downloadExecutionDebugZip(tid, out);
const bytes = statSync(path).size;
console.log(`trace_id=${tid} output=${path} bytes=${bytes}`);
}
main().catch((err) => {
console.error(err instanceof Error ? err.message : err);
process.exit(1);
});// Download an execution debug ZIP by trace id.
//
// Documented at https://appcd-dev.github.io/stackgen-sdk/code-samples/ask-debug-zip/
//
// go run ./examples/go/ask/download-debug-zip.go --trace-id <trace-id>
package main
import (
"context"
"flag"
"fmt"
"os"
"strings"
stackgen "github.com/appcd-dev/stackgen-sdk/clients/go"
)
func envOr(keys ...string) string {
for _, key := range keys {
if v := strings.TrimSpace(os.Getenv(key)); v != "" {
return v
}
}
return ""
}
func main() {
baseURL := flag.String("base-url", envOr("STACKGEN_URL"), "Mothership URL")
apiToken := flag.String("api-token", envOr("STACKGEN_TOKEN"), "API token")
orgID := flag.String("workspace-id", envOr("STACKGEN_WORKSPACE_ID", "STACKGEN_PROJECT", "STACKGEN_ORG_ID"), "Workspace UUID (sent as orgId)")
flag.StringVar(orgID, "org-id", *orgID, "Deprecated: use -workspace-id")
traceID := flag.String("trace-id", "", "Execution trace id")
outputPath := flag.String("output-path", "", "Local ZIP path")
flag.Parse()
if *baseURL == "" || *apiToken == "" || *orgID == "" {
fmt.Fprintln(os.Stderr, "set STACKGEN_URL / STACKGEN_TOKEN / STACKGEN_WORKSPACE_ID (or flags)")
os.Exit(2)
}
if strings.TrimSpace(*traceID) == "" {
fmt.Fprintln(os.Stderr, "--trace-id is required")
os.Exit(2)
}
out := strings.TrimSpace(*outputPath)
if out == "" {
prefix := *traceID
if len(prefix) > 16 {
prefix = prefix[:16]
}
out = "execution-" + prefix + "-debug.zip"
}
client, err := stackgen.NewClient(stackgen.Config{BaseURL: *baseURL, APIToken: *apiToken, WorkspaceID: *orgID})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
path, err := client.Aiden.DownloadExecutionDebugZip(context.Background(), *traceID, out)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
info, err := os.Stat(path)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("trace_id=%s output=%s bytes=%d\n", *traceID, path, info.Size())
}Related: Ask → artifact
for the customer-facing session report.
Live PR CI also downloads debug ZIPs for every sample that produced a session
or trace and uploads them as the live-debug-zips workflow artifact.