Skip to content

Let the agent self-pause on an unrecoverable blocker#1

Open
dqtz5vpvj9-create wants to merge 2 commits into
jthack:mainfrom
dqtz5vpvj9-create:agent-self-pause
Open

Let the agent self-pause on an unrecoverable blocker#1
dqtz5vpvj9-create wants to merge 2 commits into
jthack:mainfrom
dqtz5vpvj9-create:agent-self-pause

Conversation

@dqtz5vpvj9-create

@dqtz5vpvj9-create dqtz5vpvj9-create commented May 11, 2026

Copy link
Copy Markdown

Motivation — observed runaway loop

The original STOP_HOOK_REASON told only the user how to stop the loop:

If the goal cannot continue productively because user input is required, explain the blocker clearly. The user can run /goal pause or /goal clear to stop automatic continuation.

When the agent encountered a real hard blocker (target device offline, missing external resource, user input required), it followed the instruction literally: it wrote "please run /goal pause" in chat and stopped. But chat text does not trigger user-side slash commands — the agent cannot invoke /goal pause. So the Stop hook re-fired, the same STOP_HOOK_REASON was re-injected, the agent re-explained the same blocker, and the loop tightened until either CLAUDE_GOAL_MAX_STOP_CONTINUES (500) was hit or the user's API budget ran out.

Shape of one real incident (Claude Opus 4.7 + Claude Code, May 2026), anonymized:

● Cannot make productive progress: target device is offline / unavailable,
  cannot continue flashing or run the verification step. Please /goal pause.
● Ran 1 stop hook
  ⎿ Stop hook error: An active /goal is still running.
    <objective>[install component X on device and verify it runs]</objective>
    ...
    The user can run /goal pause or /goal clear to stop automatic continuation.
● Cannot continue: target device is still unavailable... please run /goal pause.
● Ran 1 stop hook
  ...
[~24 retries of the same exchange]
...
⎿ Please run /login · API Error: 403 — insufficient pre-charge balance, the
  remaining account credit is below what the next request needs.

The runaway guard at 500 is far above the budget burn-through threshold for many users — the loop tightens fast enough to drain credit in well under 100 turns.

Fix — prompt only, no logic change

The backend already supports python3 claude_goal.py pause. The agent simply was never told it could use that path. This PR fixes the prompts:

  • STOP_HOOK_REASON now offers both paths and explicitly warns about the failure mode that caused the loop:

    If you cannot continue (need user input, device offline, missing resource), pause it: user runs /goal pause, or you run python3 ~/.claude/skills/goal/scripts/claude_goal.py pause yourself. "Please run /goal pause" written in chat does NOT pause — this hook will re-fire until the DB status changes. If the same blocker repeats across multiple Stop re-entries, the user has not seen your message yet; self-pause.

  • CONTINUATION_INSTRUCTIONS gets a matching paragraph so the same guidance is in scope from the moment a goal is set, not only after the Stop hook has already fired.

  • SKILL.md mirrors the rule so the skill-loaded view is consistent with the runtime prompt.

The user-side /goal pause path is unchanged and remains the right action when the user is present and responsive.

Verification

  • python3 -m pytest tests — 9/9 pass before and after.
  • Manual end-to-end on Linux + Claude Code Opus 4.7 (1M context): with the patched prompts, a goal whose blocker is "objective is ambiguous, need user clarification" triggers a single self-pause via the agent's shell tool instead of repeating the blocker explanation across Stop-hook re-entries.

Diff size

2 files changed, 5 insertions(+), 1 deletion(-).


Generated with Claude Code.

dqtz5vpvj9-create and others added 2 commits May 11, 2026 05:14
The original STOP_HOOK_REASON only offered the user-side `/goal pause`
as the way to stop the loop:

> If the goal cannot continue productively because user input is required,
> explain the blocker clearly. The user can run `/goal pause` or
> `/goal clear` to stop automatic continuation.

When the agent encountered a hard blocker (device offline, missing
external resource, user-input required), it followed the prompt
literally: it wrote "please run /goal pause" in chat and stopped. But
that chat text does not actually trigger the slash command — the agent
cannot invoke user-side slash commands. The Stop hook re-fired, the same
STOP_HOOK_REASON was re-injected, the agent re-explained the blocker,
and the loop repeated until either CLAUDE_GOAL_MAX_STOP_CONTINUES (500
by default) was hit or the user's API budget ran out.

Observed in the wild: a real session burned 24 retries of "无法继续,请运行
/goal pause" back-to-back before the user's account hit a 403
"insufficient pre-charge balance" error. The runaway guard at 500 is far
above the burn threshold for many users.

Backend already supports `python3 claude_goal.py pause`, so this is a
prompt-only fix:

- STOP_HOOK_REASON now tells the agent both paths are valid: the user
  can run `/goal pause`, or the agent can run the pause CLI itself. It
  also explicitly warns that writing "please run /goal pause" in chat
  does NOT pause, because that is the failure mode that triggers the
  loop. Finally it gives an escalation hint: if the same blocker
  reappears across multiple Stop re-entries, the user has not seen the
  message yet — self-pause.
- CONTINUATION_INSTRUCTIONS gets a matching paragraph so the same
  guidance is in scope from the moment a goal is set, not only after a
  Stop hook fires.
- SKILL.md mirrors the rule so the skill-loaded view is consistent with
  the runtime prompt.

No logic changes; existing tests still pass (9/9). The user-side
`/goal pause` path is unchanged and remains the recommended action when
the user is present.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… location

The previous prompts referenced `python3 ~/.claude/skills/goal/scripts/claude_goal.py complete`
(and similarly for pause) as literal strings. That path only resolves when the
user followed `install.sh`'s default layout. It silently breaks for anyone who:

- runs the script directly from a repo checkout (e.g. for testing or development),
- installs the skill at a non-default `~/.claude/skills/` prefix,
- runs on Windows, where `~/.claude/skills/goal/scripts/claude_goal.py` is not the install path,
- moves or renames the install directory.

In those cases the agent reads the prompt, copies the literal path, runs the
shell command, and gets `No such file or directory` — at which point it cannot
mark complete or self-pause and the Stop-hook loop returns.

Fix: introduce `SCRIPT_PATH = os.path.abspath(__file__)` and substitute it as
`{script_path}` into both `CONTINUATION_INSTRUCTIONS` and `STOP_HOOK_REASON`.
`os.path.abspath` (not `Path.resolve`) is used deliberately so symlinks are
preserved — `install.sh` puts a symlink at `~/.claude/skills/goal`, and the
prompt should refer to that stable path rather than the underlying repo path
(which can move).

`SKILL.md` is left alone: it is loaded statically by Claude Code at skill
load time, has no runtime substitution mechanism, and is tied to install.sh's
layout by definition (the skill cannot load at all if `~/.claude/skills/goal/`
does not exist), so embedding the literal install path there is correct.

Tests unchanged, 9/9 pass. Smoke-tested: stop-hook output now contains the
real on-disk path, e.g. `/home/<user>/.claude/skills/goal/scripts/claude_goal.py`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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