Skip to content

docs(plans): design /goal, a session goal the runtime pursues for hours or days (ENG-982) - #226

Merged
lg2m merged 5 commits into
mainfrom
docs/eng-982-goal-design
Sep 30, 2026
Merged

lg2m merged 5 commits into
mainfrom
docs/eng-982-goal-design

Conversation

@lg2m

@lg2m lg2m commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Spec

ENG-982, a follow-up to #211 / ENG-978. Design only; no code.

What /goal is

You give QQ an objective, an optional check command (for example cargo test -p billing) and a budget (a deadline, a run cap, and optionally tokens and cost). The runtime then works on it by itself across runs, restarts, provider outages, waits on external things, and days, until one of these happens:

  • the check passes;
  • the budget or deadline runs out;
  • it is genuinely blocked;
  • you pause it.

Any client can see its state, spend, remaining budget and next wake time without reading the transcript.

Research (docs/design/goal-reference-survey-2026-09-28.md)

Only Codex has a real goal feature: ext/goal, /goal, and idle continuation. It has four weaknesses:

  • completion and "blocked" are prompt text only;
  • its no-progress counters live in memory and reset on restart;
  • pausing on interrupt is client behaviour;
  • the only budget is tokens.

The others each have a piece:

  • OpenCode has a durable todo list that is never shown to the model again.
  • Pi has a finishTurn continue hook, which its README warns loops forever.
  • fx has a stop hook that fails open to "allow".

Design (ADR-0049, revised in place, still Proposed)

QQ vs Codex
Who creates it A client only. The model can edit the checklist and notes, propose a status, and request a wait Codex lets the model create goals
Scope One goal per session. A run records (goal_id, revision) when it is claimed; stale claims are rejected or merged Similar; Codex has no revision on the wire
Driver A runtime goal driver queues one goal run when the session is idle, under a transactional pending_run_id guard. Every stop that leaves the goal active recovers with a fresh run from committed history and the current goal. Explicit ContinueRun rejects, and AutoContinue skips, goal-snapshot runs Similar idea
Budget Deadline and run cap are required. Every run's RunLimits is clamped to the goal's remainder when it starts, user prompts included. A shared exact-once finalization step covers every terminal path, including queued/reserved failures, recovery and panic. It charges committed spend to the referenced goal even after clear/replacement Tokens only
Completion A claim sets audit_pending. The check command runs as a GoalCheck run: it holds the session slot and workspace-wide exclusion, can be cancelled, and waits/process share the goal-clamped deadline. The client explicitly authorizes one check start or repeated exact checks for this goal; ordinary approve-once is never widened. Exit 0 at the live active claimed revision means achieved; a failure feeds its output back to the next run; 3 failures means blocked. With no check, one audit turn decides. The audit allowance is bounded Prompt-only
Stopping Durable waits (up to 24 h each) and provider backoff (1 m, doubling, up to 30 m). An auth or config failure gives paused{needs_user}. An approval held longer than 10 min gives paused{needs_user: approval}. Repeated failures or no progress give blocked. All counters are in the store, so a restart keeps them In memory
Pausing An explicit cancel pauses the goal, enforced by the runtime for every client. An interrupting prompt redirects the run and does not pause Done by the TUI
Cost when unused Zero bytes. Goal-less requests are byte-identical, checked against a golden request —

Surfaces:

  • TUI: /goal (panel), /goal <objective> (form), /goal pause|resume|clear|edit, and a status line.
  • Headless: qq run --goal … [--check CMD] stays in the foreground until the goal ends, with JSONL records and an exit status for each outcome.
  • Server: qq goal set|show|… --session drives a goal held by qq serve.

Plan (docs/plans/goals.md): G0 combines protocol/store, goal in runs, update_goal, check authorization shapes and AC4 (loop guard) in one protocol bump. G1 is dropped into G0. G2 builds the driver; G3 builds checks and owns the full checked-completion gate; G4 builds surfaces; G5 records live evidence. This replaces autonomous-core AC7–AC9. Goal recovery no longer depends on AC5 (ContinueRun). Acceptance is a scripted multi-day run on a simulated clock: 40 goal runs, 2 process kills, a 26-hour gap, a 6-hour outage, waits and interleaved prompts, reaching achieved with no call re-executed and never two runs queued.

Review before opening

Given the review load on #211, I first had an independent reviewer check the design against source. It found 12 problems, and all are fixed in this PR. Among them:

  • The check can't reuse the shell tool: its timeouts cap at 600 s (shell.rs:23) and it needs a claimed run to hold approvals. The check is now its own run kind.
  • No process sandbox exists, so that claim was removed.
  • Recovery builds a default ClaimedRun (settlement.rs:1061), so the proposed shared goal-finalization step reads the persisted run identity/accounting, including recovery and queued/reserved terminal paths.
  • Limits are fixed at insert (commands.rs:598), so they are now clamped at start.
  • AutoContinue would have double-scheduled goal runs.
  • A held approval could have used up the whole goal deadline.

The list is in the ledger.

Also changed

  • ADR-0048: explicit ContinueRun rejects and AutoContinue skips runs that have a goal snapshot; recovery uses fresh goal runs without weakening latest-prompt admission.
  • autonomous-core.md: AC7–AC9 now point to goals.md; ContinueRun no longer admits completed runs; the goal counters are gone from the reset-scope table.
  • Indexes: docs/README.md, plans/README.md, progress/README.md, adr/README.md and the root.md row for 0049.

Verification (latest correction c4f42c3)

  • Independent focused review: Approve for this proposed docs-only design, including the paused-edit audit invalidation and neutral-control retagging follow-up.
  • cargo test -p qq docs_truth: 5 passed in the isolated worktree.
  • cargo fmt --all -- --check: passed.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: passed.
  • Initial unrestricted cargo test --workspace: five existing deadline-test failures. All 12 deadline tests passed with --test-threads=1; full cargo test --workspace -- --test-threads=4 then passed. The initial failures are disclosed, not waived or fixed by unrelated Rust changes.
  • cargo build --workspace: passed.
  • Entire PR plus fixes: 13 Markdown files, 174 relative links, balanced fences/current ledger statuses and git diff --check: passed.
  • Minimal-provider/bench gates not applicable: no Rust, dependencies, wire/schema or hot-path changes.

Latest Codex findings

All 12 findings on fb1e510 were valid and are addressed in c4f42c3: scoped check consent, hard deadlines, stale status/wait/result fencing, cancellation ownership/early-resume rejection, prompt final-slot handoff, fresh recovery, exact goal CAS, explicit terminal lifecycle, G2/G3 gate ordering, valid ledger states, prompt-priority queued checks, and archived accounting. Each is mapped to future G0/G2/G3 acceptance; this PR remains design-only. The ledger and decisions-needed row 11 record the rationale.

Decisions needed

  1. Accept, amend or reject the revised ADR-0049.
  2. The remaining open questions in goals.md: the 24 h default deadline and a separate goal-run pool.
  3. Lead acceptance of the proposed design correction in decisions-needed.md row 11 (fresh recovery, explicit check scopes, achieved replacement/stopped-goal resume).

…rs or days (ADR-0049 revised)

Survey how Codex, OpenCode, Pi and fx pursue one objective over time, and
design QQ's version without copying any of them:
- a session goal that only a client creates;
- a runtime goal driver that queues one goal run at a time;
- budgets enforced through RunLimits clamped at start;
- completion checked by a client-set GoalCheck run;
- durable waits and backoff;
- pause-on-cancel as a runtime rule;
- /goal, qq run --goal and qq goal.

ADR-0049 is revised in place, still Proposed. The loop guard is unchanged.
Autonomous-core AC7-AC9 move to the new goals plan as G0-G3. ADR-0048's
AutoContinue skips goal runs. No code change.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ccc8b47abc

ℹ️ 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".

Comment thread docs/plans/goals.md Resolved
Comment thread docs/plans/goals.md Resolved
Comment thread docs/plans/goals.md Resolved
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T05:33:12.134832Z fb1e510 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

- Check runs take a workspace-wide exclusion.
- Checks are authorized by an exact-command held approval, never by
  caller flags.
- Pause, replace and clear cancel queued goal work and ask running work
  to cancel.
- update_goal is dispatched serially.
- The approval wait is clamped to the deadline and its pause takes
  precedence.
- Stale check results are ignored, and an interrupted check pauses
  instead of re-running.
- Goal history rows, a final-run wrap-up, and runs with no committed
  turn don't count toward the cap.
- A user prompt pre-empts an unclaimed goal run.
- qq run --goal returns on any non-active state.
- Managed ceilings can only be lowered.
- G0 and G1 are merged into one goal PR with AC4.
- Stale AC7-AC9 ledger rows and ADR section references are fixed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb1e510c91

ℹ️ 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".

Comment thread docs/plans/goals.md Resolved
Comment thread docs/plans/progress/autonomous-core.md Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

ENG-982 / PR #226: address all 12 latest Codex findings with explicit once/for-goal check consent, bounded check deadlines, exact goal CAS, stale outcome fencing, guarded cancellation/resume, historical spend, fresh goal recovery, user-priority checks and final-slot handoff. Synchronize slice gates, valid ledger statuses and protocol/dependency planning.

Design only; ADR-0049 stays Proposed. Independent design review approved. Formatting, workspace Clippy, docs-truth, workspace build and full workspace tests with --test-threads=4 passed. Initial unrestricted tests hit five timing-sensitive deadline failures; all 12 deadline tests passed serially. No runtime or wire changes.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@lg2m
lg2m merged commit 5fce347 into main Sep 30, 2026
4 checks passed
@lg2m
lg2m deleted the docs/eng-982-goal-design branch September 30, 2026 20:40
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