Always fire callback via trap, even on script failure
Uses ERR/EXIT trap to ensure the orchestrator is notified when the startup script fails (e.g. clone error, missing command file). Prevents orphaned workspaces that never get cleaned up. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
e801d96410
commit
d220623a9f
@@ -428,6 +428,17 @@ resource "coder_agent" "main" {
|
||||
|
||||
startup_script = <<-EOT
|
||||
#!/bin/bash
|
||||
|
||||
# Always notify the orchestrator when done, even on failure
|
||||
notify_complete() {
|
||||
if [ -n "$CALLBACK_URL" ]; then
|
||||
curl -s -X POST -H "Content-Type: application/json" \
|
||||
-d "{\"status\":\"$1\"}" \
|
||||
"$CALLBACK_URL" || echo "Callback failed (non-fatal)"
|
||||
fi
|
||||
}
|
||||
trap 'notify_complete "failed"' ERR EXIT
|
||||
|
||||
set -e
|
||||
|
||||
# --- Configure git ---
|
||||
@@ -483,25 +494,18 @@ resource "coder_agent" "main" {
|
||||
# Read the slash command .md file, strip YAML frontmatter, substitute $ARGUMENTS
|
||||
CMD_FILE=".claude/commands/$TASK_TYPE.md"
|
||||
if [ ! -f "$CMD_FILE" ]; then
|
||||
echo "ERROR: Command file not found: $CMD_FILE" | tee ~/task-output.log
|
||||
echo "ERROR: Command file not found: $CMD_FILE"
|
||||
exit 1
|
||||
fi
|
||||
PROMPT=$(sed '1{/^---$/!q}; 1,/^---$/d' "$CMD_FILE" | sed "s/\\\$ARGUMENTS/$ARGS/g")
|
||||
|
||||
# Run Claude Code in non-interactive mode with tool access
|
||||
claude -p --dangerously-skip-permissions --verbose "$PROMPT" 2>&1 | tee ~/task-output.log
|
||||
EXIT_CODE=$?
|
||||
echo "Claude exited with code: $EXIT_CODE" | tee -a ~/task-output.log
|
||||
|
||||
echo "Task completed. Output saved to ~/task-output.log"
|
||||
|
||||
# Notify orchestrator that the task is done
|
||||
if [ -n "$CALLBACK_URL" ]; then
|
||||
curl -s -X POST -H "Content-Type: application/json" \
|
||||
-d '{"status":"complete"}' \
|
||||
"$CALLBACK_URL" || echo "Callback failed (non-fatal)"
|
||||
fi
|
||||
claude -p --dangerously-skip-permissions --verbose "$PROMPT"
|
||||
fi
|
||||
|
||||
# Success — override the trap
|
||||
trap - ERR EXIT
|
||||
notify_complete "complete"
|
||||
EOT
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user