Skip to content

Add script kill/abort mechanism — running scripts cannot be stopped #27

@Aryan1092raj

Description

@Aryan1092raj

@siddu-k

Summary

Once a script starts executing via /api/scripts/run, there is no way
to stop it from the UI or API. The only option is to kill the entire
DevShell process. This is a critical gap for long-running or hung scripts.

Current Behavior

  • /api/scripts/run spawns a subprocess and streams output via SSE
  • No process registry exists to track active run IDs
  • No /api/scripts/kill endpoint exists
  • proc.wait(timeout=10) in run_script() will silently throw
    subprocess.TimeoutExpired for any script that produces no output
    for 10+ seconds, crashing the stream unexpectedly

Expected Behavior

  • Each script execution gets a unique run_id (already generated but unused for kill)
  • A POST /api/scripts/kill endpoint accepts { "run_id": "..." } and
    terminates the process gracefully (proc.terminate()proc.kill() fallback)
  • Active terminal tabs in the UI show an Abort button while a script is running
  • SSE stream sends a final { "type": "aborted" } event on kill

Proposed Fix

Backend (app.py):

# Global registry for active processes
active_processes = {}

# In run_script(), register the process:
active_processes[run_id] = proc

# New endpoint:
@app.route('/api/scripts/kill', methods=['POST'])
def kill_script():
    data = request.json
    run_id = data.get('run_id', '')
    proc = active_processes.get(run_id)
    if not proc:
        return jsonify({'error': 'Process not found'}), 404
    proc.terminate()
    try:
        proc.wait(timeout=3)
    except subprocess.TimeoutExpired:
        proc.kill()
    active_processes.pop(run_id, None)
    return jsonify({'success': True, 'run_id': run_id})


I noticed this issue 
Could u please assign this to me, i would like to work upon this

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions