Repository navigation
feat: rag management - #2976
feat: rag management#2976
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Codex GPT-5.6 SOL <codex@openai.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR adds RAG index-run persistence, indexing workflows, eleven RAG RPC endpoints, and dashboard views for overview metrics, chunks, runs, maintenance, and feed embedding status. ChangesRAG management and indexing
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 10
🧹 Nitpick comments (8)
apps/dash/src/components/rag/rag-maintenance.tsx (2)
66-66: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueGuard
onOpenChangeon the close transition.
onOpenChangereceives the next open state. The handler ignores it and always callsonCancel(). If HeroUI ever reports an open transition here, the modal closes immediately.♻️ Proposed change
- <Modal.Backdrop isOpen={mode !== null} onOpenChange={() => onCancel()}> + <Modal.Backdrop + isOpen={mode !== null} + onOpenChange={(open) => { + if (!open) onCancel(); + }}>🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/dash/src/components/rag/rag-maintenance.tsx` at line 66, Update the Modal.Backdrop onOpenChange handler in the rag maintenance component to inspect the next open state and call onCancel only when the state indicates the modal is closing; ignore open transitions so they do not cancel the operation.
117-128: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCancel shows a pending spinner during the reindex mutation.
isPending={isPending}on the Cancel button makes Cancel look like it is doing work. UseisDisabledon Cancel instead, and keepisPendingon the confirm button.♻️ Proposed change
- <Button isPending={isPending} variant="ghost" onPress={onCancel}> + <Button isDisabled={isPending} variant="ghost" onPress={onCancel}> Cancel </Button>🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/dash/src/components/rag/rag-maintenance.tsx` around lines 117 - 128, Update the Cancel Button in the modal footer to use isDisabled={isPending} instead of isPending={isPending}, while retaining isPending={isPending} on the confirm Button.packages/db/src/libs/resources/stats.ts (3)
286-286: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winEscape LIKE wildcards in
query.The value is passed as a bound parameter, so there is no injection. But
%and_inside the operator input still act as pattern metacharacters, so a search for100%matches unrelated content. Escape them before building the pattern.♻️ Proposed escaping
+const likePattern = (value: string) => + `%${value.replace(/[\\%_]/g, (char) => `\\${char}`)}%`; + @@ - query ? ilike(chunks.content, `%${query}%`) : undefined, + query ? ilike(chunks.content, likePattern(query)) : undefined,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/db/src/libs/resources/stats.ts` at line 286, Update the query pattern construction around ilike in the stats query to escape `%` and `_` characters in the user-provided query before adding the surrounding wildcards, while preserving bound-parameter usage and existing behavior for ordinary text.
211-248: 🚀 Performance & Scalability | 🔵 TrivialPlan for the cost of the overview aggregates.
Each of the five queries scans
resource_chunkand evaluates two correlatedEXISTSsubqueries per row. The dashboard overview calls all five on every load. As the corpus grows this becomes the most expensive read in the RAG surface.Consider a partial index on
resource_embedding (chunk_id, model, index_version)for the current-vector probe, and either short-lived caching or a materialized summary for the overview page.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/db/src/libs/resources/stats.ts` around lines 211 - 248, The getRagOverview implementation issues five full aggregate queries, each repeating expensive correlated vector checks; reduce this dashboard cost by reusing a current-vector partial index on resource_embedding(chunk_id, model, index_version) and adding either short-lived caching or a materialized summary for the overview result, while preserving the existing RagOverview shape.
367-381: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winUse
rowCountinstead ofreturning(). A PostgreSQL delete without.returning()returns the driverQueryResult; return{ deletedCount: deleted.rowCount ?? 0 }to avoid materializing one row per deleted vector.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/db/src/libs/resources/stats.ts` around lines 367 - 381, Update deleteStaleEmbeddings to remove the returning({ chunkId: embeddings.chunkId }) clause and use the delete query’s QueryResult instead; return deletedCount as deleted.rowCount ?? 0.packages/db/src/schemas/resources.schema.ts (1)
232-242: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winConstrain
scopeandstatusat the database level.
$type<>()only narrows the TypeScript type. It adds no runtime or database validation.resourceChunks.kindat Line 87 usestext(..., { enum: [...] }), so this table is the outlier. A writer that supplies an unlisted value (for example a workflow status this codebase does not map) persists a row that no reader treats as active and no reader treats as terminal.Add
check()constraints, and derive the index predicates fromRESOURCE_INDEX_RUN_ACTIVE_STATUSESso the literals at Lines 261, 266, and 271 cannot drift from the constant.♻️ Proposed constraint and predicate reuse
+const ACTIVE_STATUS_SQL = sql.raw( + RESOURCE_INDEX_RUN_ACTIVE_STATUSES.map((status) => `'${status}'`).join(", ") +); + export const resourceIndexRuns = pgTable( "resource_index_run", { @@ (table) => [ + check( + "resource_index_run_scope_valid", + sql`${table.scope} in ('resource', 'feed', 'all')` + ), + check( + "resource_index_run_status_valid", + sql`${table.status} in ('pending', 'running', 'completed', 'failed', 'cancelled')` + ), index("resource_index_run_source_idx").on(table.sourceType, table.sourceId),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/db/src/schemas/resources.schema.ts` around lines 232 - 242, Update the resource index run schema around scope and status to add database-level check constraints allowing only the defined ResourceIndexRunScope and ResourceIndexRunStatus values. In the active, completed, and failed index predicates, reuse RESOURCE_INDEX_RUN_ACTIVE_STATUSES instead of duplicating status literals, while preserving the existing predicate behavior.packages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sql (1)
4-8: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd the enum CHECK constraints in this migration.
"scope"and"status"are unconstrainedtext. The application layer is the only validator today. Add CHECK constraints here so an unmapped status cannot be stored.🛡️ Proposed addition
ALTER TABLE "chia_resource_index_run" ADD CONSTRAINT "chia_resource_index_run_triggered_by_chia_user_id_fkey" FOREIGN KEY ("triggered_by") REFERENCES "chia_user"("id"); +--> statement-breakpoint +ALTER TABLE "chia_resource_index_run" ADD CONSTRAINT "resource_index_run_scope_valid" CHECK ("scope" IN ('resource', 'feed', 'all'));--> statement-breakpoint +ALTER TABLE "chia_resource_index_run" ADD CONSTRAINT "resource_index_run_status_valid" CHECK ("status" IN ('pending', 'running', 'completed', 'failed', 'cancelled'));🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sql` around lines 4 - 8, Update the migration’s table definition to add database CHECK constraints restricting “scope” and “status” to their supported enum values, while preserving the existing defaults and NOT NULL behavior. Ensure invalid or unmapped values cannot be inserted directly into the database.apps/service/src/steps/resource-reindex.step.ts (1)
29-41: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winPage the reindex target enumeration.
listFeedTranslationIds(db, {})intentionally includes unpublished and soft-deleted translations so chunk visibility remains available for BM25 filtering.
listReindexTargetsStepstill returns the complete target array as one workflow-step output. Use paging or another bounded enumeration as the corpus grows.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/service/src/steps/resource-reindex.step.ts` around lines 29 - 41, Update listReindexTargetsStep to enumerate feed translation IDs in bounded pages instead of loading all results into one array, while preserving inclusion of unpublished and soft-deleted translations for BM25 filtering. Use the existing paging support exposed by listFeedTranslationIds or the database layer, then emit or process each page without retaining the complete target collection in a single workflow-step output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/dash/src/components/rag/embedding-drawer.tsx`:
- Around line 269-274: Update the embedding drawer’s hasEmbedding initialization
to use the existing per-locale embedding values provided through meta.embedding,
then refine that value with statuses query counts once the drawer is open.
Preserve the current query-based detection after opening while ensuring the
trigger reflects existing embeddings before any resource:status query runs.
- Around line 168-190: The permission tooltip cannot open from disabled buttons;
update both Recompute controls in
apps/dash/src/components/rag/embedding-drawer.tsx at lines 168-190 and 338-354
to display the restriction message through a focusable or plain-text element,
following the existing rag-maintenance.tsx approach. Preserve the disabled
button behavior and apply the same change to both sites.
In `@apps/dash/src/components/rag/rag-chunk-explorer.tsx`:
- Around line 77-104: The chunk explorer currently shows a permanent spinner
when the chunk:get query fails because data is undefined after loading. Update
the useQuery result and Drawer.Body rendering to handle the query error after
the loading branch, rendering the error when error || !data while preserving the
spinner only for isLoading.
In `@apps/dash/src/components/rag/rag-maintenance.tsx`:
- Around line 252-259: Update the prune action in the component containing the
“Prune stale vectors” Button to require confirmation before calling
prune.mutate, using the existing confirmation pattern such as
ConfirmReindexModal. Also include isActive in the Button’s isDisabled condition
so pruning cannot start during an active index run, while preserving the
existing canTrigger and prune.isPending gates.
In `@apps/dash/src/components/rag/use-index-run.ts`:
- Around line 58-62: Update the return logic in the run-following hook around
run and query to treat query.error as inactive: set isActive to false whenever
run:get fails, while preserving the existing run-status behavior for successful
queries. Also expose query.error from the returned object so callers following a
run can display it.
In `@apps/service/src/services/rag-indexing.service.ts`:
- Around line 147-155: Validate workflow statuses end to end: in
apps/service/src/services/rag-indexing.service.ts:147-155, update the
finalization flow to map runtime status via an explicit switch to
ResourceIndexRunTerminalStatus, defaulting to RESOURCE_INDEX_RUN_STATUS.Failed;
in packages/db/src/schemas/resources.schema.ts:232-242, add check constraints
for scope and status and derive active-status index predicates from
RESOURCE_INDEX_RUN_ACTIVE_STATUSES; in
packages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sql:4-8,
add matching CHECK constraints for the permitted values.
In `@packages/db/src/libs/resources/index-run.ts`:
- Line 175: Both list repositories must normalize limits to positive integers
before applying the maximum cap. In
packages/db/src/libs/resources/index-run.ts:175-175, update the limit
calculation to truncate and clamp dto.limit, using a default of 20 and a minimum
of 1; apply the same change in packages/db/src/libs/resources/stats.ts:269-269,
using a default of 50.
In `@plans/rag-dash-management-plan.md`:
- Around line 363-365: Update the rollout plan around the “尚未執行” migration
status to apply and verify the generated resource-index migration before
enabling or deploying RAG trigger and runs routes; alternatively, explicitly
gate those routes until migration completion, while preserving read-only chunk
statistics.
- Line 331: Update the run coordination described in the “跨 scope 不互斥” section
so resource- and feed-scoped runs cannot process the same chunks concurrently.
Before starting either scope, claim a shared resource-level lease, or reuse an
already active overlapping run instead of submitting duplicate embedding work.
- Line 114: Specify the text language on all three fenced code blocks in
plans/rag-dash-management-plan.md: add text to the schema tree fence at lines
114-114, the directory tree fence at lines 261-261, and the workflow pseudocode
fence at lines 281-281.
---
Nitpick comments:
In `@apps/dash/src/components/rag/rag-maintenance.tsx`:
- Line 66: Update the Modal.Backdrop onOpenChange handler in the rag maintenance
component to inspect the next open state and call onCancel only when the state
indicates the modal is closing; ignore open transitions so they do not cancel
the operation.
- Around line 117-128: Update the Cancel Button in the modal footer to use
isDisabled={isPending} instead of isPending={isPending}, while retaining
isPending={isPending} on the confirm Button.
In `@apps/service/src/steps/resource-reindex.step.ts`:
- Around line 29-41: Update listReindexTargetsStep to enumerate feed translation
IDs in bounded pages instead of loading all results into one array, while
preserving inclusion of unpublished and soft-deleted translations for BM25
filtering. Use the existing paging support exposed by listFeedTranslationIds or
the database layer, then emit or process each page without retaining the
complete target collection in a single workflow-step output.
In
`@packages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sql`:
- Around line 4-8: Update the migration’s table definition to add database CHECK
constraints restricting “scope” and “status” to their supported enum values,
while preserving the existing defaults and NOT NULL behavior. Ensure invalid or
unmapped values cannot be inserted directly into the database.
In `@packages/db/src/libs/resources/stats.ts`:
- Line 286: Update the query pattern construction around ilike in the stats
query to escape `%` and `_` characters in the user-provided query before adding
the surrounding wildcards, while preserving bound-parameter usage and existing
behavior for ordinary text.
- Around line 211-248: The getRagOverview implementation issues five full
aggregate queries, each repeating expensive correlated vector checks; reduce
this dashboard cost by reusing a current-vector partial index on
resource_embedding(chunk_id, model, index_version) and adding either short-lived
caching or a materialized summary for the overview result, while preserving the
existing RagOverview shape.
- Around line 367-381: Update deleteStaleEmbeddings to remove the returning({
chunkId: embeddings.chunkId }) clause and use the delete query’s QueryResult
instead; return deletedCount as deleted.rowCount ?? 0.
In `@packages/db/src/schemas/resources.schema.ts`:
- Around line 232-242: Update the resource index run schema around scope and
status to add database-level check constraints allowing only the defined
ResourceIndexRunScope and ResourceIndexRunStatus values. In the active,
completed, and failed index predicates, reuse RESOURCE_INDEX_RUN_ACTIVE_STATUSES
instead of duplicating status literals, while preserving the existing predicate
behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 34c93e97-d6ff-41cd-952d-f92be139106a
⛔ Files ignored due to path filters (2)
apps/dash/.next/dev/types/link.d.tsis excluded by!**/.next/**apps/dash/.next/dev/types/routes.d.tsis excluded by!**/.next/**
📒 Files selected for processing (39)
apps/dash/src/app/(workspace)/feed/(edit)/edit/[id]/page.tsxapps/dash/src/app/(workspace)/rag/chunks/page.tsxapps/dash/src/app/(workspace)/rag/layout.tsxapps/dash/src/app/(workspace)/rag/maintenance/page.tsxapps/dash/src/app/(workspace)/rag/page.tsxapps/dash/src/app/(workspace)/rag/runs/page.tsxapps/dash/src/components/commons/app-sidebar.tsxapps/dash/src/components/commons/root-provider.tsxapps/dash/src/components/feed/edit-fields.tsxapps/dash/src/components/feed/edit-form.tsxapps/dash/src/components/feed/metadata-fields.tsxapps/dash/src/components/rag/embedding-drawer.tsxapps/dash/src/components/rag/rag-chunk-explorer.tsxapps/dash/src/components/rag/rag-maintenance.tsxapps/dash/src/components/rag/rag-overview.tsxapps/dash/src/components/rag/rag-runs-table.tsxapps/dash/src/components/rag/rag-shared.tsxapps/dash/src/components/rag/use-index-run.tsapps/dash/src/shared/routes.tsxapps/service/src/routes/rpc.route.tsapps/service/src/services/rag-indexing.service.tsapps/service/src/steps/resource-reindex.step.tsapps/service/src/workflows/resource-reindex.workflow.tspackages/api/__tests__/rag.route.test.tspackages/api/orpc/contracts/rag.contract.tspackages/api/orpc/indexing.tspackages/api/orpc/router.contract.tspackages/api/orpc/router.tspackages/api/orpc/routes/rag.route.tspackages/api/package.jsonpackages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sqlpackages/db/.drizzle/migrations/20260812083824_resource_index_run/snapshot.jsonpackages/db/package.jsonpackages/db/src/libs/feeds/index.tspackages/db/src/libs/resources/index-run.tspackages/db/src/libs/resources/stats.tspackages/db/src/schemas/index.tspackages/db/src/schemas/resources.schema.tsplans/rag-dash-management-plan.md
| <Tooltip delay={300} isDisabled={canTrigger}> | ||
| <Tooltip.Trigger> | ||
| <Button | ||
| isDisabled={!canTrigger || isBusy} | ||
| isPending={isBusy} | ||
| size="sm" | ||
| variant="tertiary" | ||
| onPress={() => | ||
| trigger.mutate({ | ||
| sourceType: FEED_TRANSLATION_SOURCE_TYPE, | ||
| sourceId: resource.sourceId, | ||
| }) | ||
| }> | ||
| <RefreshCwIcon className="size-3.5" /> | ||
| Recompute | ||
| </Button> | ||
| </Tooltip.Trigger> | ||
| <Tooltip.Content> | ||
| <p className="text-xs"> | ||
| Only the configured admin can trigger this | ||
| </p> | ||
| </Tooltip.Content> | ||
| </Tooltip> |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
The permission tooltip never opens, because its trigger is disabled in the same state. Both controls enable the Tooltip only when canTrigger is false, and both disable the Button under that same condition. React Aria requires a hoverable and focusable trigger, so a disabled button does not open a tooltip. The user sees a greyed-out button with no reason.
apps/dash/src/components/rag/embedding-drawer.tsx#L168-L190: show the restriction text without depending on the disabled Recompute button, or wrap the button in a focusable element.apps/dash/src/components/rag/embedding-drawer.tsx#L338-L354: apply the same change to the "Recompute whole feed" control in the drawer footer.
apps/dash/src/components/rag/rag-maintenance.tsx at Line 263 already renders this message as plain text. Reuse that approach for consistency.
📍 Affects 1 file
apps/dash/src/components/rag/embedding-drawer.tsx#L168-L190(this comment)apps/dash/src/components/rag/embedding-drawer.tsx#L338-L354
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/dash/src/components/rag/embedding-drawer.tsx` around lines 168 - 190,
The permission tooltip cannot open from disabled buttons; update both Recompute
controls in apps/dash/src/components/rag/embedding-drawer.tsx at lines 168-190
and 338-354 to display the restriction message through a focusable or plain-text
element, following the existing rag-maintenance.tsx approach. Preserve the
disabled button behavior and apply the same change to both sites.
| const first = statuses[0]?.data; | ||
| const canTrigger = first?.canTrigger ?? false; | ||
| const isFeedBusy = feedRun.isActive || indexFeed.isPending; | ||
| const hasEmbedding = statuses.some( | ||
| (query) => (query.data?.counts.current ?? 0) > 0 | ||
| ); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
hasEmbedding is always false until the drawer opens.
The resource:status queries use enabled: isOpen. hasEmbedding reads only those query results. Before the first open, every query is idle, so the trigger icon always renders in the muted color and never signals existing embeddings.
The feed page already resolves this data. apps/dash/src/app/(workspace)/feed/(edit)/edit/[id]/page.tsx passes t.hasEmbedding per locale in meta.embedding. Pass the same information into the drawer, and use the query results only as a refinement after opening.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/dash/src/components/rag/embedding-drawer.tsx` around lines 269 - 274,
Update the embedding drawer’s hasEmbedding initialization to use the existing
per-locale embedding values provided through meta.embedding, then refine that
value with statuses query counts once the drawer is open. Preserve the current
query-based detection after opening while ensuring the trigger reflects existing
embeddings before any resource:status query runs.
| const result = | ||
| status === "completed" | ||
| ? await run.returnValue.catch(() => undefined) | ||
| : undefined; | ||
|
|
||
| return await finalize(db, row, status, { | ||
| result, | ||
| error: status === "completed" ? null : `Workflow run ${status}.`, | ||
| }); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
The run status is unvalidated end to end. The service forwards the workflow runtime status straight into the status column, and no layer restricts that column to the five known values. An unmapped value produces a row that isActive reports as inactive, that the partial unique indexes ignore, and that the dashboard cannot render.
apps/service/src/services/rag-indexing.service.ts#L147-L155: map the runtime status toResourceIndexRunTerminalStatuswith an explicit switch, and default toRESOURCE_INDEX_RUN_STATUS.Failed.packages/db/src/schemas/resources.schema.ts#L232-L242: addcheck()constraints forscopeandstatus, and derive the active-status index predicates fromRESOURCE_INDEX_RUN_ACTIVE_STATUSES.packages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sql#L4-L8: add the matchingCHECKconstraints so existing databases enforce the same values.
📍 Affects 3 files
apps/service/src/services/rag-indexing.service.ts#L147-L155(this comment)packages/db/src/schemas/resources.schema.ts#L232-L242packages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sql#L4-L8
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/service/src/services/rag-indexing.service.ts` around lines 147 - 155,
Validate workflow statuses end to end: in
apps/service/src/services/rag-indexing.service.ts:147-155, update the
finalization flow to map runtime status via an explicit switch to
ResourceIndexRunTerminalStatus, defaulting to RESOURCE_INDEX_RUN_STATUS.Failed;
in packages/db/src/schemas/resources.schema.ts:232-242, add check constraints
for scope and status and derive active-status index predicates from
RESOURCE_INDEX_RUN_ACTIVE_STATUSES; in
packages/db/.drizzle/migrations/20260812083824_resource_index_run/migration.sql:4-8,
add matching CHECK constraints for the permitted values.
|
|
||
| 放在 `packages/db/src/schemas/resources.schema.ts`,緊接 `resourceEmbeddings`。 | ||
|
|
||
| ``` |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Specify a language for each fenced code block.
markdownlint-cli2 reports MD040 at all three locations.
plans/rag-dash-management-plan.md#L114-L114: addtextto the schema tree fence.plans/rag-dash-management-plan.md#L261-L261: addtextto the directory tree fence.plans/rag-dash-management-plan.md#L281-L281: addtextto the workflow pseudocode fence.
🧰 Tools
🪛 markdownlint-cli2 (0.23.2)
[warning] 114-114: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
📍 Affects 1 file
plans/rag-dash-management-plan.md#L114-L114(this comment)plans/rag-dash-management-plan.md#L261-L261plans/rag-dash-management-plan.md#L281-L281
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@plans/rag-dash-management-plan.md` at line 114, Specify the text language on
all three fenced code blocks in plans/rag-dash-management-plan.md: add text to
the schema tree fence at lines 114-114, the directory tree fence at lines
261-261, and the workflow pseudocode fence at lines 281-281.
Source: Linters/SAST tools
| - `meta-chip.tsx` 的 chip 是否改用三態語意(空間只有一個 icon)。目前維持「曾經嵌入過」。 | ||
| - 檢索品質基準(`docs/rag-architecture.md` §9 的第一項)不在本規劃範圍。RAG 管理區塊將來是放評測結果的自然位置,但要先有評測腳本。 | ||
| - `resource_index_run` 的保留期限 / 清理策略。目前資料量小,暫不處理。 | ||
| - **跨 scope 不互斥**:`resource` 與 `feed` 兩個 scope 各有自己的 active unique index,所以「重算此語系」與「重算整篇」可以同時在跑,同一批 chunk 會被嵌入兩次。資料不會壞(`saveChunkEmbeddings` 是 upsert),但會多花額度。要擋需要跨 scope 的鎖,先不做。 |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift
Prevent duplicate embedding work across run scopes.
Line 331 permits overlapping resource and feed runs for the same chunks. Both runs can submit identical chunks to the embedding provider. This consumes duplicate credits and can exhaust provider rate limits.
Claim a shared resource-level lease before starting any scope, or reuse the overlapping run.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@plans/rag-dash-management-plan.md` at line 331, Update the run coordination
described in the “跨 scope 不互斥” section so resource- and feed-scoped runs cannot
process the same chunks concurrently. Before starting either scope, claim a
shared resource-level lease, or reuse an already active overlapping run instead
of submitting duplicate embedding work.
| ### 尚未執行 | ||
|
|
||
| **migration 未套用。** `packages/db/.drizzle/migrations/20260812083824_resource_index_run/` 已產生但沒有跑 `db:migrate` / `db:push`。在套用之前,所有觸發與 runs 頁都會因為 `chia_resource_index_run` 不存在而失敗;唯讀的 chunk 統計不受影響。 |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Apply the migration before enabling RAG triggers.
Line 365 states that chia_resource_index_run does not exist yet. Trigger and run routes query this table, so they fail until the migration completes.
Apply and verify the migration before deploying these routes, or gate the routes until rollout completes.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@plans/rag-dash-management-plan.md` around lines 363 - 365, Update the rollout
plan around the “尚未執行” migration status to apply and verify the generated
resource-index migration before enabling or deploying RAG trigger and runs
routes; alternatively, explicitly gate those routes until migration completion,
while preserving read-only chunk statistics.
- confirm stale-vector pruning and prevent it during active runs - surface run and chunk fetch failures in the dashboard - keep unknown workflow statuses active and normalize list limits
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/dash/src/components/rag/rag-maintenance.tsx`:
- Around line 290-307: Update the pruning button’s disabled condition in the
maintenance component to also block when the tracked run polling error from
useIndexRun is present, even if isActive is false. Surface that polling error in
the existing UI error display, allowing pruning to become available again once
run status polling succeeds.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 92a6c74b-12f4-4e3f-94bb-3b37a5b9e3dc
📒 Files selected for processing (7)
apps/dash/src/components/rag/embedding-drawer.tsxapps/dash/src/components/rag/rag-chunk-explorer.tsxapps/dash/src/components/rag/rag-maintenance.tsxapps/dash/src/components/rag/use-index-run.tsapps/service/src/services/rag-indexing.service.tspackages/db/src/libs/resources/index-run.tspackages/db/src/libs/resources/stats.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- apps/dash/src/components/rag/use-index-run.ts
- apps/dash/src/components/rag/rag-chunk-explorer.tsx
- packages/db/src/libs/resources/stats.ts
- packages/db/src/libs/resources/index-run.ts
- apps/service/src/services/rag-indexing.service.ts
| onPress={() => setAction("top-up")}> | ||
| <RefreshCwIcon className="size-4" /> | ||
| Top up missing | ||
| </Button> | ||
| <Button | ||
| isDisabled={!canTrigger || isBusy} | ||
| isPending={isBusy} | ||
| variant="danger" | ||
| onPress={() => setAction("full")}> | ||
| <RefreshCwIcon className="size-4" /> | ||
| Full reindex | ||
| </Button> | ||
| {/* `isActive` matters here: pruning mid-run would delete rows the run is still writing */} | ||
| <Button | ||
| isDisabled={!canTrigger || isActive || prune.isPending} | ||
| isPending={prune.isPending} | ||
| variant="tertiary" | ||
| onPress={() => setAction("prune")}> |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Block pruning when run polling fails.
Line 304 only blocks pruning when isActive is true. useIndexRun sets isActive to false when run:get fails. A known activeRunId can then still represent a running index job while this button enables pruning.
Keep pruning disabled when the tracked run has a polling error. Display that error so the user can retry after run status is available.
Proposed fix
- const { run, isActive } = useIndexRun({ runId: activeRunId, onSettled });
+ const { run, isActive, error: runError } = useIndexRun({
+ runId: activeRunId,
+ onSettled,
+ });
...
- isDisabled={!canTrigger || isActive || prune.isPending}
+ isDisabled={
+ !canTrigger || isActive || !!runError || prune.isPending
+ }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/dash/src/components/rag/rag-maintenance.tsx` around lines 290 - 307,
Update the pruning button’s disabled condition in the maintenance component to
also block when the tracked run polling error from useIndexRun is present, even
if isActive is false. Surface that polling error in the existing UI error
display, allowing pruning to become available again once run status polling
succeeds.
Summary by CodeRabbit
New Features
Bug Fixes