[P0] Fix Tool Timeout Race Condition #6
Labels
No labels
audit-2025-12-03
component/api
component/commands
component/llm
component/memory
component/tick-loop
component/tools
priority
high
priority
low
status
in-progress
status
needs-info
status
needs-triage
status
on-hold
type
bug
type
documentation
type
enhancement
type
feature
type
refactor
type
test
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
blightbow/evennia_ai#6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
In
tool_execution.py:199-220, iftool.execute()takes longer than the timeout, both callbacks fire. This can cause:Suggested Fix
Use
DeferredListwith proper cancellation instead of dual callbacks.Priority
P0 — Immediate (Blocks Production)
Source
Architecture Audit 2025-12-03, Section 1: Async/Concurrency Issues
Resolution
Replaced the buggy dual-callback timeout pattern with Twisted's built-in
addTimeout().The Bug
The original code (lines 199-220):
dtool.execute()synchronously and immediately firedd.callback(result)reactor.callLater()to calld.callback()on timeoutyield dProblems:
@inlineCallbackstools (memory, delegation),resultwas a Deferred object, not the actual resultd.callback(deferred_object)fireddwith wrong valueresult.get("success")would fail since result was a DeferredAlreadyCalledErrorif somehow both paths firedThe Fix
tool_execution.py (lines 200-215):
Benefits:
maybeDeferred()handles both sync and async tools correctlyaddTimeout()uses Twisted's built-in cancellation (no race condition)Tests Added
test_tool_execution.py (9 tests):
TestMaybeDeferredPattern- sync/async/exception handlingTestAddTimeoutPattern- fast completion, timeout, async tool patternTestNoDoubleCallback- verify noAlreadyCalledErrorTestToolExecutionSourceVerification- verify fix in source code