Skip to content

fix(ai-vault): stop labeling the preview fallback as the first prompt - #12178

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-aivault-first-prompt
Aug 3, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-aivault-first-prompt

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

AI Vault session details now label sliding-window fallback text as "Recent prompt" and reserve "First prompt" for stored or successfully re-read opening prompts. Local sessions keep showing the preview while the full prompt loads, then update both the text and label when the authoritative read succeeds; remote sessions retain the honest recent-prompt state without adding remote file reads. Copy accessibility labels and success messages follow the same provenance, with translations added to every renderer locale catalog.

Screenshots

No screenshot captured because the required $electron validation capability is unavailable in this session. The visual delta is limited to the existing prompt section label: preview-window text reads "Recent prompt" (localized), then changes to "First prompt" only after a local authoritative read succeeds.

Testing

  • pnpm lint (not run; targeted changed-code quality gate passed)
  • pnpm typecheck (pnpm tc)
  • pnpm test (not run in full; targeted tests passed)
  • pnpm build (not run)
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Additional checks:

  • pnpm vitest run --config config/vitest.config.ts src/renderer/src/components/right-sidebar/ai-vault-session-display.test.ts src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.test.tsx
  • pnpm run verify:localization-catalog
  • pnpm run verify:localization-extraction
  • pnpm run check:code-quality:changed

AI Review Report

Reviewed prompt provenance through stored firstUserPrompt, preview-window fallback, remote/unavailable reads, local successful replacement, loading stability, copy feedback, and locale coverage. The review found that the base branch suppressed truncated fallback text entirely; this change instead preserves the useful recent text while carrying explicit provenance through the display layer. Cross-platform compatibility was checked for macOS, Linux, and Windows: the change adds no shortcuts, path handling, shell behavior, platform checks, or Electron-specific branching, and the same localized labels and host-aware behavior apply on every platform.

Security Audit

Reviewed input handling, IPC, path handling, command execution, auth, secrets, and dependencies. This PR adds no IPC surface, remote file access, command execution, path manipulation, authentication flow, secrets, or dependencies; it only classifies already-scanned prompt text and adjusts renderer copy. The existing local-only first-prompt read boundary remains unchanged, so no security follow-up is needed.

Notes

Remote-host first-prompt reads remain intentionally out of scope. $electron was unavailable, so Electron UI validation and screenshots could not be performed without violating the repository instruction against substitute UI automation.

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes an honest-labeling bug in the AI Vault session details panel: preview-window text that comes from a sliding-window fallback is now tagged with a 'preview-window' source and displayed under a "Recent prompt" label, while "First prompt" is reserved for stored or re-read authoritative opening prompts. Local sessions still perform the on-demand re-parse and relabel dynamically when it succeeds; remote sessions surface the truncated text immediately without attempting a remote file read.

  • sessionFirstPrompt is replaced by sessionPromptPreview in /shared, which now returns { text, source } instead of a bare string, carrying provenance through to the renderer without requiring any extra IPC.
  • FirstPromptCard absorbs its own section header (previously rendered by the parent), derives the label and copy-button aria-label from displaySource, and updates both when the on-demand full read succeeds.
  • Five new i18n keys ("Recent prompt", "Copy recent prompt", etc.) are added across all five locale catalogs (en, es, ja, ko, zh) with matching translations.

Confidence Score: 4/5

Safe to merge; the change is display-only with no IPC, auth, or data-persistence side-effects.

The core behavioral shift — surfacing truncated preview text for remote sessions instead of hiding it — is intentional, well-tested, and correctly walled off by the 'preview-window' source tag so the renderer never misrepresents it. Two small rough edges exist in ai-vault-first-prompt-card.tsx: the section label briefly reads the generic 'Prompt' while loading for sessions that have no preview user messages (contradicting the 'Loading first prompt…' body text), and promptCopiedLabel silently conflates an undefined source with 'preview-window' in its fallback branch. Neither affects correctness in the paths exercised today, but both could cause confusion if the call-sites evolve.

