Fix zero-row populate retry and refresh model config#117
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR improves the populate orchestration pipeline and aligns agent model configuration. The populate agent's INSTRUCTIONS prompt is restructured into explicit numbered workflow steps with a "CRITICAL" checklist that enforces subagent invocation for concrete leads and clarifies row-limit termination. The populate workflow is enhanced with row-count verification after generation: if zero rows are inserted, it logs a warning and retries with stricter subagent requirements; if still empty after retry, it throws an error; otherwise it returns combined output. The refresh agent now derives its OpenRouter model from configured authContext instead of using a hardcoded value. Sequence DiagramsequenceDiagram
participant PopulateWorkflow as Populate Workflow
participant PopulateAgent as Populate Agent
participant Subagent as Subagent
participant Dataset as Dataset
PopulateWorkflow->>PopulateAgent: agent.generate(initial prompt) with run_subagent requirement
PopulateAgent->>Subagent: run_subagent(concrete leads)
Subagent->>Dataset: insert rows
PopulateWorkflow->>Dataset: count inserted rows
alt rows == 0
PopulateWorkflow->>PopulateAgent: agent.generate(retry prompt) with stricter subagent requirements
PopulateAgent->>Subagent: run_subagent(3-5 candidates)
Subagent->>Dataset: insert additional rows
PopulateWorkflow->>Dataset: count rows again
alt still 0 rows
PopulateWorkflow->>PopulateWorkflow: throw error
else rows > 0
PopulateWorkflow->>PopulateWorkflow: return original + retry output
end
else rows > 0
PopulateWorkflow->>PopulateWorkflow: return output
end
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/src/mastra/agents/refresh.ts (1)
59-68:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winValidate the
investigateSubagentmodel slug before callingopenrouter()In
backend/src/mastra/agents/refresh.ts,authContextSchemadefinesmodelConfigand enforcesinvestigateSubagent: z.string().min(1), so theauthContext.modelConfig!non-null assertion should be safe. What’s still missing is validation thatinvestigateSubagentis a valid OpenRouter model identifier/format—invalid strings can still fail at runtime when passed toopenrouter(modelSlug). Add schema refinement (or a runtime guard) to enforce the expected model-id format/range.🤖 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 `@backend/src/mastra/agents/refresh.ts` around lines 59 - 68, Validate the investigateSubagent value before passing it to openrouter: add a schema refinement to authContextSchema (or a runtime guard near refresh agent creation) that enforces the allowed OpenRouter model-id format/range, then use the validated value instead of raw authContext.modelConfig!.investigateSubagent; specifically update the authContextSchema or add a helper that checks authContext.modelConfig.investigateSubagent (the investigateSubagent string) against the OpenRouter model-id pattern/range and throw/handle a clear error if invalid before calling openrouter(modelSlug) in the Agent constructor.
🤖 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 `@backend/src/mastra/workflows/populate.ts`:
- Around line 252-285: The retry call to the orchestrator uses the wrong step
budget—change the second agent.generate call that produces retryResult to use
maxSteps: 80 (matching the initial run) instead of 40; update the call site
where retryResult is created (agent.generate(retryPrompt, { maxSteps: 40 })) so
the retry has the full orchestrator budget and then continue to record metrics
and re-check rowCount as currently done.
---
Outside diff comments:
In `@backend/src/mastra/agents/refresh.ts`:
- Around line 59-68: Validate the investigateSubagent value before passing it to
openrouter: add a schema refinement to authContextSchema (or a runtime guard
near refresh agent creation) that enforces the allowed OpenRouter model-id
format/range, then use the validated value instead of raw
authContext.modelConfig!.investigateSubagent; specifically update the
authContextSchema or add a helper that checks
authContext.modelConfig.investigateSubagent (the investigateSubagent string)
against the OpenRouter model-id pattern/range and throw/handle a clear error if
invalid before calling openrouter(modelSlug) in the Agent constructor.
🪄 Autofix (Beta)
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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5c3eb323-cf1e-4082-8d13-9a84f32e7116
📒 Files selected for processing (3)
backend/src/mastra/agents/populate.tsbackend/src/mastra/agents/refresh.tsbackend/src/mastra/workflows/populate.ts
|
Rechecked this head before asking for review. Current state:
@MMeteorL @simantak-dabhade could one of you do the non-author review when you have a minute? Looks good from my side. |
Summary
Verification