Skip to content

Make native select differential deterministic#21

Merged
loreste merged 1 commit into
mainfrom
agent/memory-safety-runtime-install
Jul 23, 2026
Merged

Make native select differential deterministic#21
loreste merged 1 commit into
mainfrom
agent/memory-safety-runtime-install

Conversation

@loreste

@loreste loreste commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • ensure only channel b can be ready for the first select
  • delay channel a so it deterministically feeds the second select
  • remove scheduler-order flakiness from the C/native differential gate

Validation

  • ./scripts/native-compiler-test.sh
  • prior merged CI run: ASan, UBSan, TSan, GCC, LLVM, cross-compile, product claims, benchmark gates, and macOS/Linux platform jobs passed

Summary by CodeRabbit

  • Documentation
    • Updated the select-syntax example timing to make channel readiness and timeout behavior clearer.
    • Increased selection timeout values for more reliable example execution.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The select syntax example updates sender delays and increases both timeout values so the first selection targets channel b readiness.

Changes

Select syntax example

Layer / File(s) Summary
Channel timing and timeout adjustments
examples/select_syntax.mko
Sender kickoff delays are revised so channel b is ready for the first selection, and both select timeouts change from 500 to 2000.
Estimated code review effort: 1 (Trivial) ~2 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: making the native select differential test deterministic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/memory-safety-runtime-install

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.

@loreste
loreste marked this pull request as ready for review July 23, 2026 18:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/select_syntax.mko`:
- Around line 13-17: Update the setup around chan_selectn in the first select
test so b’s sender is confirmed to have started or become ready before kicking
the delayed sender for a. Replace the fixed-delay-only ordering with an explicit
synchronization mechanism, while preserving the existing intent that only b is
selectable initially and retaining the current select timeout and values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a2ffe787-54e6-4a30-8414-2b2fd8cb648d

📥 Commits

Reviewing files that changed from the base of the PR and between cf5e37e and 3e20dda.

📒 Files selected for processing (1)
  • examples/select_syntax.mko

Comment on lines +13 to +17
// Keep only b ready for the first select. A large gap prevents a busy
// CI runner from making both buffered channels ready before selection.
let _ = t.kick(sender(a, 11, 500))
let _ = t.kick(sender(b, 22, 0))
select timeout 2000 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the ordering guarantees of crew kickoff and channel readiness.
rg -n -C5 '\bt\.kick\s*\(|fn\s+kick\b|sleep_ms\b|chan_select' .

Repository: loreste/mako

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate crew definitions =="
rg -n -C8 '\bkick\b|struct .*Crew|type .*Crew|impl .*Crew|fn new_crew|Crew::|t\.kick' src runtime examples/testing examples/select_syntax.mko --glob '!runtime/native_bridge.c' | head -n 240

echo
echo "== select_syntax.mko and chan_select implementation references =="
cat -n examples/select_syntax.mko
rg -n -C7 'select|chan_select' runtime src --glob '!runtime/native_bridge.c' | head -n 220

Repository: loreste/mako

Length of output: 29009


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== focused crew/channel/select runtime symbols =="
rg -n -C6 'struct mako_crew|type mako_crew|crew_\w*|Crew|kick\(|chan_new|chan_send|chan_select|mako_chan_select|mako_native_chan_select|selectn|selectn' runtime src -g '*.c' -g '*.h' -g '*.rs' | head -n 300

echo
echo "== relevant exact files if any =="
git ls-files | rg '(^|/)(?i)(crew|select|channel|thread|task).*\.(c|h)$|(^|/)(mako_rt|mako_vm|mako_sched).*\.(c|h)$|src/.*select.*|src/.*crew.*'

Repository: loreste/mako

Length of output: 16622


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== runtime/mako_rt.h relevant ranges =="
sed -n '5030,5115p' runtime/mako_rt.h
sed -n '5115,5150p' runtime/mako_rt.h
sed -n '5440,5515p' runtime/mako_rt.h
sed -n '5590,5660p' runtime/mako_rt.h

echo
echo "== crew kickoff and scheduling references =="
rg -n -C8 'kick|Crew|crib|Task|task|spawn|thread|pthread|schedule|runnable|ready|selectn\(|chan_selectn\(' runtime/mako_rt.h runtime -g '*.c' -g '*.h' --glob 'runtime/mako_rt.h'

Repository: loreste/mako

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== exact ranges requested =="
sed -n '5030,5115p' runtime/mako_rt.h
sed -n '5115,5150p' runtime/mako_rt.h

echo
echo "== select-n implementation candidates =="
rg -n -C10 'mako_chan_selectn|static inline .*select.*' runtime/mako_rt.h

echo
echo "== crew/task implementation candidates =="
rg -n -C10 'struct .*Task|struct .*Crew|typedef .*Task|typedef .*Crew|kick\(|Kick\(|pthread_create|pthread_mutex|pthread_cond|runnable|ready|spawn|join' runtime/mako_rt.h --glob 'runtime/mako_rt.h'

Repository: loreste/mako

Length of output: 50368


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== crew/task implementation tail =="
wc -l runtime/mako_rt.h
sed -n '5646,5950p' runtime/mako_rt.h

echo
echo "== select syntax lowering =="
rg -n -C8 'Select|stmts|ChanSelect|select_syntax|mako_chan_select' src --glob '*.rs'

Repository: loreste/mako

Length of output: 50369


Wait for b’s send to start before delaying a.

chan_selectn starts scanning from the current round-robin index, so if both buffered channels become ready before the first select, either arm can be chosen. A fixed delay does not guarantee a is still unavailable, so the test remains scheduler-dependent; establish readiness ordering between kicking/beginning the delayed sender and the first select.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/select_syntax.mko` around lines 13 - 17, Update the setup around
chan_selectn in the first select test so b’s sender is confirmed to have started
or become ready before kicking the delayed sender for a. Replace the
fixed-delay-only ordering with an explicit synchronization mechanism, while
preserving the existing intent that only b is selectable initially and retaining
the current select timeout and values.

@loreste
loreste merged commit 75c4ad0 into main Jul 23, 2026
14 checks passed
@loreste
loreste deleted the agent/memory-safety-runtime-install branch July 23, 2026 19:12
loreste added a commit that referenced this pull request Jul 25, 2026
Make native select differential deterministic
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