Skip to content

[Bug]: Every reaction reads the whole active branch to find its message #6899

Closed

Description

@enyst

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.react calls find_reaction_target(state.active_branch(), ...), then ConversationState.get_unmatched_actions(state.active_branch()) to decide whether to hold the reaction back;
  • the agent's react/unreact executor calls find_reaction_target(state.active_branch(), ...);
  • while held reactions wait, _flush_pending_reactions rebuilds 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

  1. Load a conversation with a long history.
  2. React to the agent's latest message via POST /api/conversations/{id}/reactions.
  3. 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 calls active_branch() without a bound or iterates the full branch. This includes find_reaction_target and ReactionExecutor — the agent's react/unreact read only state.view.events and 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 raises ValueError ("No message with id {id}" / "no agent message"), so POST /api/conversations/{id}/reactions still answers 400 through the existing event_router.py mapping 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_result and test_execute_tool_returns_the_reaction_without_recording_it semantics.
  • Regression tests in tests/tools/reaction/ (and any state/event tests for the new bounded-lookup helper) pass under uv 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

  1. added
    priority:lowFor bugs, affects only non-mainstream cases, or is annoying but with a clear workaround.
    ready-for-devIssue meets development readiness criteria
    on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:lowFor bugs, affects only non-mainstream cases, or is annoying but with a clear workaround.ready-for-devIssue meets development readiness criteria

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions