Skip to content

P1: Clean up provisioned runtimes when task startup or streaming fails #8

@vamgan

Description

@vamgan

Problem

RuntimeService.runTask() provisions resources, but cleanup only runs on the success path.

Relevant code:

  • src/runtime.ts:153-227
  • provisioning: src/runtime.ts:157-164
  • cleanup: src/runtime.ts:206-222
  • catch block: src/runtime.ts:223-227

If startTask(), event streaming, artifact persistence, or later store writes throw after provisioning, the catch block marks the task failed but does not call adapter.cleanup().

Impact

Provider resources can be orphaned and billed indefinitely.

Suggested fix

Track resolved.target and provisioned.runtime/session outside the inner success path, then attempt cleanup in catch/finally when provisioning occurred. Persist cleanup status where possible and avoid masking the original task failure with cleanup errors.

Acceptance criteria

  • Cleanup runs if provisioning succeeds and startTask() fails.
  • Cleanup runs if event streaming fails after task start.
  • Tests verify cleanup failures do not hide the original task failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions