Skip to content

Pause a Codex Goal when bb stops its turn, and add /goal commands - #6596

Merged
ymichael merged 1 commit into
mainfrom
bb/clearing-a-codex-goal-on-a-stopped-thread-starts-thr_7csui6fdj4
Oct 29, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/clearing-a-codex-goal-on-a-stopped-thread-starts-thr_7csui6fdj4

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Stopping a Codex thread interrupted its turn but left its Goal active. Clearing the Goal afterwards (the Goal card's ✕ or bb thread clear-goal) first resumes the Codex thread, and Codex 0.164 continues an active Goal as soon as a thread loads (thread/resume → idle → continue_if_idle). So a new goal turn started in the same moment as the clear, working on the Goal being cleared, while bb showed the thread as idle with no Stop button. An ordinary message after a stop did the same: Codex answered, then went back to the Goal.

Related: Codex's blocked and usageLimited Goal statuses failed bb's schemas, so those Goals were invisible, and bb had no way to resume a Goal at all (#6551).

What changed

All of the Goal behaviour lives in the Codex plugin; core only stops assuming every Goal is active.

Codex plugin (plugins/provider-codex)

  • bridge.ts: the bridge tracks each thread's Goal status from the goal events it already forwards. When bb stops a turn whose Goal is active, the bridge sends thread/goal/set {status: "paused", origin: "user"} before turn/interrupt, as Codex's own terminal client does. A paused Goal stays paused until the user resumes it.
  • bridge.ts: the bridge handles /goal resume, /goal pause and /goal clear itself instead of sending them to Codex. bb already offers /goal in the composer for Codex.
    • Resume: sets the Goal active. The goal turn Codex then starts is attached to the user's message, through the same queued request ID that /compact uses. If Codex starts no turn within 5s (it can quietly skip one), the message finishes with an empty turn.
    • Pause and clear: finish with an empty turn.
    • Rejected commands (no Goal, already active, not active) fail the message with the reason.
    • Any other /goal text, such as /goal <objective>, still goes to Codex as a prompt.
  • schemas.ts, extension-kinds.ts: accept blocked and usageLimited.
  • fake-codex-app-server.mjs: supports thread/goal/set and thread/goal/get, and starts a goal turn on resume.
  • The Codex skill doc describes the stop behaviour and the /goal commands.

Core

  • apps/server/src/routes/threads/actions.ts: the clear-goal route accepts a Goal in any status, not just an active one; a stopped thread's Goal is now paused. The 409 message is now "No Goal to clear".
  • apps/server/src/services/threads/thread-runtime-display.ts: adds getThreadTimelineGoal, which reads the thread's latest Goal.
  • ThreadGoalCard.tsx and CollapsibleActiveStackCard.tsx:
    • The card now also shows paused, blocked and usage-limited Goals ("Goal paused" and so on), dimmed, with ✕.
    • Completed and budget-limited Goals stay hidden.
  • packages/domain/src/thread-timeline-goal.ts: adds the two statuses.
  • bb thread clear-goal: the CLI description and the guide line say "the thread's Goal" instead of "the active Goal".

There is no HOST_DAEMON_PROTOCOL_VERSION bump and no Plugin SDK change.

This differs from #6551's proposal: instead of a new REST/SDK/CLI "set Goal" call, you resume with /goal resume. That's typed in the composer, or sent with bb thread tell <id> "/goal resume".

How you verified

Tests

  • New plugins/provider-codex/src/bridge/bridge.goal-controls.test.ts, 7 tests against the fake Codex app-server:
    • stop pauses an active Goal before turn/interrupt;
    • no pause when the Goal isn't active;
    • /goal resume attaches Codex's goal turn to the message;
    • /goal resume finishes the message when Codex starts no turn;
    • /goal clear clears without a Codex turn;
    • /goal resume is rejected for an active Goal;
    • other /goal text reaches Codex unchanged.
  • The four /goal tests fail with the handling switched off.
  • Server: clearing a paused Goal. App: card for a paused vs. a complete Goal.

Commands, on the rebased branch

  • pnpm exec turbo run typecheck lint --filter='...[origin/main]': 153/153 passed.
  • turbo run test for bb-plugin-provider-codex (550), @bb/cli (865, 1 skipped), @bb/templates (46) and @bb/domain (294): all pass.
  • Server public-thread-banner-actions.test.ts (13) and app components/promptbox/banner (130): all pass.

Manual, real app. Two pnpm start:worktree servers, this branch and its base (main without the change), with Codex 0.164 and gpt-6-luna. The same steps were run on both through the UI (headless browser) and the source bb CLI. File counts come from a goal that writes one numbered file per shell command.

Scenario Before After
Goal card after Stop "Goal" (active) "Goal paused"
✕ on the stopped thread New Codex turn; files 3 → 13 in 30s while bb shows idle No turn; files 4 → 4
Ordinary message after Stop Answers "4", then resumes the Goal (files 4 → 24) Answers "4"; the Goal stays paused (files 4 → 4)
/goal clear Sent to the model, which only paused the Goal Goal removed; no turn, no reply
/goal resume Not possible Goal active, Codex's turn attached to the message, files 4 → 11; Stop pauses it again
bb thread clear-goal with no Goal 409 No active Goal to clear 409 No Goal to clear

Regression checks on the branch server also passed:

  • a normal Codex turn;
  • bb thread compact;
  • stopping and then messaging a thread with no Goal;
  • /goal <objective> reaching Codex as identical text on both builds, checked in Codex's session file.

Known limits

  • Threads stopped before this change still have an active Goal, so clearing one can still race.
  • A rejected /goal command shows as a failed message and marks the thread error until the next message, like any failed message.
  • /goal pause sent while Codex is running is a steer, so it reaches the model as text.

Fixes #6551

🤖 Generated with Claude Code

AGENT GENERATED

Stopping a Codex thread left its Goal active. Clearing the Goal later
resumed the Codex thread first, and Codex continues an active Goal as
soon as the thread loads, so a new turn started on the Goal being
cleared.

The Codex bridge now pauses an active Goal before interrupting the
turn, as Codex's own client does. A paused Goal stays paused until the
user resumes it: the bridge handles "/goal resume", "/goal pause", and
"/goal clear" itself instead of sending them to Codex. Resume binds the
goal turn Codex starts to the user's message, and settles the message
with an empty turn if Codex starts none. Other "/goal" text still goes
to Codex as a prompt.

Clearing now accepts a Goal in any status, and the Goal card shows
paused, blocked, and usage-limited Goals so they can be cleared. The
Goal status schemas accept Codex's blocked and usageLimited statuses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit fa2b39c into main Oct 29, 2026
51 checks passed
@ymichael
ymichael deleted the bb/clearing-a-codex-goal-on-a-stopped-thread-starts-thr_7csui6fdj4 branch October 29, 2026 22:29
ymichael added a commit that referenced this pull request Oct 30, 2026
#6684)

## Human comments

## What was wrong

Since #6143, the GitHub PR Status plugin saves a link from each
environment to its PR and re-reads that URL on later loads. It only
looks up the branch again when the branch name changes. When a PR merged
and the thread opened a second PR from the same branch, the environment
stayed linked to the merged PR forever. For example, a thread whose
branch carried merged #6596 and then open #6613 kept showing #6596.
Before #6143 every load ran `gh pr view` on the current branch, which
prefers an open PR.

## What changed

- `plugins/github-pr-status/store.ts`: adds `isSettled(environmentId)`,
which says whether the environment's linked PR is merged or closed.
`staleAfterMs` now uses it.
- `plugins/github-pr-status/server.ts`: `prepareLoad` looks up the
branch (`url: null`) instead of reading the saved URL when the linked PR
is settled, just as it already does after a branch change. The branch
lookup prefers an open PR and otherwise returns the same settled PR, so
this takes one GitHub request per load, not two.

There are no wire, CLI or SDK changes.

Performance, measured against GitHub on the affected branch: a settled
link's reload goes from a URL read (~760 ms, 1 rate-limit point) to a
branch read (~990 ms, 3 points). Settled PRs are never polled. They
reload only when a viewer sees one over an hour old, when a CLI read
finds one more than 10 s old, on push, or after a turn that ran `gh`.
App viewers are served the cached row immediately and refreshed in the
background.

## How you verified

- A new `server.test.ts` case checks that a link to a merged PR switches
to the branch's newer open PR, with exactly one host read per load. It
fails before this change and passes after.
- `pnpm exec turbo run test typecheck lint
--filter=bb-plugin-bb--github-pr-status` passes (182 tests).
- On the real affected branch, the GitHub branch lookup returns #6613
(open) ahead of #6596 (merged).

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 14, 2026
After setting the Goal active the bridge asks Codex which turn is active
(a steer with an impossible expected id; Codex queues it behind the goal
set and names the active turn in its refusal). The message is accepted
into that Goal turn, or settles at once with an empty turn when Codex
starts none. /goal pause and clear settle on Codex's reply without a
turn. Restores #6596 coverage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 14, 2026
After setting the Goal active the bridge asks Codex which turn is active
(a steer with an impossible expected id; Codex queues it behind the goal
set and names the active turn in its refusal). The message is accepted
into that Goal turn, or settles at once with an empty turn when Codex
starts none. /goal pause and clear settle on Codex's reply without a
turn. Restores #6596 coverage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 17, 2026
After setting the Goal active the bridge asks Codex which turn is active
(a steer with an impossible expected id; Codex queues it behind the goal
set and names the active turn in its refusal). The message is accepted
into that Goal turn, or settles at once with an empty turn when Codex
starts none. /goal pause and clear settle on Codex's reply without a
turn. Restores #6596 coverage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Codex goal: blocked/usageLimited statuses are invisible and a blocked goal cannot be resumed

1 participant