Skip to content

[FEATURE]: /goal: let plugins declare background work in SessionIdle.background #60860

Open

Description

@ivopogace

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

/goal's idle judge (packages/core/src/plugin/goal.ts, v2.2.5) only sees background work the host itself tracks in SessionIdle.background: subagent, image and shell. It skips judging while the Session's own subagent or image job runs (lines 150–153). It offers wait only while one of the Session's own shells runs (lines 126–127).

A plugin can run work in other sessions and wake this one when that work finishes, but it has no way to say so. opencode-courier, for example, spawns child sessions that report back to their parent with a session.synthetic message. So a root with an active goal that spawns children and ends its turn to wait for their reports looks finished or stalled to the judge. The judge answers continue, the root is prompted on instead of waiting, and after MAX_STALLS rounds the goal pauses with "Not making progress".

Reproduced on 2.2.4 with a scripted reviewer: three continuations within a second of the spawn, then the goal paused, 25 s before the child reported. The same happened with children created with parentID set to the root.

Proposal

Let a plugin add entries to SessionIdle.background for a session, for example:

{ kind: "plugin", sessionID, description: string }

/goal would treat these the way it treats a subagent: the plugin's own wake (a synthetic message) runs the hook again, so the judge can simply return. It could also offer wait for them. Its WAIT_LIMIT watchdog would still pause a goal whose plugin work never reports.

Another option: let /goal hold back while any plugin reports pending work for the session, through a hook or a field on the idle event.

Context

Activity

  1. opencodejr commented on Oct 31, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up and the repro, @ivopogace!

    To restate the request: plugins should be able to declare pending background work for a session, for example a { kind: "plugin", sessionID, description } entry in SessionIdle.background. /goal could then skip judging, or offer wait, while that work runs, the same way it handles the session's own subagents and shells.

    I checked v2.2.5. SessionIdleBackground only covers work the host tracks itself, and built-in idle hooks run before package plugins. So a plugin can't add this on its own today; it needs a change to the plugin API. Maintainers will consider it.

    Related:

  2. jwitmann commented on Nov 5, 2026

    @jwitmann

    Following this as the author of opencode-dev-framework — my completion gate currently re-prompts through experimental.idle → session.synthetic with its own bound, while /goal judges the same turn, so the two continuations step on each other and I have no way to tell the judge my gate work is still pending. Being able to declare that background work would make them deterministic (no race).

  3. chenpao7 commented on Nov 24, 2026

    @chenpao7

    I'm experiencing a similar issue with callback-driven remote GPU benchmarking.

    I'd be interested in trying to work on this. I'm still getting familiar with the OpenCode codebase, but I'll do my best to explore a solution.

    Any suggestions or guidance would be greatly appreciated. Thank you!

  4. jwitmann commented on Nov 25, 2026

    @jwitmann

    Your benchmarking case is the same shape as the courier one in the issue (work the host can't see, wake arrives from outside), which is useful: two independent cases makes it a general API gap, not a one-plugin quirk.

    I've been through this area for my own gate work, so to save you some digging:

    • the host entries get built in packages/core/src/session/background.ts from Job recovery records, the public type is SessionIdleBackground in the plugin session types, and the judge lives in packages/core/src/plugin/goal.ts (idle() skips on own subagent/image work, offers wait only for shells).
    • The consumer half is small — treat a plugin entry like a subagent for the skip, and only offer wait if the plugin guarantees a wake, otherwise WAIT_LIMIT pauses it, which is the right backstop anyway.
    • The real design question is the producer side: where a plugin declares "I'm waiting on X" and how that gets cleaned up. That's the piece worth sketching first, even roughly, before writing code.

    One practical tip: keep the PR to type + registry + goal handling + tests, modeled on session-background.test.ts and subagent-idle-e2e.test.ts. Small ones move fastest here — review bandwidth is thin.

    And if it helps, I'm happy to test against opencode-dev-framework. My completion gate hits the exact same race (my re-prompt vs /goal's continuation, no way to declare pending work), so you'd have a second consumer from day one.

  5. iniaki662 commented on Nov 29, 2026

    @iniaki662

    We run the goal loop from a plugin rather than the built-in opencode.goal, so
    we hit the limitation described here from the other side.

    Our plugin (thread-goal, https://github.com/iniaki662/opencode-thread-goal)
    keeps its own state in plugin storage and drives continuation from the idle hook.
    Two consequences of the built-in design that a plugin-owned goal has to work
    around:

    1. The goal state is not reachable from a plugin. The built-in goal exposes
      get plus a changed event, so a plugin can read a goal but cannot re-limit
      or drive it - every alternative has to reimplement the judge and the stall
      logic. That is exactly what we ended up doing (we ported MiniMax Code's
      agent-modules/goal, which has no external judge: the agent proposes the
      terminal state and the host settles it).
    2. Background work cannot be declared from a plugin. Our continuation often
      waits on work started outside the session (a quota wake-up, an external
      worker), and there is no way to tell the idle judge that the session is
      waiting rather than finished.

    We are not asking for a specific API. What would help is either:

    Either way the goal semantics stay pluggable instead of being fixed in the
    built-in plugin. Happy to share the plugin as a reference implementation.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions