feat(tasks): task_self — a task can learn its own id (#526)#529
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #526
What
task_self of null→ the running task's id (a number, in the same integer spacetask_spawnreturns; the main task is 0, including before any task has been spawned).Why
Surfaced by
lib/supervise(#409):task_spawnreturns 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
s->current), no nondeterminism source, so zero tape participation — same contract astask_now.task_virtual_now's no-scheduler behavior.Tests
tests/test_tasks.eigs(+4 asserts, 69/69):task_selfis 0 with the scheduler activetask_selfequals the id its spawner got fromtask_spawntask_selfdown, workertask_sends its owntask_selfback, spawnertask_recvs itDocs:
docs/BUILTINS.mdrow,docs/SPEC.mdCooperative tasks (reply-address paragraph), CHANGELOG. Discoverability gate (stdlib_index_check.sh) green: 212 builtins documented.Validation
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