Fix guardrails TOCTOU races and wire hourly reset daemon#88
Open
Fix guardrails TOCTOU races and wire hourly reset daemon#88
Conversation
…aemon - Add atomic check_and_record_tokens using CAS loop on AtomicU64 to eliminate the race between check_tokens and record_tokens - Add atomic check_and_register_task that holds the write lock for the entire check+insert, preventing concurrent tasks from exceeding the configured limit - Add atomic check_and_register_agent with the same TOCTOU fix - Migrate dag_executor to use check_and_register_task instead of the separate check/register calls - Add HourlyResetDaemon that periodically resets the hourly token counter, following the MemoryDecayDaemon pattern (AtomicBool stop flag, tokio::time::interval tick) - Retain old check/register methods (marked deprecated in docs) for backward compatibility - Add comprehensive tests for all new atomic operations and the reset daemon Fixes #41, fixes #42 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…grate dag_executor - Replace deprecated g.record_tokens() in dag_executor with atomic g.check_and_record_tokens(), handling Blocked/Warning results with tracing — this was the primary TOCTOU site the fix was meant to address - Wire HourlyResetDaemon into SwarmOrchestrator: add field, spawn at startup (after decay daemon), stop during graceful shutdown - Add #[deprecated] attributes to old check_task_start, register_task_start, check_agent_spawn, register_agent_spawn, check_tokens, record_tokens - Suppress deprecation warnings in tests that intentionally cover old API Closes #41, closes #42 Co-Authored-By: Claude Opus 4.6 <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.
Summary
check_tokens/record_tokenswithcheck_and_record_tokensusing a CAS (compare-and-swap) loop onAtomicU64, eliminating the TOCTOU race where concurrent token recording could exceed hourly limitscheck_and_register_taskandcheck_and_register_agentthat hold the write lock for the full check+insert, replacing the splitcheck_task_start/register_task_startpatternHourlyResetDaemonfollowing theMemoryDecayDaemonpattern, wired intoSwarmOrchestrator.run()lifecycle with proper startup/shutdowndag_executor.rsto use the new atomic methodsCloses #41
Closes #42
Test plan
cargo checkclean🤖 Generated with Claude Code