opencode-goal-plugin icon indicating copy to clipboard operation
opencode-goal-plugin copied to clipboard

[Bug]: Large-plan editing: full-plan resend per revision, one validation error per round-trip, no field paths

Open Misaka0x26FE opened this issue 1 month ago • 0 comments

Environment: @prevalentware/opencode-goal-plugin 0.1.60 (installed bundle dist/server.js), OpenCode v2.0.29, Linux. Goal used for a long multi-phase task: 12 phases / 40 tasks, plan JSON 17.6 KB, 11 accepted plan revisions in one session.

Summary

Managing a large plan through update_goal_plan is workable at small sizes but becomes expensive and failure-prone as the plan grows:

  1. every revision must resend the entire plan (no diff/patch mode);
  2. every validation failure costs another full-plan resend, and cross-revision rules are enforced one violation at a time with no field paths;
  3. both get_goal and the tool result echo the entire goal, so a routine status flip costs ≈3× plan size in tokens;
  4. each auto-continue turn injects the full plan JSON into the prompt again.

Observed sequence — one logical edit (mark the last phase as blocked)

  1. Sent revision N with the phase set to blocked (task-level blockers included, phase-level blocker omitted) → rejected: {"error":{"type":"unknown","message":"[{\"code\":\"custom\",\"message\":\"blocked phases require a blocker\",\"path\":[\"plan\"]}]"}} (Zod custom issue anchored at path: ["plan"], not at the offending phase).
  2. Added the phase-level blocker and resent the full plan → rejected again: changing planned phase scope requires concrete revisit evidence (plain throw, no path and no indication of what changed — in my case it was a cosmetic rewording of one phase's objective, which I could not identify from the message).
  3. Added revisit_evidence and resent → accepted.

⇒ 3 round-trips / 3 full-plan sends for one status change, and the second error cannot be diagnosed without guessing (supplying revisit_evidence would also silently bless an unintended scope edit).

Also observed (possibly harness-side): a call missing a required field (reason) surfaced as Connection lost while reading the response: ECONNRESET instead of a validation error.

Cost numbers (measured from ~/.local/share/opencode-goal-plugin/goals.json)

  • plan JSON: 17,625 chars ≈ 4.4k tokens; whole goal JSON: 30,732 chars ≈ 7.7k tokens
  • 11 accepted revisions (plan.changes length) + 3 rejected attempts = 14 full-plan writes
  • each revision additionally follows the documented policy “Read get_goal and use its id and planRevision”, and the result echoes the whole goal → read + write + echo ≈ 20k tokens per revision (~0.3M tokens of bookkeeping for one goal on a 17.6 KB plan)
  • every continuation prompt re-injects JSON.stringify({plan, progress}) in <untrusted_goal_plan> (~4.4k tokens per auto-continue)

Root causes (shipped dist/server.js)

  • planToolArgs (~line 2999): takes goal_id, expected_revision, plan in full (GoalPlanInputSchema), reason, optional revisit_evidence — no partial/diff input.
  • reviseGoalPlan (~79–136): ten sequential throw new Error(...) statements (lines 81/86/92/94/98/100/102/108/112/114) — the first violation aborts, so one submission can be rejected repeatedly for different reasons.
  • GoalPlanSchema (line 41): blocked phases require a blocker is a Zod custom issue at path: ["plan"]; the cross-revision throws carry no path at all.
  • planFromTool (~5010): returns {goal: <whole goal>}; get_goal returns the whole goal (plan + history + checkpoints).
  • durablePlanContext (~1882): injects the full {plan, progress} JSON into every continuation prompt.

Suggested fixes (roughly in priority order)

  1. Aggregate violations: evaluate all cross-revision rules and throw one error listing every violation with a field path and the previous→next values, e.g. phases[batch-f].objective changed ("F …(贯穿全程)" → "F …") — requires revisit_evidence. This cuts round-trips and prevents accidentally blessing scope changes.
  2. Document the invariants in the model-facing tool description / per-field .describe(): completionCriteria immutable, blocked phases need blocker, revisit_evidence semantics, completed task ID/description preservation. Today they are only discoverable by failing.
  3. Patch/diff mode: accept plan_ops (set phase status, upsert task, append decision) or a partial plan merged server-side; keep the full-plan mode as fallback so routine status flips stop resending the whole plan.
  4. Compact reads/writes: get_goal with a summary mode returning {revision, progress, next_task}; return {revision, progress} rather than the whole goal from update_goal_plan (behind a flag); inject only planProgress + revision into continuation prompts (the plan stays reachable via get_goal) — also reduces pressure on the prompt-cache issue (#13).
  5. Machine-readable errors: if the tool layer serializes validation issues anyway, make the plugin side emit a single multi-line human-readable message with paths so {"error":{"type":"unknown","message":"…"}} stays readable.

Minimal reproduction

  1. create a goal with a 3-phase plan;
  2. set a phase to blocked without a phase-level blocker → error 1 (path ["plan"]);
  3. add the blocker and reword any phase objective → error 2 (no path);
  4. add revisit_evidence → accepted.

⇒ 3 round-trips / 3 full-plan sends for one status change.

Happy to test a patch. The plan/phase/progress model itself is exactly what long-running sessions need — this is purely about the update API's cost and failure ergonomics.

Misaka0x26FE avatar Oct 15 '26 10:10 Misaka0x26FE