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.
Problem
RuntimeService.runTask()provisions resources, but cleanup only runs on the success path.Relevant code:
src/runtime.ts:153-227src/runtime.ts:157-164src/runtime.ts:206-222src/runtime.ts:223-227If
startTask(), event streaming, artifact persistence, or later store writes throw after provisioning, the catch block marks the task failed but does not calladapter.cleanup().Impact
Provider resources can be orphaned and billed indefinitely.
Suggested fix
Track
resolved.targetandprovisioned.runtime/sessionoutside the inner success path, then attempt cleanup incatch/finallywhen provisioning occurred. Persist cleanup status where possible and avoid masking the original task failure with cleanup errors.Acceptance criteria
startTask()fails.