Repository navigation
Pass timestamp to StackPool.release() instead of getting current time - #177
Conversation
|
Warning Rate limit exceeded@lalinsky has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 0 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR threads monotonic timestamps through StackPool.release, replacing implicit real-time calls with explicit timestamp_ns parameters. FreeNode stores timestamp_ns, and age calculations compute elapsed time from passed timestamps rather than calling now(). Call sites in runtime.zig and runtime/task.zig updated to pass timestamps. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI Agents
In @src/coro/stack_pool.zig:
- Around line 92-93: The timestamp unit is mismatched: change the
StackPool.release parameter from timestamp_ns to timestamp_ms (u64) and update
its docstring to "milliseconds"; then convert the expiration check to compare
like-units by deriving max_age_ms = self.config.max_age_ns / 1_000_000 and using
that in the age comparison (or alternatively multiply timestamp_ms by 1_000_000
if you prefer nanosecond math), and update all call sites (calls passing
loop.now() / rt.now() and any other callers) to pass the millisecond value and
the renamed parameter.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/coro/stack_pool.zigsrc/runtime.zigsrc/runtime/task.zig
🧰 Additional context used
📓 Path-based instructions (1)
**/*.zig
📄 CodeRabbit inference engine (CLAUDE.md)
Use
zig envto get the path to the Zig standard library when checking standard library
Files:
src/runtime/task.zigsrc/runtime.zigsrc/coro/stack_pool.zig
🧠 Learnings (12)
📚 Learning: 2025-11-04T10:29:56.949Z
Learnt from: lalinsky
Repo: lalinsky/zio PR: 118
File: src/core/task.zig:33-115
Timestamp: 2025-11-04T10:29:56.949Z
Learning: In zio's task implementation (src/core/task.zig), the Closure struct intentionally caps result_len and context_len at 4096 bytes (using u12 fields) and alignment at 16 bytes (using u4 padding fields). This is a deliberate design decision to avoid bloating task structures. Users needing larger result or context storage should heap-allocate and pass pointers instead. These limits are more generous than std lib's fixed storage (64 bytes for results, 1024 bytes for args).
<!-- [add_learning]
The task storage limits in zio (4 KiB for result/context, 16-byte alignment) are intentional design constraints to prevent task bloat, not correctness issues. The maintainer's position is that larger data should be heap-allocated.
Applied to files:
src/runtime/task.zig
📚 Learning: 2025-10-03T11:09:46.846Z
Learnt from: lalinsky
Repo: lalinsky/zio PR: 18
File: src/net.zig:18-25
Timestamp: 2025-10-03T11:09:46.846Z
Learning: In zio's `Runtime.BlockingTask`, calling `deinit()` on a blocking task only frees the task wrapper (TaskData) itself, not the result returned by the blocking function. The result remains valid and owned by the caller, who is responsible for its cleanup. This is the intended design for async blocking tasks.
Applied to files:
src/runtime/task.zig
📚 Learning: 2026-01-06T09:33:09.370Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/coro/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:33:09.370Z
Learning: Applies to src/libs/coro/**/*.zig : Don't assume you know how Zig std APIs work; check the current documentation as information becomes outdated
Applied to files:
src/runtime/task.zigsrc/runtime.zigsrc/coro/stack_pool.zig
📚 Learning: 2026-01-06T09:33:09.370Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/coro/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:33:09.370Z
Learning: Applies to src/libs/coro/**/*.zig : Do not depend on `std.posix` - create custom wrappers instead in preparation for Zig 0.16 upgrade
Applied to files:
src/runtime/task.zigsrc/runtime.zigsrc/coro/stack_pool.zig
📚 Learning: 2026-01-06T09:33:09.370Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/coro/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:33:09.370Z
Learning: Applies to src/libs/coro/**/build.zig.zon : Update version in build.zig.zon during release process
Applied to files:
src/runtime.zigsrc/coro/stack_pool.zig
📚 Learning: 2026-01-06T09:32:59.436Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/aio/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:32:59.436Z
Learning: Applies to src/libs/aio/**/build.zig.zon : Release process step 2: Update version in build.zig.zon
Applied to files:
src/runtime.zig
📚 Learning: 2025-10-15T19:38:44.659Z
Learnt from: lalinsky
Repo: lalinsky/zio PR: 47
File: src/sync/Mutex.zig:237-237
Timestamp: 2025-10-15T19:38:44.659Z
Learning: In the `unlock` method of `src/sync/Mutex.zig`, the `runtime` parameter is intentionally retained (marked with `_ = runtime;`) for API consistency and future-proofing, even though it's not currently used in the implementation.
Applied to files:
src/runtime.zig
📚 Learning: 2026-01-06T09:32:59.436Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/aio/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:32:59.436Z
Learning: Applies to src/libs/aio/**/*.zig : In preparation for Zig 0.16 upgrade, don't depend on `std.posix`; create and use custom wrappers instead
Applied to files:
src/coro/stack_pool.zig
📚 Learning: 2026-01-06T09:32:50.539Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-06T09:32:50.539Z
Learning: Applies to **/*.zig : Use `zig env` to get the path to the Zig standard library when checking standard library
Applied to files:
src/coro/stack_pool.zig
📚 Learning: 2026-01-06T09:32:59.436Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/aio/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:32:59.436Z
Learning: Use `zig env` to get the path to the Zig standard library when checking standard library APIs
Applied to files:
src/coro/stack_pool.zig
📚 Learning: 2026-01-06T09:33:09.370Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/coro/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:33:09.370Z
Learning: Use `zig env` to get the path to the Zig standard library when checking Zig APIs
Applied to files:
src/coro/stack_pool.zig
📚 Learning: 2026-01-06T09:32:59.436Z
Learnt from: CR
Repo: lalinsky/zio PR: 0
File: src/libs/aio/CLAUDE.md:0-0
Timestamp: 2026-01-06T09:32:59.436Z
Learning: Don't assume knowledge of how std APIs work in Zig; most likely you have outdated information
Applied to files:
src/coro/stack_pool.zig
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
- GitHub Check: test (master, ReleaseSafe, ubuntu-latest, x86_64-netbsd, netbsd)
- GitHub Check: test (0.15.2, ReleaseSafe, windows-latest, native)
- GitHub Check: test (master, ReleaseSafe, ubuntu-latest, riscv64-linux, true)
- GitHub Check: test (master, ReleaseSafe, ubuntu-latest, loongarch64-linux, true)
- GitHub Check: test (master, Debug, macos-15-intel, native)
- GitHub Check: test (master, ReleaseSafe, windows-latest, native)
- GitHub Check: test (master, Debug, windows-latest, native)
- GitHub Check: test (master, ReleaseSafe, ubuntu-latest, x86_64-freebsd, freebsd)
- GitHub Check: test (master, ReleaseSafe, macos-latest, native)
- GitHub Check: test (0.15.2, ReleaseSafe, macos-latest, native)
- GitHub Check: test (master, ReleaseSafe, macos-15-intel, native)
- GitHub Check: test (master, Debug, ubuntu-latest, riscv64-linux, true)
- GitHub Check: test (master, Debug, ubuntu-latest, x86_64-netbsd, netbsd)
- GitHub Check: test (0.15.2, Debug, ubuntu-latest, x86_64-netbsd, netbsd)
- GitHub Check: test (0.15.2, ReleaseSafe, ubuntu-latest, x86_64-netbsd, netbsd)
- GitHub Check: test (0.15.2, ReleaseSafe, ubuntu-latest, x86_64-freebsd, freebsd)
- GitHub Check: test (0.15.2, Debug, windows-latest, native)
- GitHub Check: test (windows-latest)
🔇 Additional comments (6)
src/coro/stack_pool.zig (4)
13-13: Good simplification to use u64 directly.Storing raw nanoseconds instead of wrapping in
std.time.Instantmakes the code simpler and the intent clearer.
113-113: Saturating subtraction is the right choice here.Using
-|handles the edge case where timestamps might be out of order (though shouldn't happen with monotonic time). Good defensive coding.
201-236: Test updates look good.Passing explicit timestamps (0) to tests makes them deterministic and easy to understand.
252-283: Excellent test improvement - this is the real win.Replacing the 150ms sleep with mock timestamps makes this test:
- Instant: No waiting for real time to pass
- Deterministic: No flakiness from timing variations
- Clearer: The test logic directly validates age-based expiration without timing noise
This kind of testability improvement is exactly why explicit time injection is valuable.
src/runtime/task.zig (1)
315-315: Call site correctly updated.Passing
rt.now()provides the event loop's cached monotonic timestamp to the release function. Clean and consistent with the new signature.src/runtime.zig (1)
551-551: Efficient use of direct loop access.Since this code is already in the executor's scheduler loop, using
self.loop.now()directly is more efficient than callingself.runtime.now()which would need to resolve back to the same loop.
This makes StackPool not access system time internally, instead requiring the caller to pass a timestamp in milliseconds. The runtime passes the event loop's cached monotonic time, and tests can pass mock timestamps to avoid sleep.
07f7231 to
05097e5
Compare
Summary
timestamp_nsparameter instead of callingstd.time.Instant.now()internallyloop.now())Test plan