fix: preserve task brief on first chat message (#3615) (#3632)

This commit is contained in:
Carlos Florêncio
2026-09-13 12:06:50 +01:00
committed by GitHub
parent 2c4058c305
commit 31a48a6428
35 changed files with 3244 additions and 157 deletions
+171 -4
View File
@@ -32,12 +32,179 @@ signals, and task-scoped scheduling contracts.
[Office system](../office).
- Presentation-only behavior belongs to the [UI specifications](../ui).
## Specification map
### Requirements
- [Initial task brief](requirements/initial-task-brief.md)
- [Task completion, conversation follow-ups, and workspace access](requirements/task-completion.md)
- [Agent-Generated Task Titles](requirements/agent-generated-titles.md)
- [Additional Session Workspace Reuse](requirements/additional-session-workspace-reuse.md)
- [Task Archive Confirmation](requirements/archive-confirmation.md)
- [Task removal navigation](requirements/removal-navigation.md)
- [Attach Workspace Sources](requirements/attach-workspace-sources.md)
- [Task Autopilot Mode](requirements/autopilot-mode.md)
- [Blocked Task Escalation](requirements/blocked-task-escalation.md)
- [Command-panel archived task results](requirements/command-panel-archived-task-results.md)
- [Active clarification lifecycle scenarios](requirements/clarification-active-lifecycle-scenarios.md)
- [Active clarification lifecycle](requirements/clarification-active-lifecycle.md)
- [Clarification response reliability](requirements/clarification-response-reliability.md)
- [Task Documents](requirements/documents.md)
- [Detached Workspace Continuity](requirements/detached-workspace-continuity.md)
- [Task plan append-mode write](requirements/plan-write-append-mode.md)
- [Task Execution Stages](requirements/execution-stages.md)
- [External task ID idempotency boundaries](requirements/external-id-idempotency-boundaries.md)
- [External task ID idempotency scenarios](requirements/external-id-idempotency-scenarios.md)
- [External task ID idempotency](requirements/external-id-idempotency.md)
- [Interrupted Task Indicator](requirements/interrupted-task-indicator.md)
- [Kanban task cache preserves executor fields across merges](requirements/kanban-task-executor-cache-staleness.md)
- [Task Labels](requirements/labels.md)
- [Link Existing Task to External References](requirements/link-existing-task-github-issue.md)
- [MCP-Created Task Agent Profile Default](requirements/mcp-task-agent-profile-default.md)
- [MCP Tool Name Stability](requirements/mcp-tool-name-stability.md)
- [MCP workspace modes](requirements/mcp-workspace-mode.md)
- [Missing task route recovery](requirements/missing-task-route-recovery.md)
- [Task model unification](requirements/model-unification.md)
- [Multi-branch tasks](requirements/multi-branch.md)
- [Parent-Child Message Interrupt](requirements/parent-child-message-interrupt.md)
- [Parent-Child Task Stop](requirements/parent-child-task-stop.md)
- [Passthrough Queued Prompt Dispatch](requirements/passthrough-queued-prompt-dispatch.md)
- [Task plan content size limit](requirements/plan-content-size-limit.md)
- [Task Plan Comments](requirements/plan-comments.md)
- [Task plan write consistency](requirements/plan-write-consistency.md)
- [Passthrough Initial Prompt Turn Boundary](requirements/passthrough-initial-prompt-turn-boundary.md)
- [Prevent Agent Auto-Start On Open](requirements/prevent-agent-autostart-on-open.md)
- [Prompt attachments](requirements/prompt-attachments.md)
- [Saved Prompt Delivery](requirements/saved-prompt-delivery.md)
- [Quick Chat Sessions, Persistence, and Expiration](requirements/quick-chat-expiration.md)
- [Quick Chat Agent Titles](requirements/quick-chat-agent-titles.md)
- [Quick Chat Repository Context](requirements/quick-chat-repository-context.md)
- [Remote Contribution Tasks](requirements/remote-contribution-tasks.md)
- [Rich task title previews](requirements/rich-task-title-previews.md)
- [Queued run scheduling](requirements/run-scheduling.md)
- [Resume prompt queue](requirements/resume-prompt-queue.md)
- [Task Runtime Cleanup](requirements/runtime-cleanup.md)
- [Task Terminal Persistence](requirements/task-terminal-persistence.md)
- [Runtime Task-State Publication Order](requirements/runtime-state-publication-order.md)
- [Session Delete Preserves Task Workspaces](requirements/session-delete-resource-cleanup.md)
- [Sidebar Task Editing](requirements/sidebar-task-edit.md)
- [Task Actions Menu on Preview and Detail Surfaces](requirements/task-actions-menu.md)
- [Task menu grouping](requirements/task-menu-grouping.md)
- [Task Actions Menu In-Flight and Concurrency](requirements/task-actions-menu-concurrency.md)
- [Task Actions Menu Action Outcomes](requirements/task-actions-menu-outcomes.md)
- [Subtasks as Workflow Checklist](requirements/subtask-checklist.md)
- [Subtask Completion Trigger](requirements/subtask-completion-trigger.md)
- [Subtask detachment](requirements/subtask-detachment.md)
- [Subtask re-parenting by drag and drop](requirements/subtask-reparenting-drag-drop.md)
- [Task Subtree Controls](requirements/subtree-controls.md)
- [Create Task Escape Dismissal](requirements/task-create-escape-dismissal.md)
- [Task Create Agent Compatibility Recovery](requirements/task-create-agent-executor-compatibility.md)
- [Task Create Executor Default](requirements/task-create-executor-default.md)
- [Task Create Launch Preview](requirements/task-create-launch-preview.md)
- [Task Create Workflow Memory](requirements/task-create-workflow-memory.md)
- [Task-create advanced settings disclosure](requirements/task-dependencies-create-dialog-advanced-settings.md)
- [Task-create dependency selector refinement](requirements/task-dependencies-create-dialog-dependency-selector.md)
- [Edit task dependencies](requirements/task-dependency-detail-editing.md)
- [Task Dependencies and Auto-Start Chains](requirements/task-dependencies.md)
- [Session Launch Repository Resolution](requirements/launch-repository-resolution.md)
- [Task Launch Failure Recovery](requirements/task-launch-failure-recovery.md)
- [Worktree metadata recovery](requirements/worktree-metadata-recovery.md)
- [Task priority visibility](requirements/task-priority-visibility.md)
- [Threads task actions](requirements/threads-task-actions.md)
- [Task Title Length Limit](requirements/title-length-limit.md)
- [User Question Turn Boundary](requirements/user-question-turn-boundary.md)
- [WIP Limits and Visible Overflow Queues](requirements/wip-limit-pull-system.md)
- [Tasks Without Repositories](requirements/without-repositories.md)
- [Workflow completion-signal payload delivery](requirements/workflow-completion-signal-payload-delivery.md)
- [Cancelled Turn Completion](requirements/workflow-cancelled-turn-completion.md)
- [Workflow Cycle Guardrails](requirements/workflow-cycle-guardrails.md)
- [Workflow Duplication](requirements/workflow-duplication.md)
- [Explicit Workflow-Step Completion Signal](requirements/workflow-explicit-completion-signal.md)
- [Workflow Profile Session Lifecycle and Recipients](requirements/workflow-profile-session-lifecycle.md)
- [Agent decision recording](requirements/workflow-quorum-decision-recording-agent-surface.md)
- [Quorum ordering and concurrency](requirements/workflow-quorum-decision-recording-concurrency.md)
- [Quorum diagnostics](requirements/workflow-quorum-decision-recording-diagnostics.md)
- [Quorum participant slate](requirements/workflow-quorum-decision-recording-participant-slate.md)
- [Decision-triggered quorum re-evaluation](requirements/workflow-quorum-decision-recording-reevaluation.md)
- [Quorum regression behavior](requirements/workflow-quorum-decision-recording-regression.md)
- [Quorum step binding and thresholds](requirements/workflow-quorum-decision-recording-step-binding.md)
- [Quorum verdict vocabulary](requirements/workflow-quorum-decision-recording-verdict-vocabulary.md)
- [Workflow quorum decision recording](requirements/workflow-quorum-decision-recording.md)
- [Conditional Workflow Session Settings](requirements/workflow-session-settings.md)
- [Workflow Settings Autosave](requirements/workflow-settings-autosave.md)
- [Workflow Step Agent Start Ownership](requirements/workflow-step-agent-start-ownership.md)
- [Workflow Sync — Per-User Workspace Authorization](requirements/workflow-sync-workspace-authz.md)
- [Workflow task-step transition ledger scenarios](requirements/workflow-task-step-transition-ledger-scenarios.md)
- [Workflow task-step transition ledger](requirements/workflow-task-step-transition-ledger.md)
- [Human Assignee and Actor Attribution](requirements/human-assignee.md)
### System design
- [Initial task brief](system-design/initial-task-brief.md)
- [Task completion, conversation follow-ups, and workspace access](system-design/task-completion.md)
- [Additional Session Workspace Reuse](system-design/additional-session-workspace-reuse.md)
- [Environment-Owned Git Status](system-design/environment-owned-git-status.md)
- [Attach Workspace Sources](system-design/attach-workspace-sources.md)
- [Command-panel archived task results](system-design/command-panel-archived-task-results.md)
- [Detached Workspace Continuity](system-design/detached-workspace-continuity.md)
- [Quick Chat Agent Titles](system-design/quick-chat-agent-titles.md)
- [Quick Chat Session Resumption](system-design/quick-chat-session-resumption.md)
- [Active clarification lifecycle](system-design/clarification-active-lifecycle.md)
- [Clarification response reliability](system-design/clarification-response-reliability.md)
- [External task ID idempotency operations](system-design/external-id-idempotency-operations.md)
- [External task ID idempotency](system-design/external-id-idempotency.md)
- [Task model unification](system-design/model-unification.md)
- [MCP Tool Name Stability](system-design/mcp-tool-name-stability.md)
- [MCP workspace modes](system-design/mcp-workspace-mode.md)
- [Remote Contribution Tasks](system-design/remote-contribution-tasks.md)
- [Passthrough Queued Prompt Dispatch](system-design/passthrough-queued-prompt-dispatch.md)
- [Saved Prompt Delivery](system-design/saved-prompt-delivery.md)
- [Passthrough Initial Prompt Turn Boundary](system-design/passthrough-initial-prompt-turn-boundary.md)
- [Prompt attachments](system-design/prompt-attachments.md)
- [Task Actions Menu on Preview and Detail Surfaces](system-design/task-actions-menu.md)
- [Task menu grouping](system-design/task-menu-grouping.md)
- [Task Archive Confirmation](system-design/archive-confirmation.md)
- [Task removal navigation](system-design/removal-navigation.md)
- [Task plan content size limit](system-design/plan-content-size-limit.md)
- [Task Plan Comments](system-design/plan-comments.md)
- [Task plan write consistency](system-design/plan-write-consistency.md)
- [Task plan write lifecycle](system-design/plan-write-lifecycle.md)
- [Task plan append-mode write](system-design/plan-write-append-mode.md)
- [Task plan append-mode agent text](system-design/plan-write-append-mode-agent-text.md)
- [Task Runtime Cleanup](system-design/runtime-cleanup.md)
- [Task Cleanup Preparation](system-design/runtime-cleanup-preparation.md)
- [Task Terminal Persistence](system-design/task-terminal-persistence.md)
- [Runtime Task-State Publication Order](system-design/runtime-state-publication-order.md)
- [Queued Run Scheduling](system-design/run-scheduling.md)
- [Resume prompt queue](system-design/resume-prompt-queue.md)
- [Session Delete Preserves Task Workspaces](system-design/session-delete-resource-cleanup.md)
- [Task Dependencies and Auto-Start Chains](system-design/task-dependencies.md)
- [Edit task dependencies](system-design/task-dependency-detail-editing.md)
- [Session Launch Repository Resolution](system-design/launch-repository-resolution.md)
- [Task Launch Failure Recovery](system-design/task-launch-failure-recovery.md)
- [Worktree metadata recovery](system-design/worktree-metadata-recovery.md)
- [Task Create Launch Preview](system-design/task-create-launch-preview.md)
- [Task priority visibility](system-design/task-priority-visibility.md)
- [Threads task actions](system-design/threads-task-actions.md)
- [WIP Limits and Visible Overflow Queues](system-design/wip-limit-pull-system.md)
- [Workflow completion-signal payload delivery](system-design/workflow-completion-signal-payload-delivery.md)
- [Signal-Gated Manual Move Visibility](system-design/workflow-signal-gated-manual-move-visibility.md)
- [Workflow quorum decision recording](system-design/workflow-quorum-decision-recording.md)
- [Workflow Step Agent Start Ownership](system-design/workflow-step-agent-start-ownership.md)
- [Workflow Step Fixed-Profile Routing](system-design/workflow-step-fixed-profile-routing.md)
- [Workflow Profile Session Lifecycle and Recipients](system-design/workflow-profile-session-lifecycle.md)
- [Workflow task-step transition ledger](system-design/workflow-task-step-transition-ledger.md)
- [Human Assignee](system-design/human-assignee.md)
- [Task Create Agent Compatibility Recovery](system-design/task-create-agent-executor-compatibility.md)
## Migration record
Migration remains in progress. Use the catalog command to find the current
requirement and system-design documents for this system. Other migrated files
still need the same extraction before this system can return to a complete
migration state.
Migration remains in progress. Files that retain migration wrappers still need
extraction before this system can return to a complete migration state.
## Related systems
@@ -0,0 +1,62 @@
---
status: active
system: tasks
created: 2026-09-12
updated: 2026-09-12
owners:
- kandev
---
# Initial task brief requirements
## Overview
A message sent before an ordinary task session starts must preserve the task
brief. The message supplements that brief unless its instructions explicitly
replace the objective. Both texts remain available to the user and agent.
The task system owns first-message admission and delivery. The existing UI
transcript contract owns history windows and the synthetic description row.
## Terms
- **Brief:** The task description at first-message acceptance.
- **Eligible session:** A never-prompted, CREATED ordinary task session.
Office, ephemeral Quick Chat, and configuration sessions are excluded.
- **Additional instruction:** A direct user message that starts an eligible session.
## Requirements
### REQ-TASKS-INITIAL-TASK-BRIEF-001: Initial task brief preservation
**Intent:** Preparatory instructions retain the objective, scope, and constraints
that the task already contains.
#### Acceptance criteria
- **AC-TASKS-INITIAL-TASK-BRIEF-001.1:** When an additional instruction starts an eligible session, its first agent prompt shall include the nonempty brief and instruction.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.2:** The first stored user prompt shall retain both texts in order: brief, then additional instruction. Reloading shall preserve both texts.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.3:** When a later message arrives, the system shall not automatically repeat the brief. Message deletion or backend restart shall not restore eligibility.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.4:** When the instruction equals the brief after outer whitespace removal, the system shall include that text once. An empty brief adds nothing.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.5:** Concurrent first-message submissions shall not both add the brief. Retrying an accepted message identity shall return its original saved content without another dispatch.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.6:** When first-message persistence fails, the system shall not dispatch that message. A later retry shall remain eligible if no competing prompt won admission.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.7:** Desktop and phone Chat shall show the preserved first prompt once, through existing history navigation, including after reload.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.8:** Structured and passthrough sessions shall preserve the same visible brief and instruction. Existing attachment and saved-prompt delivery rules shall remain applicable.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.9:** Office, Quick Chat, configuration, and previously prompted sessions shall retain their existing context rules. Automatic workflow entry shall retain its fallback rules.
- **AC-TASKS-INITIAL-TASK-BRIEF-001.10:** An explicit replacement instruction shall remain after the brief, preserving its precedence. The system shall not infer replacement from preparatory wording.
## Exclusions
- Rewriting old conversations or recovering previously omitted prompts automatically.
- Changing task descriptions when users send messages.
- New replacement controls or natural-language intent classification.
- Changes to workflow move instructions, context reset, or automatic entry policy.
- Treating display-only launch previews as authorized agent input.
## System design
[Initial task brief](../system-design/initial-task-brief.md)
## Implementation plans
[Initial task brief fix package](../../../plans/initial-task-brief/plan.md)
@@ -0,0 +1,126 @@
---
status: current
system: tasks
requirements:
- REQ-TASKS-INITIAL-TASK-BRIEF-001
created: 2026-09-12
updated: 2026-09-12
owners:
- kandev
---
# Initial task brief system design
## Boundary and mapping
The task service owns accepted prompt content. The repository selects initial
content inside its existing session write transaction. The handler dispatches
the committed result. This extends the existing first-prompt boundary.
| Requirement | Design sections |
| --- | --- |
| `REQ-TASKS-INITIAL-TASK-BRIEF-001` | Admission, Composition and delivery, Transcript, Failure and compatibility |
## Admission
`MessageHandlers.wsAddMessage` already resolves session changes after
`ProcessOnTurnStart`. Eligibility belongs to that resolved session, including
a CREATED source redirected to a fresh workflow session. The service verifies
task/session ownership and excludes Office, ephemeral, and configuration contexts.
Use a server-only admission option on `CreateMessageRequest`. It carries a
prepared initial-content candidate and its corresponding trusted prompt context.
This option is not a public request field and is never accepted from client metadata.
Existing callers without the option keep their current behavior.
Select between ordinary and initial candidates inside the existing repository
user-message transaction, before `assignUserMessageBoundary` allocates an ordinal.
Read `task_session_prompt_seq` with the same transaction and session write lock.
An existing row, including `last_seq = 0`, means that another prompt owns the
first boundary. Do not use CREATED state, transcript length, title ownership,
or the eventual ordinal alone as proof of eligibility.
Extend the shared boundary used by ordinary, idempotent, plan-comment, and
queued plan-comment message writes. Keep candidate selection, message insertion,
ordinal allocation, comment consumption, and queue insertion atomic where those
operations are already atomic. Preserve SQLite writer serialization and the
PostgreSQL session advisory lock. A new counter table or migration is unnecessary.
The candidate uses a task-description snapshot read from authorized task data.
Validate that snapshot against the task row during final admission. A concurrent
description edit rejects stale admission for recomposition, rather than saving
an unintended stale brief. Do not run saved-prompt lookups inside the write transaction.
Return the selected content and selected trusted-context identity to the service.
The same selection determines persistence, queue content, and agent dispatch.
On rollback, restore caller-visible content and metadata as well as timestamps
and prompt ordinal. Otherwise retries can retain a failed selection.
## Composition and delivery
For an eligible candidate, put the trimmed brief before the additional
instruction, separated by two newlines. Exact equality after outer trimming
produces one copy. Empty descriptions use the ordinary candidate.
Prepare both candidates through the existing server-owned saved-prompt and
system-context pipeline before admission. Resolve title ownership, canvas
capabilities, and session transitions once, then reuse their canonical snapshots. Keep each candidate paired with its
trusted expansion. Fingerprint the original request before either transform.
An idempotent replay returns the saved winner even after the description changes.
`wsAddMessage` already assigns `req.Content = message.Content` before dispatch.
Extend that handoff to use the selected trusted context. Do not independently
prepend the brief inside `StartCreatedSession`, `startTask`, or the browser.
The real created-session launch must preserve both visible sections through
workflow composition. Compose the applicable workflow instructions once and
retain the accepted direct content as user input. If a replacing step template
would discard this content, append the direct content after that template and
use the existing composed-prompt launch option to prevent a second replacement.
Keep automatic workflow-entry composition unchanged. Test empty step prompts,
`{{task_prompt}}`, and nonempty templates without that placeholder.
The saved user row and final dispatch must contain the same visible brief and
instruction. Existing canonical system-context additions retain their authority.
Passthrough delivery retains visible text without hidden saved-prompt expansion.
Keep submitted attachments, entity references, and plan-comment claims intact.
`initial_prompt_preview` remains display-only and cannot supply prompt authority.
## Transcript
Keep `useProcessedMessages` and `shouldShowTaskDescriptionFallback` eligibility
unchanged. Before admission, the synthetic description row represents the brief.
After admission, prompt #1 replaces it and contains the brief plus instruction.
No synthetic historical prompt, extra ordinal, or permanently pinned banner is needed.
Reuse the existing transcript and Prompt History renderers. The nearest mobile
exemplar is `components/task/task-layout.tsx` and its `SessionMobileLayout`.
Phone Chat remains a full-height destination with one transcript scroll owner.
Composer position, safe-area handling, touch targets, and navigation remain unchanged.
Long first prompts remain reachable through existing prompt expansion/history controls.
## Failure and compatibility
A history, snapshot, or persistence error stops admission before dispatch.
Existing launch-error behavior handles failures after message acceptance. This
package does not promise provider-level exactly-once delivery after a process crash.
Race tests must include a direct request competing with
`ClaimInitialPromptFallback`, two distinct direct messages, and a same-ID retry.
A zero-valued fallback reservation suppresses direct brief insertion.
Deleted user rows cannot make an existing prompt-counter row eligible again.
Existing launch, workflow-entry, and Office callers do not opt into this direct
admission option. No public API field, database migration, or new UI control is needed.
This design records a local extension of existing ownership, so no separate ADR is required.
## Related contracts
- [Workflow first-prompt ownership](workflow-step-agent-start-ownership.md#prompt-history-contract)
- [Saved-prompt delivery](saved-prompt-delivery.md)
- [Transcript history visibility](../../ui/system-design/task-prompt-transcript-visibility.md)
- [Server-owned saved-prompt expansion](../../../decisions/2026-09-01-server-owned-saved-prompt-expansion.md)
## Implementation plans
[Initial task brief fix package](../../../plans/initial-task-brief/plan.md)