Skip to content

refactor(rivetkit-core): remove prevent_sleep field and deprecate set_prevent_sleep to no-op#4741

Merged
NathanFlurry merged 1 commit intomainfrom
sleep-cleanup/01-core-remove-prevent-sleep
Apr 27, 2026
Merged

refactor(rivetkit-core): remove prevent_sleep field and deprecate set_prevent_sleep to no-op#4741
NathanFlurry merged 1 commit intomainfrom
sleep-cleanup/01-core-remove-prevent-sleep

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 24, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026

PR Review: Remove prevent_sleep and Deprecate to No-op

Overview

This PR removes the prevent_sleep field and its associated AtomicBool/Notify machinery from rivetkit-core, replacing set_prevent_sleep and prevent_sleep with deprecated no-ops. The Rust-side cleanup is mechanically correct, but there is a behavioral concern on the native/agentOS actor path worth addressing before merge.


Critical: agentOS syncPreventSleep becomes a silent no-op on the native path

The agentOS actor factory (rivetkit-typescript/packages/rivetkit/src/agent-os/actor/index.ts) uses syncPreventSleep(c) to keep actors alive while sessions, processes, hooks, and shells are active. This calls c.setPreventSleep(...), which on the native actor path flows through NativeActorContextAdapter.setPreventSleep() in native.ts, which now delegates to the Rust no-op.

The consequence: agentOS actors with active sessions, processes, or shells can now be put to sleep mid-work. The agentOS sleepGracePeriod is 900 seconds, so this may not manifest immediately in practice, but the invariant that "actor stays awake while activeSessionIds.size > 0 || activeProcesses.size > 0" is silently broken.

The agentOS path needs to be migrated to keep_awake / wait_until before this PR removes prevent_sleep from being effective. Session and process lifecycle hooks should hold a keepAwake guard for the duration of active work instead of calling syncPreventSleep.

Required fix before merge: Either migrate syncPreventSleep in agentOS to a keepAwake-guard-based approach, or gate this change so it only becomes effective for agentOS once that migration is done. Otherwise, agentOS actors may sleep with active sessions.


Minor Issues

Stale invariant docs. Any comments or documentation listing prevent_sleep as a can_sleep input should be updated to remove it, to avoid confusing future contributors.

Unused parameter naming. In rivetkit/src/context.rs, the delegating set_prevent_sleep(enabled: bool) passes enabled to the inner no-op. Since the inner function ignores it, the outer parameter could be _enabled for consistency.

Consider #[doc(hidden)] on deprecated methods. Since set_prevent_sleep and prevent_sleep always no-op/return false and are kept only for NAPI bridge compatibility, annotating them with #[doc(hidden)] alongside #[deprecated] would keep them out of rustdoc while still compiling.


What Looks Good

  • The AtomicBool removal and prevent_sleep_notify: Arc<Notify> removal from the registry are clean with no dangling references.
  • The CanSleep::PreventSleep variant is fully removed from both the enum definition and all match arms in sleep.rs.
  • The #[allow(deprecated)] annotations in rivetkit-napi and rivetkit/context.rs correctly suppress call-site warnings while preserving the bridge surface.
  • The #[deprecated] annotation on both crates will surface warnings to downstream Rust consumers, which is the right signal.
  • The can_finalize_sleep predicate removal is consistent with the can_arm_sleep_timer removal — no half-removed guard conditions remain.
  • The wait_for_shutdown_tasks drain loop correctly drops the !self.prevent_sleep() guard since wait_until tasks now track via shutdown_tasks and keep_awake guards cover the other cases.

Summary

The Rust-side removal is mechanically sound. The main concern is the behavioral regression for agentOS actors where syncPreventSleep calls c.setPreventSleep() on the native adapter, which is now a no-op. This should be addressed via a keepAwake-guard migration in agentOS before landing, or the agentOS path should be explicitly handled so actors don't sleep with active sessions.

@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/01-core-remove-prevent-sleep branch from 96f71c0 to c43b558 Compare April 24, 2026 10:32
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/01-core-remove-prevent-sleep branch 2 times, most recently from f4dbc84 to b3b1cf8 Compare April 24, 2026 12:14
@NathanFlurry NathanFlurry force-pushed the db-fuzzer-kitchen-sink branch from 7531961 to 7d74821 Compare April 24, 2026 12:32
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/01-core-remove-prevent-sleep branch from b3b1cf8 to 610bbe5 Compare April 24, 2026 12:32
@NathanFlurry NathanFlurry changed the base branch from db-fuzzer-kitchen-sink to graphite-base/4741 April 24, 2026 12:59
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4741 to main April 24, 2026 13:00
@NathanFlurry NathanFlurry changed the base branch from main to graphite-base/4741 April 24, 2026 13:16
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/01-core-remove-prevent-sleep branch from 610bbe5 to bbf3422 Compare April 24, 2026 13:16
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4741 to 04-24-fix_api_public_import_export_orphans April 24, 2026 13:16
Base automatically changed from 04-24-fix_api_public_import_export_orphans to main April 27, 2026 07:13
@NathanFlurry NathanFlurry merged commit 19cfda1 into main Apr 27, 2026
20 of 27 checks passed
@NathanFlurry NathanFlurry deleted the sleep-cleanup/01-core-remove-prevent-sleep branch April 27, 2026 07:14
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