Skip to content

feat: graceful wind-down on rate limit detection#10

Open
Savolent wants to merge 1 commit intovcarl:mainfrom
Savolent:stability-wind-down-upstream
Open

feat: graceful wind-down on rate limit detection#10
Savolent wants to merge 1 commit intovcarl:mainfrom
Savolent:stability-wind-down-upstream

Conversation

@Savolent
Copy link
Copy Markdown
Contributor

Summary

  • New wind-down file IPC mechanism for graceful session lifecycle management
  • Process runner detects rate_limit_event in Claude's stream-json output and writes WIND_DOWN.json
  • Orchestrators can poll this file to halt gracefully instead of spinning on rate-limited API calls

Changes

File What changed
operator/wind-down-file.ts NEW — WindDownSignal type, writeWindDown(), readWindDown(), clearWindDown(), isWindDownStale(), startWindDownWatcher()
process-runner.ts Detect rate_limit_event in stream, write WIND_DOWN.json with reset time. Triggers on rejection or >75% utilization warning.
hypothalamus/types.ts Add rateLimitResetsAt?: number to TurnResult
index.ts Export wind-down types and functions

Motivation

When API rate limits hit, agents should stop gracefully rather than continue attempting API calls that will fail. The wind-down file provides a filesystem-based IPC signal that any monitoring process can read:

  1. Rate limit detected in stream → WIND_DOWN.json written with sessionEndTime
  2. Orchestrator polls for the file, halts all agents gracefully
  3. isWindDownStale() auto-detects expired signals for cleanup

Test plan

  • npx nx run @roci/core:build passes (verified)
  • Rate limit event in stream triggers WIND_DOWN.json creation
  • readWindDown() returns null when no file exists
  • isWindDownStale() returns true for expired signals, false for active ones
  • startWindDownWatcher() calls callback when signal appears

🤖 Generated with Claude Code

Add a wind-down file IPC mechanism for graceful session lifecycle
management. When the Claude API returns a rate_limit_event in the
stream-json output, the process runner writes a WIND_DOWN.json file
that the orchestrator can poll to halt gracefully.

- New file: operator/wind-down-file.ts with read/write/clear/isStale/watcher
- process-runner.ts: detect rate_limit_event, write WIND_DOWN.json
- TurnResult: add optional rateLimitResetsAt field
- Export WindDownSignal type and functions from @roci/core

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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