Skip to content

feat(tasks): task_self — a task can learn its own id (#526)#529

Merged
InauguralPhysicist merged 1 commit into
mainfrom
task-self-526
Jul 9, 2026
Merged

feat(tasks): task_self — a task can learn its own id (#526)#529
InauguralPhysicist merged 1 commit into
mainfrom
task-self-526

Conversation

@InauguralPhysicist

Copy link
Copy Markdown
Collaborator

Closes #526

What

task_self of null → the running task's id (a number, in the same integer space task_spawn returns; the main task is 0, including before any task has been spawned).

Why

Surfaced by lib/supervise (#409): task_spawn returns the child's id to the parent, but a task had no way to learn its own id — so a worker could not hand out a reply address, and the message-link supervision pattern (a worker delivering its exit as an ordinary message to its supervisor's mailbox) was not expressible.

Design

  • Deterministic by construction: reads pure scheduler state (s->current), no nondeterminism source, so zero tape participation — same contract as task_now.
  • No scheduler yet ⇒ 0 (main), consistent with task_virtual_now's no-scheduler behavior.
  • Extend-vm checklist: plain builtin (no opcode/AST/CallFrame change, no trace wrap needed).

Tests

tests/test_tasks.eigs (+4 asserts, 69/69):

  • main's task_self is 0 with the scheduler active
  • a worker's task_self equals the id its spawner got from task_spawn
  • the reply-address pattern end-to-end: spawner passes task_self down, worker task_sends its own task_self back, spawner task_recvs it

Docs: docs/BUILTINS.md row, docs/SPEC.md Cooperative tasks (reply-address paragraph), CHANGELOG. Discoverability gate (stdlib_index_check.sh) green: 212 builtins documented.

Validation

  • Full suite, release build: 2703/2703 passed
  • Full suite, ASan + detect_leaks=1: 2703/2703 passed, leak tally 0 (unchanged)

Follow-up unblocked

A link-based mode for lib/supervise (worker exit delivered as a message) is now expressible.

🤖 Generated with Claude Code

task_self of null returns the running task's id in the same integer
space task_spawn returns; the main task is 0, including before any
task has been spawned. Deterministic (pure scheduler state, zero tape
records). Unblocks the message-link supervision pattern surfaced by
lib/supervise (#409): a worker can now hand out its own id as a reply
address.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@InauguralPhysicist InauguralPhysicist merged commit 2ca5f5e into main Jul 9, 2026
17 checks passed
@InauguralPhysicist InauguralPhysicist deleted the task-self-526 branch July 9, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task layer: a task cannot learn its own id (no task_self) — blocks message-link supervision

1 participant