Files Needing Attention: ai-vault-first-prompt-card.tsx — the displaySource derivation and the promptCopiedLabel fallback branch are worth a second look.

Important Files Changed

Filename Overview
src/shared/ai-vault-session-display.ts Renamed sessionFirstPrompt → sessionPromptPreview; returns AiVaultSessionPromptPreview
src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.tsx Card now owns its own section label and derives it from displaySource; loading/copy/clipboard paths are otherwise unchanged. Minor: when preview is null and loading is true, displaySource is undefined and the label shows the generic 'Prompt' before flipping to 'First prompt' once the read settles. The promptCopiedLabel fallback silently equates undefined with 'preview-window'.
src/renderer/src/components/right-sidebar/AiVaultSessionDetails.tsx Removed the SessionReceiptSection wrapper around FirstPromptCard (and the TextCursorInput import) since the card now renders its own section header; the change is clean with no logic impact.
src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.test.tsx Three new cases added: stored firstUserPrompt labelled 'First prompt', remote truncated preview labelled 'Recent prompt' with no IPC call, and local truncated preview relabelled after the full load resolves. Existing StrictMode and timeout tests updated for the new prop signature.
src/renderer/src/i18n/locales/en.json Added five new i18n keys: prompt, recentPrompt, recentPromptCopied, copyRecentPrompt, copyPrompt. All other locale files (es, ja, ko, zh) have matching additions.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[sessionPromptPreview called] --> B{firstUserPrompt stored?}
    B -- Yes --> C[return text, source: first-user-prompt]
    B -- No --> D{user message in previewMessages?}
    D -- Yes --> E[return text, source: preview-window]
    D -- No --> F[return null]

    C --> G[FirstPromptCard receives preview]
    E --> G
    F --> G

    G --> H{canLoadFullFirstPrompt?}
    H -- Yes / local --> I[loading = true, show preview label + text]
    H -- No / remote --> J[loading = false, show preview label + text]

    I --> K[getFirstUserPrompt IPC call]
    K -- success --> L[fullText set, displaySource = first-user-prompt, label = First prompt]
    K -- timeout / null --> M[fullText stays null, displaySource = preview?.source]

    M -- preview-window --> N[label = Recent prompt]
    M -- null --> O[label = Prompt generic]
Loading

Reviews (1): Last reviewed commit: "fix(ai-vault): label preview prompt hone..." | Re-trigger Greptile

Comment on lines +130 to 131
const displaySource = fullText ? 'first-user-prompt' : preview?.source
const showEmpty = !loading && !displayText

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Label shows generic "Prompt" while loading, then flips to "First prompt"

When preview is null and loading is true (a local session that has no stored firstUserPrompt and no user messages in previewMessages), displaySource resolves to undefined, so promptSectionLabel renders the generic "Prompt" header — even though the loading message beneath it already reads "Loading first prompt…". Once the read settles with a real value, the label jumps to "First prompt". The transient mismatch is observable whenever those three conditions coincide.

Comment on lines +249 to +258
function promptCopiedLabel(source: AiVaultSessionPromptPreview['source'] | undefined): string {
return source === 'first-user-prompt'
? translate(
'auto.components.right.sidebar.AiVaultSessionDetails.firstPromptCopied',
'First prompt copied'
)
: translate(
'auto.components.right.sidebar.AiVaultSessionDetails.recentPromptCopied',
'Recent prompt copied'
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 undefined source falls through to "Recent prompt copied" toast

When source is undefined (neither 'first-user-prompt' nor 'preview-window'), promptCopiedLabel silently returns "Recent prompt copied" — the same string as the 'preview-window' case — rather than a neutral fallback. In practice today the toast cannot fire when source is undefined because the caller would have already returned early (empty copyText), but this implicit coupling makes the function's contract easy to break silently if the call-sites change. A third branch (or an explicit fallback matching the generic "Prompt copied" wording) would make the boundary explicit.

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!

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The AI Vault session display now returns structured prompt previews with source metadata. Stored first prompts take precedence, while preview-window user prompts remain available when the window is truncated. The prompt card uses source-specific headings, copy labels, icons, and success messages. Session details pass the structured preview directly to the card. English, Spanish, Japanese, Korean, and Chinese locales include the new prompt strings. Tests cover resolution and rendering behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preview fallback text is no longer labeled as the first prompt.
Description check ✅ Passed The description covers the required sections, testing, review, security, and platform checks, while clearly noting unavailable screenshots and unrun full checks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.tsx (1)

160-166: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider reusing SessionReceiptSection instead of duplicating its header markup.

This block duplicates the icon-wrapper and label markup of SessionReceiptSection in AiVaultSessionDetails.tsx (same class names for the outer flex row, icon span, and label span). SessionReceiptSection still renders that same header pattern for "Latest turns" and "Worktree" sections in that file.

Export SessionReceiptSection from a shared location and use it here with the dynamic icon and promptSectionLabel(displaySource) as its label prop. This keeps one source of truth for the section-header layout.

♻️ Proposed direction
-    <section className="space-y-1.5">
-      <div className="flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.05em] text-muted-foreground">
-        <span className="text-muted-foreground/80">
-          <TextCursorInput className="size-3" />
-        </span>
-        <span>{promptSectionLabel(displaySource)}</span>
-      </div>
-      <div className="rounded-md border border-border/70 bg-foreground/[0.04] px-2.5 py-2">
+    <SessionReceiptSection
+      icon={<TextCursorInput className="size-3" />}
+      label={promptSectionLabel(displaySource)}
+    >
+      <div className="rounded-md border border-border/70 bg-foreground/[0.04] px-2.5 py-2">

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 780ac197-2469-4372-8225-7f13aee7c22e

📥 Commits

Reviewing files that changed from the base of the PR and between bcf7d1d and d5cfa2a.

📒 Files selected for processing (11)
  • src/renderer/src/components/right-sidebar/AiVaultSessionDetails.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.test.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-first-prompt-card.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-session-display.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-display.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/ai-vault-session-display.ts

Comment on lines +31 to +45
it('labels stored firstUserPrompt text as the first prompt', () => {
const remoteSession = {
...session,
executionHostId: 'ssh:dev-box',
firstUserPrompt: 'The authoritative opening ask'
} as AiVaultSession
stubApi(vi.fn().mockResolvedValue({ prompt: null }))

render(
<FirstPromptCard session={remoteSession} preview={sessionPromptPreview(remoteSession)} />
)

expect(screen.getByText('First prompt')).toBeTruthy()
expect(screen.getByText('The authoritative opening ask')).toBeTruthy()
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Keep stored prompts authoritative for local sessions.

This test uses executionHostId: 'ssh:dev-box', so it cannot detect local behavior. FirstPromptCard starts loadFullPrompt() for a loadable local session even when preview.source is 'first-user-prompt'. A re-read can replace the stored prompt despite the required precedence.

Add a local stored-prompt case that asserts getFirstUserPrompt is not called. Skip the on-demand read when the preview source is 'first-user-prompt'.

Based on PR objective “Stored first prompts take precedence” and the supplied FirstPromptCard implementation.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA — live screenshots of both card states (dev build of this branch, isolated instance, seeded 8-message Claude session fixture so the last-5 preview window excludes the opening ask):

Fallback state — full read unavailable (transcript unreadable, standing in for a remote-host session). Previously this text appeared under "First prompt"; it is the sliding-window fallback ("The parser chokes…" is message 5 of 8):

qa12178-recent-prompt-card.png

Loaded state — on-demand read succeeds and the card relabels with the true opening ask:

qa12178-first-prompt-card.png

Method: seeded ~/.claude/projects fixture in an isolated HOME/user-data instance running this branch (identity verified via getIdentity()); fallback state pinned by making the transcript unreadable after the list scan, then restored to capture the loaded state. Both labels render as designed; copy toast follows provenance as well.

@brennanb2025
brennanb2025 merged commit c9a37f5 into main Aug 3, 2026
84 of 86 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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