Skip to content

Reflect sessions can recursively start more reflect sessions #1

Description

@MAakber

Hi, I ran into what looks like a recursion bug while trying /reflect.

I'm using OpenCode 1.18.1 on Windows with opencode-hermes commit 204fc281. The command returned ok, but it seemed to keep running, so I checked hermes-state.json.

The background reflect session had called hermes_nudge_now again, which created another background session. That session did the same thing. In this run, the chain reached eight levels and the titles looked like this:

<session>#reflect
<session>#reflect#reflect
<session>#reflect#reflect#reflect
...

Here is a shortened version of the event log with the session IDs removed:

{"event":"tool","sid":"<main>"}
{"event":"bg_created","sid":"<main>","bg":"<bg-1>","title":"...#reflect"}

{"event":"tool","sid":"<bg-1>"}
{"event":"bg_created","sid":"<bg-1>","bg":"<bg-2>","title":"...#reflect#reflect"}

{"event":"tool","sid":"<bg-2>"}
{"event":"bg_created","sid":"<bg-2>","bg":"<bg-3>","title":"...#reflect#reflect#reflect"}

Most of these sessions eventually returned step1_result: ["none"], so the chain stopped, but each one still created a session and made another model call.

My guess is that this happens because the experimental.chat.system.transform hook adds the "call hermes_nudge_now when the user says reflect" instruction to the internal reflector sessions too. The reflector prompt itself contains words such as "reflector" and "reflection".

There is already a prefix check in chat.message, but it did not prevent the background session from becoming mainId in this run.

I expected one /reflect call to create or reuse one background session. Internal reflector sessions probably should not be able to invoke hermes_nudge_now.

A guard against session IDs stored in bgSessionIds, both when injecting the instruction and when executing the tool, might prevent this. Restricting the trigger to the /reflect command would also avoid matching the reflector's own prompt.

I can provide the longer anonymized event log if it would help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions