[codex] fix goal control state and turn provenance#1201
Draft
chovy-ai wants to merge 1 commit into
Draft
Conversation
chovy-ai
force-pushed
the
codex/goal-control-root-fix
branch
from
July 16, 2026 03:41
70077fe to
58a263d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Calling
/goaland immediately clearing it could leave the first response permanently thinking, keep the session running, and leave/goal clearstuck at planning the next step.The user-visible failure came from modeling Goal control as a specially shaped Turn. The old path could allocate a local Turn ID before the provider had started any Turn. If the Goal was cleared before provider activation, that phantom Turn never received a matching terminal lifecycle event.
Root cause
Goal is session-owned, long-running state that can produce zero or more provider Turns. It is not itself a Turn. The previous implementation mixed these identities and did not have durable operation/revision/provenance fences for delayed provider observations, retries, restarts, or clear-and-recreate races.
Fix
This PR implements the three-stage Goal/Turn design documented in
docs/specs/2026-07-15-agent-goal-control-design.md:main's provider-native root/child session lifecycle: provider terminals settle canonical root Turns transactionally without duplicate terminal events;User impact
/goal setfollowed immediately by/goal clearnow converges without a phantom Turn, permanent thinking state, or session-running leak. Delayed provider work cannot inherit a newer Goal identity, resurrect a cleared Goal, or cancel an unrelated user Turn.Validation
check:full: 18 tasks passed;git diff --check: passed.Deferred non-blocking hardening
Summary by cubic
Fixes phantom Turns and stuck “thinking” by making Goal a session-level entity and separating Goal control from Turn lifecycle. Adds durable Goal provenance and session audit events so
/goal setfollowed by/goal clearconverges without leaks or orphaned Turns.New Features
sendWorkspaceAgentSessionInputmay return{ kind: "goalControl" }with noturn/turnId.getWorkspaceAgentSessionGoalandreconcileWorkspaceAgentSessionGoaltransport methods.originand optional Goal provenance (sourceGoalOperationId,sourceGoalRevision,sourceGoalRepairEpoch); reducers preserve provenance across snapshots in@tutti-os/agent-activity-core, daemon/runtime, andstore-sqlite.session_auditevents for turnless Goal history; inline parser and report coalescer handle audits; store enforces that onlysession_auditmessages may be turnless.origin, and quiesce Goal Turns with bounded retries and grace windows.GoalCapabilitiesandApplyGoal(...); controller exposes goal capabilities and reconcile helpers.resultKindand track goal-only sends in diagnostics.initialTurnExpectedto send goal controls without expecting a Turn.originon Turns.Migration
sendWorkspaceAgentSessionInputreturningkind: "goalControl"; do not assume a Turn exists after Goal commands; trackresultKindin diagnostics.initialTurnExpected: false.originon all Turns and propagate it in models, reducers, events, and UI.session_audit; all other messages must reference a Turn.getWorkspaceAgentSessionGoal,reconcileWorkspaceAgentSessionGoal) instead of routing through the prompt pipeline; provider adapters should implementGoalCapabilities/ApplyGoaland durable provenance binding.Written for commit 58a263d. Summary will update on new commits.