Skip to content

Simplify yield logic - #296

Merged
lalinsky merged 7 commits into
mainfrom
simplify-yield
Feb 7, 2026
Merged

lalinsky merged 7 commits into
mainfrom
simplify-yield

Conversation

@lalinsky

@lalinsky lalinsky commented Feb 7, 2026

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@lalinsky has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

The runtime scheduler was refactored to use AnyTask instead of WaitNode across core paths — getNextTask now returns ?*AnyTask, yield/run/cleanup and queue handling updated accordingly. RunMode lost the until_idle variant. A mutex contention stress test was added to src/sync/Mutex.zig.

Changes

Cohort / File(s) Summary
Runtime Scheduling Refactor
src/runtime.zig
Replaces WaitNode-centric scheduling with AnyTask-centric flow: getNextTask now returns ?*AnyTask, yield and run loop logic updated (main-task handling, last_task cleanup), ready/lifo/next queue branches adapted, and RunMode now only has until_ready and until_stopped.
Mutex Concurrency Test
src/sync/Mutex.zig
Adds a new "Mutex contention" stress test that spawns 4 workers on 4 executors performing 100 lock/increment/unlock iterations each; asserts counter consistency and no failures.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

AnyTask steps up where WaitNode stood,
The scheduler shuffles queues for good.
Executors hum, the main loop sings,
A mutex test proves threaded wings.
Small changes, big choreography — code in motion, tidy and hood.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, so there is no content to evaluate against the changeset. Add a description explaining why the yield logic refactoring improves the codebase and its implications for the scheduler.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Simplify yield logic' directly matches the primary changes in the pull request, which involve refactoring the yield function and scheduling logic to use AnyTask-centric flow instead of WaitNode-centric handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch simplify-yield

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/runtime.zig`:
- Around line 413-420: The assert after calling executor.run(.until_ready)
assumes the main task became ready; instead check whether the loop stopped
first: after executor.run(.until_ready) returns, inspect executor.loop.stopped()
(or self.loop.stopped()) and if true call `@panic` with a clear message like
"event loop stopped while main task was yielding"; otherwise keep the existing
std.debug.assert(task.state.load(.acquire) == .ready). Update the block handling
the main task (referencing executor.run(.until_ready), executor.main_task, and
task.state) to include this guard so the diagnostic is explicit when the loop
was externally stopped.
🧹 Nitpick comments (1)
src/runtime.zig (1)

388-411: Inconsistent use of self vs executor at line 406.

Line 397 uses executor.current_task, line 406 uses self.current_task. At this point they're identical since executor = self hasn't been reassigned yet, so no bug — just a readability hiccup for anyone tracing the flow later.

Suggested fix
-                self.current_task = task;
+                executor.current_task = task;

Comment thread src/runtime.zig Resolved
@lalinsky
lalinsky merged commit b08f1fa into main Feb 7, 2026
5 checks passed
@lalinsky
lalinsky deleted the simplify-yield branch February 7, 2026 13:21
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.

1 participant