Skip to content

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

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

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

Conversation

Copilot AI 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-slack
      onFailure: send-alert
  notify-slack:
    sh: echo build succeeded | notify-slack
  send-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-slack
  onFailure: send-alert
tasks:
  notify-slack:
    sh: echo all tasks completed
  send-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.

Copilot AI and others added 2 commits March 20, 2026 21:30
Copilot AI changed the title [WIP] Discuss potential hooks for project Add lifecycle hooks for tasks and the overall workflow graph Mar 20, 2026
Copilot AI requested a review from alexec March 20, 2026 21:36
Comment thread internal/types/lifecycle.go Outdated
Copilot AI requested a review from alexec June 21, 2026 16:46
@alexec

alexec commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

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

Copilot AI commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

@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 free to 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