Skip to content

Proposal: Validate automation definitions before saving #577

Open

Description

Tracked in #568. This proposal stands on its own and doesn't depend on the others tracked there.

Summary

Event-trigger configuration is defined by the host, so only the host can fully validate it. Today the host validates only when a create or update action arrives, and it rejects with a single free-text reason.

This proposal adds a side-effect-free validateAutomation command. It returns the definition as the host would store it, plus field-level problems (errors and warnings), so editors can give inline feedback while the user is still typing.

Scenarios

  • Inline errors for host-defined triggers. A trigger filter names a label that doesn't exist, or a branch pattern the host can't parse. The editor highlights the field before the user saves.
  • Warnings that need host knowledge. "This event includes activity from bots, so this automation could trigger itself." "This repository receives about 400 events a day."
  • Preview. Show the trigger titles and other values the host would fill in, and when the schedule will next fire, before saving.
  • Check before approving. Validate a definition that someone else proposed before accepting it.

AHP today

  • listAutomationTriggerDefinitions returns event-trigger discovery data and a configSchema, so clients can check structure (types, enums, required properties) locally.
  • Clients can preview schedules locally with the portable cron rules.
  • Anything else is validated only when automation/createRequested or automation/updateRequested arrives. A rejection carries one free-text ActionEnvelope.rejectionReason and no field information.

Proposal

  1. Command. validateAutomation on ahp-automations:// takes a complete definition and, when the user is editing an existing automation, its automation URI.
  2. Result.
    • definition: the definition as the host would store it, after the same normalization it applies on create or update.
    • problems: field-level findings. Each has a JSON Pointer path into the definition, a message, and a severity (@nonexhaustive: error or warning). An error means the host would reject the definition. A warning means the host would accept it.
    • nextOccurrences (optional): the next few times each schedule trigger would fire, as the host evaluates it. Clients can already compute previews with the portable rules; the host's answer is authoritative for its own evaluation, for example its time zone data.
  3. No side effects. Validation persists nothing, captures no customizations, and creates no runs. Hosts SHOULD run the same checks they run for create and update, so a definition with no errors is accepted unless something changes in between.
  4. Capability. automations.validate. Clients use the command only when the host advertises it.

Sketch

Names and shapes are illustrative. The implementation PR settles them.

/** validateAutomation, on ahp-automations:// */
interface ValidateAutomationParams extends BaseParams {
  channel: 'ahp-automations://';
  definition: AutomationDefinition;
  /** The existing automation being edited, if any. */
  automation?: URI;
}

interface ValidateAutomationResult {
  /** The definition as the host would store it. */
  definition: AutomationDefinition;
  /** Empty when the host would accept the definition without warnings. */
  problems: AutomationProblem[];
  /** Next few occurrences per schedule trigger, as ISO 8601 timestamps. */
  nextOccurrences?: { triggerId: string; at: string[] }[];
}

interface AutomationProblem {
  /** JSON Pointer into the definition, for example "/triggers/1/config/labels". */
  path: string;
  message: string;
  severity: AutomationProblemSeverity;
}

/** @nonexhaustive */
const enum AutomationProblemSeverity {
  Error = 'error',
  Warning = 'warning',
}

interface AutomationCapabilities {
  // ...existing fields
  validate?: {};
}

Why this shape

  • AHP already resolves prospective state on the host. resolveSessionConfig lets a client send a partial session configuration and get back what the host would do, before anything is created. listAutomationTriggerDefinitions already evaluates a prospective session template. Validating a prospective definition is the same pattern.
  • The authoritative path is unchanged. Create and update actions behave exactly as they do today. Validation is advisory, and the host stays the authority when the action arrives.
  • JSON Pointer paths let any client map a problem to a field without understanding host-specific configuration.

Compatibility

  • Additive and capability-gated. Clients that don't call the command see no change.

Out of scope

  • Changing how create and update rejections are reported.

Open questions

  1. Should rejected create and update actions also carry structured problems? rejectionReason is free text everywhere in the protocol, so that would be a broader change.
  2. Should the command also accept a patch for an existing automation, instead of a complete definition?
  3. Should hosts be able to signal that validation is expensive, so clients debounce more aggressively?

Related proposals (none required)

Metadata

Metadata

Labels

feature-request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions