🤖 feat(goals): long-horizon auto-continuation with budgets#3235
🤖 feat(goals): long-horizon auto-continuation with budgets#3235
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
/coder-agents-review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa89082972
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
First-pass review (Netero only). This is a mechanical scan; the full review panel has not yet reviewed this PR.
Netero raised 6 findings. 5 were dropped during verification: 3 cited an em-dash convention that does not exist in mux, and 2 cited a Storybook-only testing convention that mux does not follow (88 standalone .test.tsx files exist in src/browser). 1 P2 survives.
The surviving finding is a permanently empty UI section that ships to users with no path to displaying real data. The panel will review after this is addressed.
🤖 This review was automatically generated with Coder Agents.
|
@codex review P1 issues addressed in
Please take another look. |
|
/coder-agents-review |
There was a problem hiding this comment.
Round 2 is blocked. The open finding from round 1 has no author response and the code is unchanged.
DEREM-6 (P2, GoalTab.tsx:374-380): "Recent continuations" section is a permanent placeholder with no data source. No continuations prop, no schema field, no data pipeline. The author's e488c4ebd commit addressed the two Codex P1 findings but did not address or acknowledge DEREM-6.
Further review is blocked until the author responds to DEREM-6 (fix, acknowledge, or contest) or pushes a commit addressing it. The full review panel will run once this is resolved.
🤖 This review was automatically generated with Coder Agents.
|
Codex Review: Didn't find any major issues. Keep it up! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@coder-agents-review DEREM-6 addressed in the latest force-push: deleted the empty "Recent continuations" section from The full review panel can run now. |
|
/coder-agents-review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a26bcdd0a4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Two new P1s addressed in
Regression tests added for both. |
|
/coder-agents-review |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
Second Netero pass (round 3). The full review panel has not yet reviewed this PR.
DEREM-6 (placeholder UI) verified fixed. 4 new findings: 1 P2, 3 P3. The P2 is a test reliability issue (raw setTimeout for coordination, violating mux AGENTS.md). The P3s are dead code, missing test coverage, and a silently divergent helper. The panel will review after the P2 is addressed.
🤖 This review was automatically generated with Coder Agents.
|
@codex review Two more rounds addressed in |
|
/coder-agents-review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99168af5e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed setGoal router validation: getGoal, setGoal, and clearGoal now all verify the workspace exists before calling WorkspaceGoalService, and unknown IDs return safe null/false/invalid_transition results without touching goal files. Updated router coverage to include setGoal. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 762aa9dbe2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed queued mid-stream goal conflicts: deferred goal mutations now persist the original |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 172a4f101d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed both optimistic-concurrency retry comments:
Added focused regression coverage and reran static-check. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a419a730d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed limit-hit unpriced kickoff validation: backend setGoal now rejects budgeted goals that would become either active or budget_limited when the kickoff model has no billable pricing, preventing zero-budget/default-budget limit-hit goals from being created and then stranding on a rejected synthetic wrap-up. Added regression coverage for zero-budget + unpriced kickoff model. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e1778dd3e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed queued mid-stream unpriced budgeted goals: the streaming/projection branch now runs the same kickoff-model pricing check before storing a pending mutation, returning the typed unpriced-model error immediately instead of projecting success and dropping at stream end. Added regression coverage. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8effa41b5f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed non-conflict goal error surfacing: slash goal mutations now show the backend |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f9693c862
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed typed goal error surfacing for the Goal tab and command palette: both now preserve the generic conflict message only for |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22701eb1c8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed palette goal failures: command-palette goal mutations no longer throw on typed backend errors. They now surface the backend message through |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3fc92c117a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed skipped continuation re-requesting: transient |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4ed8528f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed one-shot unpriced continuation capture: WorkspaceGoalService now validates continuation send options for budgeted goals and falls back to priced kickoff/current options when the just-finished stream options are unpriced. Added regression coverage for budgeted goals created during an unpriced one-shot stream. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e7519d4cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed slash goal pricing for one-shot streams: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27ec856c84
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed selected-model pricing in palette and GoalTab: both budget guards now validate the selected continuation/send model rather than stale transcript/one-shot model state, aligning with backend continuation fallback behavior. Focused tests and static-check pass locally. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1207e2c810
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Addressed startup recovery ordering: pending compaction follow-ups are now dispatched before goal continuations are re-armed, preventing goal continuations from racing ahead of saved compaction follow-up recovery. Startup/compaction/goal tests and static-check pass locally. |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Adds a workspace-scoped, persistent **Goal** primitive that the agent
auto-continues against an explicit dollar budget after each turn ends.
Inspired by OpenAI Codex's `/goal` but adapted to Mux's primitives.
- `/goal "<objective>" [--budget $X[.YY]] [--turn-cap N]` slash command
plus parity in the command palette (set / pause / resume / complete /
clear / edit budget). Workspaces hold at most one active goal.
- New `IdleDispatcher` that serializes per-workspace dispatches and is
shared with `HeartbeatService`; goals get priority 100 (suppresses
background heartbeats while a goal is active).
- Cost / budget / turn / elapsed accounting persisted to
`~/.mux/sessions/<workspaceId>/goal.json` with atomic writes and an
optimistic-concurrency `expectedGoalId` on `setGoal`.
- Auto-continuation: at every stream-end, if the goal is `Active` and
the workspace is idle, a synthetic `<untrusted_objective>`-wrapped
user message is injected to drive the next turn (60s cooldown,
serialized globally).
- BudgetLimited wrap-up: once `costCents >= budgetCents`, exactly one
graceful "stop and summarize" continuation fires before further
dispatches are suppressed.
- Auto-pause hooks: any non-synthetic user message pauses an active
goal before streaming; partial-message recovery on startup arms a
user-acknowledgment gate that blocks continuations until the user
posts again.
- Sub-agent task costs are attributed up to the parent's active goal
on task completion (children do not inherit the goal).
- Forked workspaces inherit a snapshot of the parent goal but reset
accounting and default to `Paused` to avoid runaway loops.
- Two model-facing tools: `get_goal` (read-only) and
`complete_goal(summary)` — conditionally injected when the GOALS
experiment is on, the workspace has an active/budget-limited goal,
and the agent is exec-like with editing capabilities.
- UI: left-sidebar `Target` pill on every workspace with a goal,
conditional right-sidebar Goal tab (status + accounting +
Pause/Resume/Mark complete/Clear), a settings section under
Experiments, and custom transcript cards for `get_goal` /
`complete_goal` that mirror the GoalTab styling.
- Live snapshot fan-out via `WorkspaceService.emit("activity")` so
pill + tab refresh without a reload.
- Telemetry: lifecycle events (`goal_created/replaced/cleared/paused/
resumed/completed/budget_limited/budget_changed/continuation_fired/
wrapup_fired/crash_gate_set`) emitted through `AnalyticsService`.
Gated by `EXPERIMENT_IDS.GOALS` (off by default, user-overridable).
- Dollars (cents internally), not tokens, because Mux supports many
models with different token economics. `turnCap` is a secondary
guardrail. Wall-clock time is display-only.
- Compaction streams are excluded from goal accounting; failed /
aborted streams are counted (provider cost is still paid).
- Synthetic continuation prompts XML-escape the objective inside an
`<untrusted_objective>` block and explicitly tell the model to
treat the objective as data, not instructions.
---
_Generated with `mux` • Model: `anthropic:claude-opus-4-7` • Thinking: `max` • Cost: `$768.23`_
<!-- mux-attribution: model=anthropic:claude-opus-4-7 thinking=max costs=768.23 -->
|
@codex review Addressed selected-model budget validation across Goal UI entry points. Palette and GoalTab now validate the selected continuation/send model (with provider config) rather than stale transcript/one-shot model state, matching backend continuation fallback behavior. Focused palette/GoalTab tests and static-check pass locally. |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Adds a workspace-scoped, persistent Goal primitive that the agent auto-continues against an explicit dollar budget after each turn ends. Inspired by OpenAI Codex's
/goalbut adapted to Mux's primitives: synthetic visible user messages instead of adeveloperrole, dollar budgets instead of tokens (we already track normalized cost viasessionUsageService), a sharedIdleDispatcherconsolidating heartbeats and goal continuations, and conditionally-injected model tools.Gated end-to-end by
EXPERIMENT_IDS.GOALS(off by default, user-overridable). Off the experiment, the only externally observable change is the new ESM module graph; runtime behavior is identical tomain.Background
Long-horizon agent runs on Mux today require the user to nudge the agent ("continue", "what next") at every stream-end. Codex solved this with
/goal, but its model is token-budget + developer-role. Mux supports many providers with wildly different token economics, has no developer role, and already has an idle scheduler shared by heartbeats — so the design adapts the spec rather than copying it. The accompanying RFC (separategoals-planningbranch — not part of this PR to keep history clean) covers the full architecture, state diagram, accounting boundaries, and edge cases.Implementation
Backend
WorkspaceGoalService(new) owns goal lifecycle. Persists each workspace's goal at~/.mux/sessions/<id>/goal.jsonviawriteFileAtomic+ per-workspace file locks. Optimistic-concurrency onsetGoalvia an optionalexpectedGoalIdreturns a typedResult<GoalRecordV1, GoalSetError>so the frontend can retry without throwing.IdleDispatcher(new, also extracted fromHeartbeatService) serializes per-workspace dispatches with priority-ordered consumers — goals = 100, heartbeats = 50 — so an active goal naturally suppresses heartbeats. Global concurrency cap of 1.Active→Paused(manual user message or/goal pause),Active→BudgetLimited(cost ≥ budget),BudgetLimited→ exactly one wrap-up continuation → done,*→Complete(modelcomplete_goalor/goal complete). Setting an identical objective is idempotent (preservesgoalId+ accounting).agentSessionstream-end, if the goal isActiveand the workspace is idle, anIdleDispatchercandidate fires a synthetic user message wrapping the objective in<untrusted_objective>. 60s cooldown, gated byrequireUserAcknowledgmentSinceMsif a partial assistant message was recovered on startup.taskcompletion. Children do not inherit goals (avoids recursive budget exhaustion).Paused.get_goal()andcomplete_goal(summary)are conditionally registered when GOALS is on, the workspace has an active/budget-limited goal, and the agent has editing capabilities.create_goalwas deliberately omitted — goals must be user-initiated.Frontend
Target-icon pill on workspaces with a goal (live status, e.g.Target $0.04 / $1.00).get_goalandcomplete_goal(replacing the generic▶ tool_namerow), styled to match the GoalTab./goal "<obj>",/goal pause,/goal resume,/goal complete,/goal clear,/goal budget. All have command-palette equivalents.WorkspaceGoalService.pushSnapshotinvokes a callback wired incoreServicestoworkspaceService.emit("activity"), so the pill + tab refresh without a reload.Telemetry
AnalyticsService.recordGoalLifecycleEventemits a closed set of events:goal_created/replaced/cleared/paused/resumed/completed/budget_limited/budget_changed/continuation_fired/wrapup_fired/crash_gate_set. All carry buckets, never raw text.Validation
make static-checkgreen (typecheck + ESLint + Prettier + docs link checking)WorkspaceGoalService,IdleDispatcher,agentSession.goalAutoPause,goal.test(tools),GoalTab,goalToolUtils, slash-command parser, command palette, and the dispatcher registrydev-server-sandbox: kicked off two goals (one auto-completing, one budget-limited), confirmed the synthetic continuation fires within ~180ms ofsetGoal, the cost accumulator + budget gating advance correctly, and Pause/Resume/Complete/Clear all round-trip through the UIRisks
Medium. The dispatcher serialization, accounting accumulator, and stream-end hook all touch hot paths shared with heartbeats and sub-agents. Mitigations:
EXPERIMENT_IDS.GOALSgates every runtime branch — off by defaultIdleDispatcherwas extracted as a pure refactor in the first wave (no behavior change toHeartbeatService) and covered by 28 dedicated tests before goal logic was layered onworkspaceFileLocks+writeFileAtomic; corruptedgoal.jsonis treated as no goal rather than crashing the workspacegetGoalContinuationRuntimeStatereportingisInitializingindefinitely)Pains
The biggest sink was discovering, mid-dogfood, that the auto-continuation loop never fired because
WorkspaceService.getGoalContinuationRuntimeStatereturnedisInitializing: initState != nullinstead ofinitState?.status === "running".InitStateManagerkeeps the persisted status forever after init succeeds, so the eligibility check kept deferring withreason: "initializing". Existing tests stubbed the bridge, so the bug went undetected. Now covered by an integration test wiring the realWorkspaceServicethrough the real dispatcher.A separate snag:
coreServices.ts(used bymux server/ dev-server-sandbox) was constructing the goal service but never callingregisterGoalContinuationConsumer. Now wired in bothcoreServicesandserviceContainer.