feat(ai): add prompts.getAll to fetch all prompts at a label - #4903
Conversation
Prompt To Fix All With AI### Issue 1
packages/ai/src/prompts.ts:301
**Partial matches hide incompatibility**
On an older server that ignores the label filter, some latest prompt versions can match the requested label while others do not. Because this guard throws only when no rows match, `getAll()` returns an incomplete set as a successful result. Callers cannot distinguish the missing prompts from prompts that do not carry the label, and the promised one-request cache warm-up is incomplete.
### Issue 2
packages/ai/src/prompts.ts:276-280
**Malformed rows are silently skipped**
This condition handles malformed rows the same way as valid rows whose label moved. If a response contains valid rows alongside one with a missing or incorrectly typed prompt field, `getAll()` caches and returns only the valid subset instead of rejecting the invalid response. That hides server response errors and leaves callers with an incomplete result, unlike the existing single-prompt fetch path, which throws when response validation fails.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "feat(ai): add prompts.getAll to fetch al..." | Re-trigger Greptile |
| } | ||
| } | ||
|
|
||
| if (rows.length > 0 && Object.keys(results).length === 0) { |
There was a problem hiding this comment.
Partial matches hide incompatibility
On an older server that ignores the label filter, some latest prompt versions can match the requested label while others do not. Because this guard throws only when no rows match, getAll() returns an incomplete set as a successful result. Callers cannot distinguish the missing prompts from prompts that do not carry the label, and the promised one-request cache warm-up is incomplete.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ai/src/prompts.ts
Line: 301
Comment:
**Partial matches hide incompatibility**
On an older server that ignores the label filter, some latest prompt versions can match the requested label while others do not. Because this guard throws only when no rows match, `getAll()` returns an incomplete set as a successful result. Callers cannot distinguish the missing prompts from prompts that do not carry the label, and the promised one-request cache warm-up is incomplete.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if (!isPromptApiResponse(row) || !rowResolvesLabel(row, label)) { | ||
| const name = typeof row === 'object' && row !== null ? (row as Record<string, unknown>).name : undefined | ||
| skipped.push(typeof name === 'string' ? name : '?') | ||
| continue | ||
| } |
There was a problem hiding this comment.
Malformed rows are silently skipped
This condition handles malformed rows the same way as valid rows whose label moved. If a response contains valid rows alongside one with a missing or incorrectly typed prompt field, getAll() caches and returns only the valid subset instead of rejecting the invalid response. That hides server response errors and leaves callers with an incomplete result, unlike the existing single-prompt fetch path, which throws when response validation fails.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ai/src/prompts.ts
Line: 276-280
Comment:
**Malformed rows are silently skipped**
This condition handles malformed rows the same way as valid rows whose label moved. If a response contains valid rows alongside one with a missing or incorrectly typed prompt field, `getAll()` caches and returns only the valid subset instead of rejecting the invalid response. That hides server response errors and leaves callers with an incomplete result, unlike the existing single-prompt fetch path, which throws when response validation fails.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
marandaneto
left a comment
There was a problem hiding this comment.
Advisory review of the verified PR snapshot.
| label, | ||
| config, | ||
| fetchedAt: now, | ||
| }) |
There was a problem hiding this comment.
blocking: Preserve __proto__ as a prompt entry — The API permits the prompt name __proto__, but assigning it into the plain results object changes its prototype instead of creating an own property. This prompt disappears from enumeration and JSON serialization; when it is the only returned prompt, getAll() incorrectly throws the unsupported-server error. Use a dictionary that safely handles arbitrary prompt names. Reproduction: reproduced — pnpm exec vitest run tests/prompts.test.ts tests/prompts-get-all-review.test.ts --coverage.enabled=false in a disposable validation worktree passed all 65 existing tests and failed both added regression cases (missing entry and erroneous exception); both cases passed with a temporary null-prototype result object.
marandaneto
left a comment
There was a problem hiding this comment.
approving to unblock, resolve comments before
Problem
Changes
prompts.getAll({ label: 'production' })fetches every prompt at that label in one call, following pagination, and returns an object of name to result.prompts.get(name, { label })calls are cache hits. One call per cache cycle instead of one per prompt.labelparam on the list endpoint and return latest versions. Each row is checked against itsall_labelsfield; if nothing resolves the label, the call throws a clear error instead of caching wrong versions. A single row whose label moved mid-request is skipped with a warning.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
.changeset/(written by hand, same format aspnpm changeset)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
getAllalways fetches (no cache read) so one call refreshes everything, like a feature flag poller.