Skip to content

feat: Implement Task Timeouts in same.yaml #63

@drlucaa

Description

@drlucaa

Currently, tasks in same run indefinitely until completion or until the entire build is cancelled. We need to add support for a timeout field in the same.yaml task definition. This will allow users to specify a maximum duration for a task (e.g., 5m, 30s). If a task exceeds this limit, the system must terminate the process and report the task as failed.

Goals

  • Prevent Hanging Tasks: Allow users to safeguard their builds against processes that may get stuck or hang indefinitely.
  • Configuration: Provide a simple, human-readable configuration option in same.yaml.
  • Enforcement: Ensure the scheduler strictly enforces these limits during execution.

Acceptance Criteria

1. Configuration & Domain

  • Update the Samefile schema (internal/adapters/config/schema.go) to accept a timeout field (string).
  • Update the domain.Task struct (internal/core/domain/task.go) to include a Timeout field of type time.Duration.
  • Update the config loader to parse the timeout string using time.ParseDuration and populate the domain model.
  • Invalid formats (e.g., "forever") should result in a config validation error.

2. Execution Logic

  • Modify the Scheduler (internal/engine/scheduler/scheduler.go) to apply the timeout.
  • In executeTask, if a task has a Timeout > 0, wrap the execution context using context.WithTimeout.
  • Ensure that when the context deadline is exceeded, the underlying executor kills the process immediately.
  • The error returned must clearly indicate a timeout occurred (e.g., wrap context.DeadlineExceeded).

3. Documentation

  • Update docs/configuration/same-yaml.mdx to include the timeout field in the Task Definition section with examples.

4. Verification

  • Add a unit test verifying that timeout: "10s" is correctly parsed into a duration.
  • Add an integration test where a task with a short timeout (e.g., 100ms) runs a slow command (e.g., sleep 10) and asserts that it fails with a timeout error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions