Skip to content

feat(schedules): preRun / postRun lifecycle hooks #558

Open

Description

@vybe

Summary

Add pre_run_config and post_run_config hook arrays to agent schedules, allowing arbitrary setup and teardown steps to run before and after each scheduled task execution.

Inspired by Sympozium's lifecycle hook design, which uses init containers for preRun and follow-up Jobs for postRun. Trinity's equivalent will use lightweight HTTP callbacks or agent-internal script invocations.

Context

Schedules currently fire a single chat message at the agent and record the result. Many automation patterns require work before or after that message:

  • preRun examples: fetch fresh context from an API, clone a repo, warm a cache, inject dynamic parameters into the message prompt
  • postRun examples: send a Slack notification with the result, upload artifacts, trigger a downstream webhook, clean up temp files

Without hooks, users must bake all setup/teardown logic into the agent's CLAUDE.md or the schedule message itself — polluting the agent's core instructions and making schedules fragile.

Sympozium's design also supports a response gate variant of postRun (a hook with gate: true) that blocks the agent's output from reaching users until an operator approves, rejects, or rewrites it. That gate feature will be tracked separately in a companion issue.

Acceptance Criteria

  • agent_schedules table gains pre_run_config and post_run_config JSON columns (nullable, versioned migration)
  • pre_run_config schema: { type: "webhook" | "script", url?: string, command?: string, timeout_seconds?: int, env?: Record<string,string> }
  • post_run_config schema: same as above, plus { inject_result: bool } to pass AGENT_RESULT to the hook
  • task_execution_service.py executes pre_run hook before sending the chat message; on hook failure the execution is marked failed with error: "pre_run_hook_failed: ..."
  • task_execution_service.py executes post_run hook after receiving the agent response; hook failure is logged but does not retroactively fail the execution (fire-and-forget)
  • Schedule create/update API (POST/PUT /api/agents/{name}/schedules) accepts and validates hook config
  • UI: Schedule form shows collapsible "Advanced: Lifecycle Hooks" section with webhook URL + timeout inputs
  • Existing schedules without hooks are unaffected (fully backward-compatible)
  • Unit tests cover: pre_run failure stops execution, post_run failure is non-fatal, result injection into post_run env

Technical Notes

  • Schema change: add to db/schema.py AGENT_SCHEDULES table; versioned migration in db/migrations.py
  • Implementation seam: services/task_execution_service.py around the agent_client.chat() call
  • Webhook execution: use httpx.AsyncClient with configurable timeout; pass {"agent_name", "schedule_id", "execution_id", "message"} as JSON body
  • Keep hook execution out of the critical path for slot accounting — release the capacity slot after post_run, not before
  • Related: Sympozium docs/concepts/lifecycle-hooks.md, internal/controller/agentrun_controller.go

Activity

  1. added
    priority-p2
    type-feature
    on Apr 28, 2026
  2. added
    complexity-medium
    theme-infrastructure
    on Jun 3, 2026
  3. added
    status-incubating
    on Jun 14, 2026
  4. added
    complexity-high
    and removed
    complexity-medium
    on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-highpriority-p2status-incubatingtheme-infrastructuretype-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions