Skip to content

fix: dead regex in quotaResetDelay, write_count race, env info lock#6684

Open
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/dead-regex-write-count-race-env-lock
Open

fix: dead regex in quotaResetDelay, write_count race, env info lock#6684
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/dead-regex-write-count-race-env-lock

Conversation

@aaronlab

@aaronlab aaronlab commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • run_agent.py: Fix double-escaped \d in quotaResetDelay regex (line 2313) — the pattern \\d in a raw string matches a literal backslash+d, never matching actual digits. This makes rate-limit reset time extraction dead code. The companion sec_match regex (line 2320) uses \d correctly, confirming this is a bug, not a style choice.
  • hermes_state.py: Move _write_count += 1 inside self._lock to prevent concurrent _execute_write callers from racing on the counter, which could skip or double WAL checkpoints.
  • tools/terminal_tool.py: Acquire _env_lock in get_active_environments_info() before reading _active_environments. Without the lock, a concurrent cleanup_vm() call can modify the dict mid-iteration, raising RuntimeError: dictionary changed size during iteration.

Test plan

  • Verify _extract_api_error_context correctly parses quotaResetDelay: 30000ms from Gemini API errors
  • Confirm WAL checkpoints fire at consistent intervals under concurrent writes
  • Confirm get_active_environments_info() no longer raises under concurrent environment cleanup

🤖 Generated with Claude Code

1. run_agent.py: Fix double-escaped \d in quotaResetDelay regex that
   caused it to never match (dead code since introduction). The
   sec_match fallback regex on line 2320 uses \d correctly.

2. hermes_state.py: Move _write_count increment inside self._lock to
   prevent concurrent _execute_write callers from racing on the counter
   and skipping/doubling WAL checkpoints.

3. tools/terminal_tool.py: Acquire _env_lock in get_active_environments_info
   before reading _active_environments. Without the lock, a concurrent
   cleanup_vm() call can modify the dict mid-iteration, raising
   RuntimeError: dictionary changed size during iteration.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder tool/terminal Terminal execution and process management labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #6655 — overlapping fix for _env_lock in terminal tool shared dict accesses.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #6655 — overlapping fix for _env_lock in terminal tool shared dict accesses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants