Skip to content

Conversation

@AnthonyRonning
Copy link
Contributor

@AnthonyRonning AnthonyRonning commented Oct 13, 2025

Resolves #270 where clearing the system prompt in User Preferences would fail. Now properly calls deleteInstruction() when prompt is empty instead of attempting to update with an empty string.

Summary by CodeRabbit

  • Bug Fixes

    • Preferences: Empty prompts no longer create new instructions, and clearing an existing prompt now deletes the saved instruction, keeping settings clean and accurate.
  • Refactor

    • Minor internal cleanup in the comparison chart component with no functional or visual impact.

Resolves #270 where clearing the system prompt in User Preferences
would fail. Now properly calls deleteInstruction() when prompt is
empty instead of attempting to update with an empty string.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

Deploying maple with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6c88ad8
Status: ✅  Deploy successful!
Preview URL: https://3e360403.maple-ca8.pages.dev
Branch Preview URL: https://claude-issue-270-20250113-15.maple-ca8.pages.dev

View logs

@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Walkthrough

The pull request makes a minor JSX tweak in ComparisonChart and updates PreferencesDialog save logic to handle empty prompts: delete existing instructions when cleared, prevent creating new instructions with empty prompts, and update or create instructions only when the prompt is non-empty.

Changes

Cohort / File(s) Summary
Chart JSX tweaks
frontend/src/components/ComparisonChart.tsx
Replaced an empty header cell div with a self-closing div; minor inline style formatting adjustment. No data or control-flow changes.
Preferences save logic
frontend/src/components/PreferencesDialog.tsx
Centralized save behavior: if instructionId exists and trimmed prompt is empty → delete instruction and clear local state; if non-empty → update. If no instructionId and prompt is non-empty → create and set instructionId; if empty → no-op. Prevents saving empty prompts.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant PD as PreferencesDialog
  participant OS as os (instructions API)

  U->>PD: Click Save
  alt instructionId exists
    alt prompt.trim() is empty
      PD->>OS: deleteInstruction(instructionId)
      OS-->>PD: OK
      PD->>PD: Clear instructionId and prompt
    else prompt.trim() non-empty
      PD->>OS: updateInstruction(instructionId, prompt)
      OS-->>PD: OK
    end
  else no instructionId
    alt prompt.trim() non-empty
      PD->>OS: createInstruction(prompt)
      OS-->>PD: instructionId
      PD->>PD: Set instructionId
    else prompt.trim() empty
      PD->>PD: No-op (no create)
    end
  end
  PD-->>U: Save complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibbled bugs in fields of state,
Where prompts once grew, now validate—
If emptiness, we prune with grace;
If words remain, we keep their place.
A tiny chart now neat and spry,
I thump my paw and save—no sigh. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The PR includes an unrelated minor JSX/style tweak in frontend/src/components/ComparisonChart.tsx (changing an empty header cell div to a self-closing div and formatting adjustments) that is not related to issue #270 or the PreferencesDialog fix and therefore appears out of scope for this bugfix. Please remove or move the ComparisonChart formatting change into a separate commit/PR or document why it is included here to keep the bugfix focused and the review history clean; also ensure CI/tests pass after that split.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and succinctly describes the primary change in the PR: switching to the delete API when the system prompt is emptied to fix the save failure described in issue #270, and it is specific and free of extraneous noise.
Linked Issues Check ✅ Passed The changes to PreferencesDialog.tsx implement the intended behavior from issue #270 by calling deleteInstruction when the trimmed prompt is empty, preventing creation of empty instructions and only updating/creating when the prompt is non-empty, which directly addresses the save-failure when clearing the system prompt.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/issue-270-20250113-1530

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5651608 and 6c88ad8.

📒 Files selected for processing (2)
  • frontend/src/components/ComparisonChart.tsx (2 hunks)
  • frontend/src/components/PreferencesDialog.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Use 2-space indentation, double quotes, and a 100-character line limit for formatting
Use camelCase for variable and function names
Use try/catch with specific error types for error handling

Files:

  • frontend/src/components/ComparisonChart.tsx
  • frontend/src/components/PreferencesDialog.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use strict TypeScript typing and avoid any when possible

Files:

  • frontend/src/components/ComparisonChart.tsx
  • frontend/src/components/PreferencesDialog.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build-ios
  • GitHub Check: build-linux
  • GitHub Check: build-macos (universal-apple-darwin)
  • GitHub Check: build-android
  • GitHub Check: Cloudflare Pages

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

Fixed issue #270 where clearing the system prompt in User Preferences would fail with "Failed to save user preferences" error.

Key Changes:

  • When an existing instruction exists and the prompt is cleared (empty string), now calls deleteInstruction() instead of attempting updateInstruction() with empty prompt
  • Added validation to prevent creating new instructions with empty prompts
  • Properly resets local state (instructionId and prompt) after deletion
  • Minor formatting cleanup in ComparisonChart component (non-functional)

The fix correctly handles all three scenarios: creating new prompts, updating existing prompts, and deleting prompts by clearing them.

Confidence Score: 5/5

  • This PR is safe to merge with no risks - it's a clean, focused bug fix with proper state management
  • The fix directly addresses the reported issue with a straightforward solution. The logic properly handles all three cases (create, update, delete) with appropriate validation using trim() to check for empty strings. State is correctly reset after deletion. The changes are minimal, well-contained, and follow React best practices.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
frontend/src/components/PreferencesDialog.tsx 5/5 Fixed system prompt clearing by calling deleteInstruction() for empty prompts, preventing save failures
frontend/src/components/ComparisonChart.tsx 5/5 Minor formatting cleanup - removed empty lines and trailing spaces (non-functional change)

Sequence Diagram

sequenceDiagram
    participant User
    participant PreferencesDialog
    participant OpenSecretAPI
    participant Database

    User->>PreferencesDialog: Opens User Preferences
    PreferencesDialog->>OpenSecretAPI: listInstructions()
    OpenSecretAPI->>Database: Query instructions
    Database-->>OpenSecretAPI: Return instructions
    OpenSecretAPI-->>PreferencesDialog: Default instruction found
    PreferencesDialog->>PreferencesDialog: Set instructionId & prompt

    alt User clears system prompt (empty)
        User->>PreferencesDialog: Clear text & Save
        PreferencesDialog->>PreferencesDialog: Check if prompt.trim() === ""
        PreferencesDialog->>OpenSecretAPI: deleteInstruction(instructionId)
        OpenSecretAPI->>Database: Delete instruction
        Database-->>OpenSecretAPI: Success
        OpenSecretAPI-->>PreferencesDialog: Deleted
        PreferencesDialog->>PreferencesDialog: setInstructionId(null), setPrompt("")
        PreferencesDialog->>User: Success message
    else User updates system prompt (non-empty)
        User->>PreferencesDialog: Edit text & Save
        PreferencesDialog->>OpenSecretAPI: updateInstruction(instructionId, {prompt})
        OpenSecretAPI->>Database: Update instruction
        Database-->>OpenSecretAPI: Success
        OpenSecretAPI-->>PreferencesDialog: Updated
        PreferencesDialog->>User: Success message
    else User creates new prompt (no existing)
        User->>PreferencesDialog: Enter text & Save
        PreferencesDialog->>OpenSecretAPI: createInstruction({name, prompt, is_default})
        OpenSecretAPI->>Database: Create instruction
        Database-->>OpenSecretAPI: New instruction
        OpenSecretAPI-->>PreferencesDialog: New instructionId
        PreferencesDialog->>PreferencesDialog: setInstructionId(newId)
        PreferencesDialog->>User: Success message
    end
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@AnthonyRonning AnthonyRonning merged commit 017987a into master Oct 14, 2025
8 checks passed
@AnthonyRonning AnthonyRonning deleted the claude/issue-270-20250113-1530 branch October 14, 2025 01:04
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.

Clearing out the User Preferences System Prompt results in a save failure

2 participants