fix(desktop): slim floating bar prompt context#7544
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Greptile SummaryThis PR builds a dedicated slim system prompt for the floating bar by adding a
Confidence Score: 4/5Safe to merge; the prompt-slimming logic is correct and the two floating entry points are updated consistently. The core change routes floating queries to a schema-free, skills-free prompt correctly and symmetrically in both entry points. The two findings are a missed cache-write in the fallback path (wasteful but not incorrect) and a parallel-enum design that will need coordinated updates if a third style is ever added. Neither affects correctness today. desktop/Desktop/Sources/Providers/ChatProvider.swift — specifically the sendMessage fallback path and the relationship between ChatSystemPromptStyle and PromptProfile. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[sendMessage called] --> B{isOnboarding && systemPromptPrefix set?}
B -- Yes --> C[systemPrompt = systemPromptPrefix only]
B -- No --> D{systemPromptStyle}
D -- .floating --> E{cachedFloatingSystemPrompt empty?}
E -- No --> F[systemPrompt = cachedFloatingSystemPrompt]
E -- Yes --> G[buildFloatingBarSystemPrompt fallback rebuild]
G --> F
D -- .main --> H[systemPrompt = cachedMainSystemPrompt]
F --> I{systemPromptPrefix set?}
H --> I
I -- Yes --> J[prefix + newline + systemPrompt]
I -- No --> K[apply suffix if set]
J --> K
K --> L[pass to agentBridge.query]
subgraph Warmup
W1[formatMemoriesSection] --> W2[buildSystemPrompt profile:.main]
W1 --> W3[buildFloatingBarSystemPrompt profile:.floating]
W2 --> W4[cachedMainSystemPrompt]
W3 --> W5[cachedFloatingSystemPrompt]
end
Reviews (1): Last reviewed commit: "fix(desktop): use slim prompt for agent ..." | Re-trigger Greptile |
| if systemPromptStyle == .floating { | ||
| systemPrompt = cachedFloatingSystemPrompt.isEmpty | ||
| ? buildFloatingBarSystemPrompt(contextString: formatMemoriesSection()) | ||
| : cachedFloatingSystemPrompt | ||
| } else { |
There was a problem hiding this comment.
The fallback branch computes a fresh floating prompt but never writes it back to
cachedFloatingSystemPrompt. If warmup failed (bridge start returned early before setting the cache), every subsequent floating query triggers a full buildFloatingBarSystemPrompt rebuild instead of amortising that cost after the first call. Caching the result here mirrors exactly what warmup does and avoids repeated rebuilds.
| if systemPromptStyle == .floating { | |
| systemPrompt = cachedFloatingSystemPrompt.isEmpty | |
| ? buildFloatingBarSystemPrompt(contextString: formatMemoriesSection()) | |
| : cachedFloatingSystemPrompt | |
| } else { | |
| if systemPromptStyle == .floating { | |
| if cachedFloatingSystemPrompt.isEmpty { | |
| cachedFloatingSystemPrompt = buildFloatingBarSystemPrompt(contextString: formatMemoriesSection()) | |
| } | |
| systemPrompt = cachedFloatingSystemPrompt | |
| } else { |
| case main | ||
| case floating | ||
| } | ||
|
|
||
| /// State management for chat functionality with Claude Agent SDK | ||
| /// Uses hybrid architecture: Swift → Claude Agent (via Node.js bridge) for AI, Backend for persistence + context | ||
| @MainActor | ||
| class ChatProvider: ObservableObject { | ||
|
|
There was a problem hiding this comment.
Parallel enums for the same concept
ChatSystemPromptStyle (file-scope, public routing discriminator) and PromptProfile (private nested enum, build-time gate) both model the same .main/.floating distinction. The only code that converts between them is the implicit branch in sendMessage — there is no switch or mapping function. If a third style is added later (e.g. .task), both enums need updating and the if systemPromptStyle == .floating branch in sendMessage needs a matching arm, with no compiler enforcement of the mapping. Collapsing to a single enum (or adding an explicit promptProfile(for:) helper) would make the contract between the two clear.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Addressed the Greptile review comments in follow-up commit
|
kodjima33
left a comment
There was a problem hiding this comment.
desktop bug-fix fast lane (3/5) but mergeStateStatus BLOCKED — downgraded merge to approve
Summary
FloatingControlBarWindowandAgentPill) to request the explicit.floatingprompt style instead of relying on the floating prefix as an implicit sentinelWhy
Issue #6981 measured floating-bar chat latency at 6.6-11.1s per query and identified the shared main-chat prompt as a major contributor. The issue breakdown shows the floating session receiving the same large prompt as main chat, including about 12,280 chars of database schema and a skills section that is not needed for "what do you see on my screen?" style floating-bar queries.
The issue comments specifically call out:
This PR implements that narrow prompt-slimming recommendation without changing quota checks, save/sync timing, screenshot size, model defaults, or voice playback behavior.
Relation to existing work
Implementation details
ChatSystemPromptStylewith.mainand.floatingChatSystemPromptStyleowns the schema/skills inclusion policy throughincludesDatabaseSchemaandincludesSkillsbuildSystemPrompt(..., style: .main)preserves current main chat prompt behaviorbuildFloatingBarSystemPrompt(...)prependsfloatingBarSystemPromptPrefixbut uses.floating, which omits:cachedDatabaseSchema<available_skills>cachedFloatingSystemPromptduring bridge warmup so floating sessions are prewarmed with the slimmer promptsendMessage(..., systemPromptStyle: .floating)and writes fallback rebuilds back intocachedFloatingSystemPromptReview follow-up
Addressed Greptile feedback in follow-up commit
615bc02:cachedFloatingSystemPromptPromptProfileenum so there is one source of truth for prompt style policyExpected impact
This directly removes the schema section called out in #6981 (
schema:12280cin the posted logs) from floating-bar prompts. It should reduce prompt size, cache-write cost, and cold/warm inference latency for floating-bar queries while leaving the full main chat context intact.Verification
xcrun swift build -c debug --package-path Desktop🤖 Generated with OpenCode