Skip to content

[Phase 4] Workspace Hooks: Execution Engine with Timeout and Error Handling #394

Description

@frankbria

Summary

Implement the hook execution engine that runs shell scripts with timeout enforcement, error handling, and structured logging.

Parent issue: #392

Scope

New module: core/hooks.py

  1. async def run_hook(script: str, cwd: Path, timeout_ms: int, context: dict) -> HookResult

    • Execute shell script via subprocess with cwd set to workspace path
    • Enforce timeout (kill process on expiry)
    • Capture stdout/stderr (truncated to reasonable limit, ~10KB)
    • Return structured HookResult(success, exit_code, stdout, stderr, duration_ms)
  2. Error handling:

    • Timeout → HookResult(success=False, error="timeout")
    • Non-zero exit → HookResult(success=False, exit_code=N)
    • Exception → HookResult(success=False, error=str(e))
  3. Logging:

    • Log hook start with name and script preview
    • Log hook completion with duration
    • Log hook failures with stderr excerpt

Acceptance Criteria

  • Hook scripts execute with correct cwd
  • Timeout kills the subprocess after timeout_ms
  • stdout/stderr captured and truncated
  • Structured HookResult returned for all outcomes
  • Integration test: successful hook, failing hook, timeout hook

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase-4.3Phase 4.3: Workspace Lifecycle Hooks Systemsymphony-inspiredInspired by OpenAI Symphony spec analysis

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions