Skip to content

refactor(core): serve the goal over a plugin RPC instead of session metadata - #59850

Merged
neriousy merged 7 commits into
client-done-checkfrom
goal-rpc
Oct 28, 2026
Merged

neriousy merged 7 commits into
client-done-checkfrom
goal-rpc

Conversation

@neriousy

@neriousy neriousy commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Stacked on #59437, so it targets client-done-check. It's a variant for comparison: the /goal state moves out of Session metadata and behind the goal plugin's own RPC. No new package: the plugin stays in core, and its RPC contract lives in @opencode/schema.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

In #59437 the goal lives in Session metadata under opencode.goal. That has three problems:

  • Copied into children and forks, so every reader has to check the goal's sessionID.
  • No ownership. Any plugin or API client can overwrite the key.
  • The storage format is public through @opencode/schema/session-goal.

Here the goal plugin owns its state and serves it over a plugin RPC:

  • Contract (@opencode/schema/goal, replacing @opencode/schema/session-goal): Goal.State without sessionID, plus Goal.Definition, an RPC opencode.goal with get({ sessionID }) and a changed event { sessionID, goal }. It describes the RPC, not storage. Its schemas are wrapped with Schema.toStandardSchemaV1, so the Promise client can call it.
  • Server (core/src/plugin/goal.ts):
    • Storage: the goal lives in the plugin's own storage, key session:<id>. Plugin storage isn't per Location, so a goal follows its Session when it moves, and children and forks start without one.
    • Writes: every write publishes changed in the Session's Location.
    • Cleanup: session.deleted removes the entry. The startup sweep pages through every stored goal, pausing goals left by an earlier process and dropping goals of deleted Sessions. Before, it checked the 100 most recent Sessions.
    • Commands: /goal pause, resume and clear are unchanged.
  • Desktop (gui-plugins/src/goal/renderer.tsx):
    • Subscription: one createKeyed run per routed Session while its server is connected: get for the current value, then changed.
    • Refetch: it runs again when another Session is routed, the Session moves, or the server reconnects, since changes published meanwhile were missed.
    • Cache: keyed by server and Session, so switching back shows the last value while the refetch runs.
    • Ordering: a reply that arrives after a newer changed is ignored.
  • TUI (prompt/goal.tsx): createSessionGoal, the same pattern. It fetches on Session change and after server.connected, follows changed, and ignores replies older than the last change. The footer owns it and passes it to the status item and the dialog.
  • Removed: @opencode/schema/session-goal, with SessionGoal.KEY and fromMetadata. The client store's handling of session.metadata.updated from feat(core): add /goal with a client-side done check #59437 stays, since it's a general fix.

The client cost is one get per routed Session, plus one after each reconnect. RPC events ride the client's shared event stream, so there's no extra connection.

Trade-offs

  • Events are only for a Location. changed is published in the Session's Location. The startup sweep runs in whichever Location loads first, so a goal it pauses in another Location is only picked up by that Location's clients on their next fetch: a reconnect, which follows the restart anyway, or a route.
  • Desktop has no direct test. No automated test covers the desktop data path. It's checked by type checks and by the component tests that boot every built-in.

How did you verify your code works?

  • goal-watchdog.test.ts, new "serves the goal over RPC and publishes every change": get returns null, then the paused goal, then null after clear. changed carries active, paused, then null. It fails if writes stop publishing the goal.
  • goal.test.ts: the full-stack scenarios now seed and read goals through the plugin's real storage (PluginHost.storage). The child-Session case now checks that a child created during an active goal has no goal and isn't driven.
  • prompt-footer.test.tsx: the footer shows the goal from get, follows changed for its own Session only, and clears on goal: null. It fails if the Session filter is removed, and passes --rerun-each 10.
  • Checks: bun run check, lint:changed and the SDK docs check pass. @opencode/schema passes typecheck:tsc.
  • Tests: core goal, runner and execution (296), the TUI footer and notification tests (13), and the app's plugin-graph and plugin-host component tests (30) all pass.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@neriousy
neriousy requested a review from a team October 28, 2026 08:18
@neriousy neriousy changed the title refactor(core): serve the goal over a plugin RPC instead of session metadata refactor(core): move the goal into @opencode/plugin-goal behind a plugin RPC Oct 28, 2026
@neriousy neriousy changed the title refactor(core): move the goal into @opencode/plugin-goal behind a plugin RPC refactor(core): serve the goal over a plugin RPC instead of session metadata Oct 28, 2026
@neriousy
neriousy merged commit 3582fab into client-done-check Oct 28, 2026
18 checks passed
@neriousy
neriousy deleted the goal-rpc branch October 28, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant