Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
Each emoji reaction (from #6609) builds the whole active branch to find the message it is about:
- the user's
LocalConversation.reactcallsfind_reaction_target(state.active_branch(), ...), thenConversationState.get_unmatched_actions(state.active_branch())to decide whether to hold the reaction back; - the agent's
react/unreactexecutor callsfind_reaction_target(state.active_branch(), ...); - while held reactions wait,
_flush_pending_reactionsrebuilds the whole branch again on every observation.
active_branch() walks from the leaf to the root and reads every event on the way. An EventLog can hold 60k+ events, so a single reaction costs the length of the conversation.
Expected Behavior
A reaction's cost follows where its message is, not the size of the log:
- the agent reacts only to a message it sees, so it looks in
state.view.events; - the user may react to a message that the agent no longer sees (condensed out of the View), so the user's reaction walks back from the end of the active branch only as far as that message;
- "are tool calls waiting for their results?" reads back only through the agent's latest batch of tool calls.
Actual Behavior
O(branch) work (event reads, from disk on a cold cache) on every reaction, twice for the user's, and on every observation while a reaction is held.
Steps to Reproduce
- Load a conversation with a long history.
- React to the agent's latest message via
POST /api/conversations/{id}/reactions. - Every event on the active branch is read.
Acceptance Criteria
- No reaction path calls
active_branch()or otherwise reads the whole log. - Messages on branches the conversation navigated away from are still never targets.
- Tests show the user's reaction reads only back to its message and the agent's looks only at its View.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Verified against main: LocalConversation.react builds the whole active branch twice (find_reaction_target(state.active_branch(), ...) and ConversationState.get_unmatched_actions(state.active_branch())), _flush_pending_reactions rebuilds it on every observation while a reaction is held, and the agent's ReactionExecutor builds it again; active_branch() with no limit walks leaf→root through EventLog.path_to_root, deserializing every event. The repository already ships the primitives for a bounded lookup (EventLog.get_index() for id→index, active_branch(limit=...) for O(limit) windows, state.view.events for what the agent sees), so the expected behavior is achievable without a new mechanism, and the maintainer has already opened a fix (draft PR #6901, "Fixes #6899"). Bounded scope: make each reaction's cost proportional to the distance to its target — the agent's tools read state.view.events, the user's reaction walks back from the end of the active branch only as far as its target, and the held-reaction check reads back only through the agent's latest batch of tool calls. Non-goals: no API or event-schema changes (POST /api/conversations/{id}/reactions, ReactionEvent, ReactionObservation, the react/unreact tools keep their shape), no changes to reaction holding/unheld timing or the off-branch exclusion rule, no change to get_unmatched_actions itself or its other callers, and no new cost/latency instrumentation. Preserving the route's contract is part of the check: an unknown or off-branch target_event_id still fails with 400 through the existing ValueError → Invalid mapping in event_router.py, not 404/409.
Acceptance Criteria
- The user's reaction path (
LocalConversation.react, including its pending-tool-call check and_flush_pending_reactions) reads at most the events from the end of the active branch back to the target message; no reaction path callsactive_branch()without a bound or iterates the full branch. This includesfind_reaction_targetandReactionExecutor— the agent'sreact/unreactread onlystate.view.eventsand do not touch the log for a target that is in the View. - A reaction to an event that is off the active branch (after
navigate_to) or condensed out of the agent's View still raisesValueError("No message with id {id}" / "no agent message"), soPOST /api/conversations/{id}/reactionsstill answers 400 through the existingevent_router.pymapping and the tool returns an error observation. - The held-reaction decision returns no waiting action while any tool call lacks its result, and lets the held reaction through once every open call has its result, matching
test_a_reaction_during_a_pending_tool_call_waits_for_its_resultandtest_execute_tool_returns_the_reaction_without_recording_itsemantics. - Regression tests in
tests/tools/reaction/(and any state/event tests for the new bounded-lookup helper) pass underuv run pytest tests/tools/reaction, including a test that demonstrates the read bound — e.g., a long branch where the reaction reads only back to its target — and keep the existing tests (test_messages_off_the_active_branch_are_not_targets, the pending-tool-call and finish-target tests) passing.
Activity