[P2] Document Threading Model #14

Closed
opened 2025-12-05 13:49:34 +00:00 by blightbow · 1 comment
Owner

Problem

  • Multiple fields modified without locks (is_ticking, consecutive_errors, current_tool_call)
  • Threading model assumptions not documented
  • No state synchronization documentation

Suggested Fix

  • Clarify single-reactor assumption
  • Add assertions if multi-threaded operation is unsupported

Priority

P2 — Medium Priority

Source

Architecture Audit 2025-12-03, Section 1: Async/Concurrency Issues

## Problem - Multiple fields modified without locks (`is_ticking`, `consecutive_errors`, `current_tool_call`) - Threading model assumptions not documented - No state synchronization documentation ## Suggested Fix - Clarify single-reactor assumption - Add assertions if multi-threaded operation is unsupported ## Priority **P2 — Medium Priority** ## Source Architecture Audit 2025-12-03, Section 1: Async/Concurrency Issues
Author
Owner

Implementation Complete

Committed in e35184066: Document threading model and add safety assertion

Changes

Module docstring (assistant_script.py):

  • Comprehensive "Threading Model" section explaining single-reactor guarantees
  • Documents safety for is_ticking, consecutive_errors, current_tool_call, emergency_stop
  • Warning about multi-reactor/deferToThread violations

at_tick docstring:

  • Added "Threading Model" section explaining why is_ticking is safe

Inline comments:

  • Tick collision detection: explains single-threaded reactor safety
  • Finally block: documents cleanup guarantee

Safety assertion (line 678):

assert not self.db.is_ticking, (
    "Tick collision bypassed - this indicates a threading model violation. "
    "The AI assistant requires single-reactor execution."
)

CLAUDE.md: Added threading model to feature location table.

Verification

All 30 tick loop tests pass.

## Implementation Complete Committed in `e35184066`: Document threading model and add safety assertion ### Changes **Module docstring** (`assistant_script.py`): - Comprehensive "Threading Model" section explaining single-reactor guarantees - Documents safety for `is_ticking`, `consecutive_errors`, `current_tool_call`, `emergency_stop` - Warning about multi-reactor/deferToThread violations **at_tick docstring**: - Added "Threading Model" section explaining why `is_ticking` is safe **Inline comments**: - Tick collision detection: explains single-threaded reactor safety - Finally block: documents cleanup guarantee **Safety assertion** (line 678): ```python assert not self.db.is_ticking, ( "Tick collision bypassed - this indicates a threading model violation. " "The AI assistant requires single-reactor execution." ) ``` **CLAUDE.md**: Added threading model to feature location table. ### Verification All 30 tick loop tests pass.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blightbow/evennia_ai#14
No description provided.