feat(call): emit explicit final run status and JSON output (#1139)#1198
feat(call): emit explicit final run status and JSON output (#1139)#1198l2ysho wants to merge 11 commits into
Conversation
`apify call` and `apify task run` started a cloud run and streamed logs, but gave no explicit final result — a run could start successfully yet finish FAILED, TIMED_OUT, or ABORTED with no clear signal. Agents and CI could not tell "run started" from "run succeeded". Add a shared `run-result` module that owns the final-status contract: - `getRunExitCode` maps terminal status to a process exit code (SUCCEEDED→0, ABORTED→3, TIMED-OUT→2, FAILED→the Actor's own exit code or 1). - `buildRunResultJson` produces the structured `--json` payload (ok, operation, actor, run.status, run.exitCode, storage, error.logTail, exitCode). - `printRunResultSummary` prints a human-readable final summary, including a Reason block with the last log lines on failure. - `finalizeRun` is the single entry point both commands funnel through. `apify task run` now waits for the run to finish, gains `--json`, and reports a status-derived exit code. Final-status presentation and exit-code handling move out of `runActorOrTaskOnCloud` into the commands. Failed, timed-out, and aborted runs now exit non-zero. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The final-status contract nests the run status under `run.status` and adds `ok`/`operation`/`exitCode`; update the runs lifecycle e2e to match instead of reading the old top-level `status`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…-status-and-json-output-for-agents
| run: { | ||
| id: run.id, | ||
| status: run.status, | ||
| exitCode: run.exitCode ?? null, |
There was a problem hiding this comment.
Q: do we need inner exitCode with the top one in place (exitCode: getRunExitCode(run))?
| datasetUrl: datasetUrl(run.defaultDatasetId), | ||
| }, | ||
| error: ok | ||
| ? null |
There was a problem hiding this comment.
Suggestion: let's use the same format as in case of #1199, meaning, the error should be undefined if ok===true.
| return; | ||
| } | ||
|
|
||
| if (!silent) { |
There was a problem hiding this comment.
Suggestion: the silent should silence the json output as well, right?
Now if both silent and json are set, the json output still prints.
DaveHanns
left a comment
There was a problem hiding this comment.
Pre-approving. The silent vs json should be definitely addressed before merging.
| FLAGS | ||
| -b, --build=<value> Tag or number of the build to run | ||
| (e.g. "latest" or "1.2.34"). | ||
| --json Format the command output as JSON |
There was a problem hiding this comment.
Needs a period at the end :D
There was a problem hiding this comment.
yeah this follows me everywhere :D It is fixed in #1168 so when we merge I will sync it here
…-status-and-json-output-for-agents
…-status-and-json-output-for-agents
…call-and-task-run-final-status-and-json-output-for-agents # Conflicts: # docs/reference.md # src/commands/actors/call.ts # src/commands/task/run.ts # src/lib/commands/run-on-cloud.ts # test/e2e/commands/runs/lifecycle.test.ts
…-status-and-json-output-for-agents
Closes #1139
apify callandapify task runstarted a cloud run and streamed logs, butgave no explicit final result — a run could start successfully yet finish
FAILED, TIMED_OUT, or ABORTED with no clear signal. Agents and CI could not
tell "run started" from "run succeeded".
Add a shared
run-resultmodule that owns the final-status contract:getRunExitCodemaps terminal status to a process exit code (SUCCEEDED→0,ABORTED→3, TIMED-OUT→2, FAILED→the Actor's own exit code or 1).
buildRunResultJsonproduces the structured--jsonpayload (ok, operation,actor, run.status, run.exitCode, storage, error.logTail, exitCode).
printRunResultSummaryprints a human-readable final summary, including aReason block with the last log lines on failure.
finalizeRunis the single entry point both commands funnel through.apify task runnow waits for the run to finish, gains--json, and reports astatus-derived exit code. Final-status presentation and exit-code handling move
out of
runActorOrTaskOnCloudinto the commands. Failed, timed-out, and abortedruns now exit non-zero.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com