Skip to content

fix(plugin-native): join worker thread on run_source timeout/error early returns #523

@staging-devin-ai-integration

Description

Problem

Inside the run_source tick loop, send_to_worker(...).await?, await_reply(...).await?, and apply_params_update(...).await? can return early via ? before the final worker.shutdown().await. These exits use the InstanceWorker::Drop fallback (detach), which is safe but means the deterministic join from #519 only applies to clean exits and plugin-reported errors.

Context

This is intentional for now — joining on a timed-out or wedged FFI call would block spawn_blocking for the full timeout duration. The Arc<InstanceState> keeps the plugin alive until the worker finishes.

However, it may be worth exploring a bounded join with a secondary timeout, so the worker is given a chance to drain before detaching.

Suggested approach

On the ? error paths, take the join handle before returning and attempt a short bounded join (e.g. 100ms via spawn_blocking + tokio::time::timeout). Fall back to detach if the join times out.

Related: #481, #519

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions