Repository navigation
Labels
enhancementNew feature or request
Milestone
Description
Goal
Every request a provider receives says why it is made and for which saved chat session. A provider that keeps state between requests (for example a long-running local agent process) can then keep chat turns of one chat together, answer side calls (compaction, title, second opinion …) without mixing them into the conversation, and start fresh after "New Chat".
Context
- One provider instance is built per connection (
crates/app-shell/src/commands/connect/mod.rs) and reused for side calls: compaction (crates/app-logic/src/compaction.rs:759), notes (crates/app-logic/src/orchestration/notes.rs:625/:854/:1228), second opinion and injection check (crates/app-logic/src/second_opinion.rs:185/:388), and chat rounds (crates/app-logic/src/orchestration/chat_turn.rs:617/:922). send()only gets aRedactedContext(crates/core/src/ai/redacted_context.rs:72, wrappingSessionContextincrates/core/src/ai/types.rs). The provider cannot tell a chat round from a side call, nor which saved chat it belongs to. The saved chat session id changes with "New Chat" while the provider instance stays.AiUsagePurpose(crates/app-logic/src/ai_usage.rs:21) already names the purposes for usage records, but it lives inapp-logicand does not reach the provider.
Requirements
- A purpose type in
crates/core/src/ai(e.g.AiRequestPurpose) with at least: chat turn (including automatic follow-up rounds), compaction, session title, note suggestion, risk second opinion, injection check, other. RedactedContext(orSessionContext) carries the purpose and the saved chat session id (Option,Nonewhere no saved chat exists). It also carries a round marker for chat turns: first round of a user message vs. follow-up round after an action result.- Every call site above sets the right purpose.
AiUsagePurposeis either derived from it or replaced, so the two cannot disagree. - Built-in providers ignore the new fields. Their requests stay byte for byte the same (existing request snapshot tests unchanged).
- The redaction guarantees of
RedactedContextare unchanged. The new fields are metadata only, never content.
Acceptance Criteria
- A recording test provider sees the expected purpose at each call site: chat turn first round, follow-up round, compaction, title, note suggestion, second opinion, injection check.
- The saved chat session id in the request changes after "New Chat" on the same connection (test) and is
Nonewhere chat persistence is off. - Existing request/format tests of the built-in providers pass unchanged.
- Usage records keep their current purpose values (existing
ai_usagetests pass). - Relevant automated tests pass.
Technical Notes
crates/corestays free of app-logic types. The new purpose type belongs in core, and app-logic maps to it.- No security-relevant change: metadata only, and no new path for content.
Files: crates/core/src/ai/types.rs, crates/core/src/ai/redacted_context.rs, crates/app-logic/src/ai_usage.rs, crates/app-logic/src/compaction.rs, crates/app-logic/src/orchestration/chat_turn.rs, crates/app-logic/src/orchestration/notes.rs, crates/app-logic/src/second_opinion.rs, docs/specs/0006-ai-provider-trait.md
Spec impact: update 0006
Open questions
- Where the fields live: (a) on
SessionContext, (b) onRedactedContextnext to it. Recommendation: (b), because the purpose is request metadata, not session content.
Related Work
- Epic: Epic: AI provider kinds contributed by the embedding application #1636
- Blocked by Extension point: register AI provider kinds through Wiring (storage, factory, commands) #1637 (both change
crates/core/src/ai/types.rs)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Type
Fields
Priority
P2 - Normal
Activity
feat(ai): requests carry their purpose and the saved chat session id (#…
refactor(app-logic): keep size-limited files within their limit (#1638)
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1676. Requests now carry AiRequestPurpose (with chat round marker) and the saved chat session id on RedactedContext; all call sites set it, usage purpose derived where possible, spec 0006 updated, new recording-provider tests; CI green on PR #1676.
smart-ssh-reviewer commentedon Dec 4, 2026
Review: 1. The usage purpose is still hard-coded at three call sites (
notes.rs:626SessionTitle,notes.rs:891NoteSuggestion,compaction.rs:760Other). It is not derived from the request purpose, so the requirement "AiUsagePurpose is derived from it or replaced, so the two cannot disagree" is only partly met. Fix: take the purpose from the sealed request beforesend(e.g.let usage_purpose = request_context.purpose();in place of the comment line above the call) and reportusage_purpose.into(), as chat_turn.rs does. Swapping the comment line keeps both files within their size allowlist. Everything else checked out: the purposes and chat id are tested and counter-proven, spec 0006 §5a matches the code, built-in providers are unchanged, CI is green.fix(app-logic): derive usage purpose from the sealed request purpose (#…
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1676. Review fix: usage purpose for session title, note suggestion and compaction summary is now derived from the sealed request purpose (6a1cafd). app-logic tests pass, CI green.
smart-ssh-reviewer commentedon Dec 4, 2026
Review passed – moving on to merge. Approved. The previous finding is fixed in 6a1cafd. The compaction summary, session title and note suggestion now take their usage purpose from the sealed request purpose, so the two cannot disagree, and the usage values stay the same. The security review of the delta found nothing. app-logic tests pass locally and CI is green.
smart-ssh-coordinator commentedon Dec 4, 2026
Needs maintainer (merge): PR #1676 still not mergeable after 150 min (state BLOCKED, 0 checks pending).
feat(ai): requests carry their purpose and the saved chat session id (#…
smart-ssh-coordinator commentedon Dec 5, 2026
Merged and branch deleted: PR #1676 (squash) in develop