Skip to content

Add lifecycle hooks for tasks and the overall workflow graph - #116

Draft
alexec with Copilot wants to merge 6 commits into
mainfrom
copilot/discussion-useful-hooks
Draft

Add lifecycle hooks for tasks and the overall workflow graph#116
alexec with Copilot wants to merge 6 commits into
mainfrom
copilot/discussion-useful-hooks

Conversation

CopilotAI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Implements onSuccess and onFailure lifecycle hooks at two scopes: individual tasks and the overall workflow graph.

New types (internal/types/lifecycle.go)

  • Lifecycle — groups onSuccess and onFailure hooks as task name references; nil-safe accessors on both Lifecycle and Task

Per-task hooks (Task.Lifecycle)

Run after a task transitions to succeeded or failed, before any restart logic. The hook values are names of tasks already defined in the workflow file:

tasks:
build:
command: [go, build, .]lifecycle:
onSuccess: notify-slackonFailure: send-alertnotify-slack:
sh: echo build succeeded | notify-slacksend-alert:
command: [./scripts/alert.sh, build failed]

Graph-level hooks (Spec.Lifecycle)

Run when the entire workflow exits. onSuccess fires only on clean internal completion (not on Ctrl+C); onFailure fires when any task fails without restart. Graph hooks run with a signal.NotifyContext context so that a second SIGTERM/SIGINT/SIGHUP while the hook is executing will cancel it cleanly (the hook process receives SIGTERM and is killed after the grace period).

lifecycle:
onSuccess: notify-slackonFailure: send-alerttasks:
notify-slack:
sh: echo all tasks completedsend-alert:
sh: ./scripts/send-alert.sh

All hooks are best-effort — failures are logged but do not affect task or graph outcome. The named hook task is looked up and executed via the same proc.New() mechanism used for all other tasks. JSON schema updated to reflect the new types.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

CopilotAI changed the title [WIP] Discuss potential hooks for projectAdd lifecycle hooks for tasks and the overall workflow graphMar 20, 2026
CopilotAI requested a review from alexecMarch 20, 2026 21:36
Comment threadinternal/types/lifecycle.go Outdated
CopilotAI requested a review from alexecJune 21, 2026 16:46
@alexec

Copy link
Copy Markdown
Collaborator

@copilot fix conflicts. Make sure hooks cancel
With SIGTERM etc

CopilotAI commented Jun 21, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot fix conflicts. Make sure hooks cancel
With SIGTERM etc

Conflicts resolved and hook cancellation fixed.

  • Merge conflicts: restored the setTerminalTitle/ringTerminalBell calls added to main, alongside our lifecycle hook calls
  • Signal cancellation: graph-level hooks (which run after the main context is already cancelled) now use signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) — so if a second SIGTERM/Ctrl-C arrives while the hook is running, the hook process receives SIGTERM (via host.go's context-done handler) and is given the grace period before being killed. Per-task hooks already used the live ctx so they were fine.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@alexec