Skip to content

fix(coding-agent): pause stale goals on direct input - #553

Open
realsigridjin wants to merge 2 commits into
code-yeongyu:mainfrom
realsigridjin:fix/stale-goal-input-precedence
Open

fix(coding-agent): pause stale goals on direct input#553
realsigridjin wants to merge 2 commits into
code-yeongyu:mainfrom
realsigridjin:fix/stale-goal-input-precedence

Conversation

@realsigridjin

@realsigridjin realsigridjin commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • pause an active durable goal as soon as newer interactive or RPC input arrives
  • cancel pending monitor continuation synchronously and defer in-flight pauses until usage is fully accounted
  • remove the unconditional userGrace continuation path while preserving extension-originated and unattended monitor continuation
  • migrate legacy pi-goal state before session initialization without changing current-store precedence or tokenBudget round trips

Root cause

Direct input did not create another session. A stale active goal remained eligible for a hidden delayed continuation after the user had moved on, making the terminal appear to switch back to another task.

Behavior changes

  • idle direct input accounts the existing idle window, then persists active -> paused before the new turn
  • in-flight direct input preserves that turn's usage, then pauses at agent_end with a goal-id guard
  • blocked and paused goals remain unchanged by ordinary input; blocked goals now require explicit /goal resume
  • extension input never pauses a goal, and explicit resume re-arms one continuation
  • current goal files always win over legacy files; only legacy migration removes obsolete budget metadata

Verification

  • affected goal, wire, and regression suites: 9 files / 134 tests passed
  • isolated migration commit: 3 files / 74 tests passed, plus full npm run check
  • full npm run check passed on the final tree
  • ordered root npm run build passed
  • built and installed RPC plus native PTY/TUI stale-goal scenarios passed
  • five independent review lanes passed after finding and fixing the current-store tokenBudget regression

Risk boundaries

  • no authentication, dependency, lockfile, payment, or provider behavior changes
  • timer tests use fake time and assert synchronous cancellation before the first awaited read
  • changes are split into independently reviewable migration and input-precedence commits

Related to #447.


Summary by cubic

Pause active goals on direct interactive/RPC input to prevent stale hidden continuations; remove the 60s “userGrace” timer and keep monitor-delayed continuation intact. Also migrate legacy pi-goal files into the current goal store at session start. Fixes #447.

  • Bug Fixes

    • Idle input pauses active -> paused at the input seam; the new turn isn’t charged to the goal.
    • Input during a run defers the pause to agent_end after usage is accounted.
    • Cancels any pending monitor continuation immediately on input; extension-sourced input never pauses.
    • Blocked goals no longer auto-resume on user prompts; use /goal resume to reactivate.
  • Migration

    • On session start, migrate from extensions/pi-goal/<threadId>.json to extensions/goal/<threadId>.json.
    • Drop legacy tokenBudget and normalize budgetLimited to active; existing current-store files always win.
    • Current-store tokenBudget metadata (if present) is preserved on read/write.

Written for commit 92af158. Summary will update on new commits.

Review in cubic

Migrate legacy pi-goal state before session initialization while keeping current-store precedence and current token-budget metadata intact.
Give newer interactive and RPC input precedence over active durable goals while preserving extension continuation, in-flight accounting, and explicit lifecycle controls.

Related to code-yeongyu#447.
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.

Built-in goal continuation can cause unbounded token consumption and self-reinforcing output loops

1 participant