fix(ai-connectors): move fallbackStrategy out of SalesPrompt.salesPrompt JSON to prevent overwrite race

Open
#66 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, typescript
Domain
backend, database

Research direction

Read apps/api/src/ai-connectors/ai-connectors.service.ts around getFallbackStrategy and saveFallbackStrategy, then inspect the SalesPrompt model in packages/prisma/schema.prisma and the related Prisma migration setup. Trace how the current JSON value is read and written, including the legacy fallback path. Done means fallback settings use a dedicated nullable column, existing JSON settings remain readable, and saving fallback settings leaves salesPrompt unchanged.

Written by the indexing model from the issue text.

Description

backend database
Problem Description

In apps/api/src/ai-connectors/ai-connectors.service.ts (saveFallbackStrategy, lines 432-469), fallback settings are stored inside the same SalesPrompt.salesPrompt JSON string as the main AI Sales Prompt. saveFallbackStrategy reads the entire salesPrompt, parses it, mutates fallbackStrategy, and writes the whole string back.

If an admin edits the Sales Prompt concurrently with a Fallback Strategy update, the second write silently overwrites the first.


Expected Behavior
  • Saving fallbackStrategy must never overwrite SalesPrompt.salesPrompt.
  • Existing workspaces that currently have fallbackStrategy stored inside salesPrompt JSON must continue to work seamlessly with zero data loss.

Where to Look
  • apps/api/src/ai-connectors/ai-connectors.service.ts (getFallbackStrategy, saveFallbackStrategy lines 432-469)
  • packages/prisma/schema.prisma (SalesPrompt)

Solution / Implementation Guide (Zero-Breakage Way)
  1. Add a nullable fallbackStrategy Json? column to SalesPrompt in packages/prisma/schema.prisma (via Prisma migration).
  2. In getFallbackStrategy:
    • Read record.fallbackStrategy first; if null, fall back to parsing fallbackStrategy from record.salesPrompt JSON so existing workspaces keep their settings.
  3. In saveFallbackStrategy:
    • Update only the dedicated fallbackStrategy column via prisma.salesPrompt.upsert / update, leaving salesPrompt untouched.
Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
6m
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sumamakhan761/tryinstance

All issues in sumamakhan761/tryinstance

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.