Enable TF service to wait for future transforms#2229
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR adds a
Confidence Score: 4/5Safe to merge; the wait/notify logic is correct and all previously-flagged buffer-iteration races are resolved. The core threading design is sound — re-entrant Condition/RLock nesting is handled correctly, spurious wakeups are covered by the while loop, and the race window between the initial _get and _wait_get acquiring the lock is closed by the first iteration of the loop rechecking before waiting. The one remaining issue is that logger.warning fires unconditionally on a forward_tolerance timeout, which could produce log noise for callers using forward_tolerance as a finite retry window. dimos/protocol/tf/tf.py — the warning emission on timeout is the only outstanding concern. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant MultiTBuffer
participant _cv as threading.Condition (_cv)
participant Publisher
Caller->>MultiTBuffer: "get(parent, child, forward_tolerance=T)"
MultiTBuffer->>_cv: acquire (via _get)
_cv-->>MultiTBuffer: locked
MultiTBuffer->>MultiTBuffer: get_transform / get_transform_search → None
_cv-->>MultiTBuffer: release
Note over MultiTBuffer: result is None, forward_tolerance > 0
MultiTBuffer->>_cv: acquire (via _wait_get)
_cv-->>MultiTBuffer: locked
loop until result or deadline
MultiTBuffer->>MultiTBuffer: _get() [re-entrant RLock]
alt transform not yet available
MultiTBuffer->>_cv: "wait(timeout=remaining)"
_cv-->>MultiTBuffer: releases lock
Publisher->>_cv: acquire (via receive_transform)
Publisher->>MultiTBuffer: buffers[key].add(transform)
Publisher->>_cv: notify_all()
_cv-->>Publisher: release
_cv-->>MultiTBuffer: re-acquire (woken)
else transform available
MultiTBuffer-->>Caller: Transform result
end
end
alt deadline expired
MultiTBuffer-->>Caller: None + logger.warning
end
Reviews (7): Last reviewed commit: "[autofix.ci] apply automated fixes" | Re-trigger Greptile |

Problem
Closes #2212
Solution
Add a forward_tolerance param to TF service get functions. Default value is 0, keeps old behaviour.
When the lookup cannot find a transform and forward_tolerance > 0, it re-checks under a threading.Condition lock and waits until the deadline.
How to Test
uv run pytest dimos/protocol/tf/test_tf.py
Contributor License Agreement