base-action: persist execution log when SDK throws (e.g. max-turns)#1253
Open
STRd6 wants to merge 1 commit intoanthropics:mainfrom
Open
base-action: persist execution log when SDK throws (e.g. max-turns)#1253STRd6 wants to merge 1 commit intoanthropics:mainfrom
STRd6 wants to merge 1 commit intoanthropics:mainfrom
Conversation
When the Agent SDK's query() iterator throws — most notably on max-turns exhaustion — the existing catch block re-throws before reaching the writeFile/setOutput code below, so: - $RUNNER_TEMP/claude-execution-output.json is never written - the execution_file / session_id step outputs are never set - any downstream step gated on steps.claude.outputs.execution_file (e.g. an S3 upload of the transcript) silently skips, and the partial transcript is lost Fix by capturing the SDK error, writing the transcript and setting the outputs unconditionally, then re-throwing so the step still fails. Outputs are now published from within this function because index.ts re-throws on failure before reaching its own setOutput calls. Repro: a job that hits --max-turns 1000 exits with exit code 1, no execution_file output, no log persisted. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
c20646d to
be3b21a
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When the Agent SDK's
query()iterator throws — most commonly on--max-turnsexhaustion — the partial transcript is silently lost.base-action/src/run-claude-sdk.ts:The rethrow bubbles to
index.ts, whosecatchcallscore.setFailedand sets onlyconclusion—execution_fileandsession_idoutputs are never set. So:$RUNNER_TEMP/claude-execution-output.jsonis never writtensteps.<id>.outputs.execution_fileis emptyRepro
A workflow that hits
--max-turns Nfails with:Exit code 1, no
execution_fileoutput, no log persisted — even though 1000 turns' worth of data was in memory moments earlier.Fix
Capture the SDK error, write the transcript, publish the outputs, then re-throw so the step still fails. Outputs are now set from inside the SDK runner because
index.tsre-throws before reaching its ownsetOutputcalls on the failure path.On the success path the behavior is unchanged: the outputs get set in
run-claude-sdk.tsand again inindex.tswith identical values (last-write-wins, no observable difference).Why this matters
Max-turns failures are precisely the runs where the transcript is most valuable — long, expensive runs that the user wants to inspect and recover partial work from. Losing them silently is a bad default.