Skip to content

Task.is_done() returns false after .await (await appears to invalidate the handle) #637

Closed

Description

@ehartford

Summary

t.is_done() is FALSE immediately after t.await completes — reproduced twice (sync stepping and async-main). §14.7 says is_done reports completion, so post-await it should be true (or the handle's post-await state should be specified).

Repro sketch

let t = work()      // async fn
let r = t.await     // completes
assert(t.is_done()) // FAILS — is_done() is false

Stepping the scheduler (is_done false→true via with_runtime_run_one_step) works correctly; only the post-await path disagrees. Likely await consumes/moves the handle, leaving is_done querying an invalidated task.

Spec §14.7

Either is_done should remain true after await, or the spec should state the handle is consumed by await (in which case calling is_done post-await should be a compile error, not a silent false).

Found

Coverage sweep #531, 2026-07-03. Fixtures assert is_done false→true via scheduler stepping, avoiding the await path.

Activity

  1. ehartford commented on Jul 16, 2026

    @ehartford
    ContributorAuthor

    Fixed in 1056ff5, taking the issue's first fork: is_done remains true after await (§14.7's is_done (&Task[T]) -> bool signature is a borrow and promises a completion report; silent false was the one wrong answer).

    Root cause: with_runtime_fiber_is_completed returned 0 whenever the generational slot lookup failed — which is exactly the state after .await, because await reaps the fiber (slot released, generation superseded). The generational SlotMap was correctly refusing a stale handle, but the query layer translated "stale" into "not done".

    Fix: handles are minted only by spawn, and every reap path is terminal-only (verified: result-take gated on DONE, panic-take gated on DONE+has_panic, runtime shutdown). So a well-formed handle that no longer resolves names a finished task — both fiber cores now report completed for that case. Valid-handle behavior is untouched (false after spawn, true after the scheduler completes it — the existing stepping fixtures still pin that). Bonus: cancel() on an already-reaped handle now reports "already completed" instead of issuing a no-op cancel request.

    Residual, noted for the record: was_cancelled() on a reaped handle still returns false — after reaping, the runtime cannot distinguish cancelled-then-joined from completed-normally without a per-slot tombstone. If that combination matters, it needs a small design decision (tombstone bit vs documenting the post-reap contract).

    Pinned by the extended test/spec/spec_ss14_7_task_is_done.w (post-await assertion added alongside the original spawn/step assertions). Windows core changed in lockstep and target-validated (--target x86_64-pc-windows-msvc --no-prelude --validate-all); not executed on a Windows host (that work is milestone post-v0.16.0).

    Gates on 1056ff5: build 0, FIXPOINT, audit:all violations=0, :test all targets ok, test-green/last-green recorded.

  2. added a commit that references this issue on Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions