# RFC 0002: Structured Concurrency Status: Proposed Target: Aji 0.1 ## Summary Aji makes structured task scopes the default concurrency primitive. A child task cannot silently outlive the scope that created it. ## Motivation Unstructured task spawning complicates: - lifetime reasoning; - cancellation; - resource cleanup; - borrowed data; - error propagation; - deterministic replay. A language designed for machine verification should make the lifetime tree explicit. ## Rule Every normal task belongs to a task scope. ```aji task.scope s { let a = task.spawn(s, worker_a, move input_a)?; let b = task.spawn(s, worker_b, move input_b)?; let ra = task.join(move a)?; let rb = task.join(move b)?; } ``` Leaving the scope with live children is a verifier error. ## Borrowing Because child lifetime is bounded by the scope, scoped tasks may borrow parent storage when the verifier proves the storage outlives all child uses. This enables zero-copy parallel algorithms. ## Cancellation Cancellation propagates downward through the task tree but is observed only at explicit cancellation points. Aji intentionally rejects arbitrary asynchronous interruption because it can break invariants between instructions. ## Detached tasks Detached tasks require an explicit capability and fully owned `Send` state. Long-lived services should normally be expressed using supervisors rather than detached background work. ## Failure policy The language does not hard-code fail-fast semantics. Libraries may implement supervision policies. ## Determinism Structured task topology gives the deterministic runtime a bounded set of live tasks and parent/child relationships, simplifying replay and schedule exploration.