feat: store topic primary_agent_id in topics table#1171
Open
sh1nj1 wants to merge 3 commits into
Open
Conversation
…or_policies Move primary_agent_id from OrchestratorPolicy (scope_type: Topic) to a direct column on the topics table. This prevents topic-level agent assignments from being wiped when admin saves global orchestration config via the YAML editor (which does OrchestratorPolicy.delete_all). Changes: - Migration adds primary_agent_id column to topics with data migration - Topic model uses belongs_to :primary_agent instead of policy lookup - TopicsController uses includes(:primary_agent) for eager loading - PolicyResolver checks topic column first, falls back to policy config - AiAgentResolvable checks topic column directly before policy resolver - All tests updated to assert on topic.primary_agent_id
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a4818cd95
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…nostic - PolicyResolver#arbitration_strategy now returns "primary_first" when topic has primary_agent_id, preserving prior behavior where set_primary_agent! always implied primary_first routing. - Rewrite migration from raw SQLite SQL (json_extract, json_object) to ActiveRecord queries for PostgreSQL compatibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
primary_agent_idcolumn directly totopicstable instead of relying onOrchestratorPolicywith scope_type: "Topic"TopicsController,PolicyResolver,AiAgentResolvable, and related codeWhy
Previously, topic-level primary agent was stored in
orchestrator_policiestable withscope_type: "Topic". When admin updated orchestration YAML,apply_policies!woulddelete_allpolicies and re-create from YAML — destroying any topic-scoped settings. Storing directly on the topics table prevents this data loss.Changes
add_primary_agent_id_to_topicswith data migration from orchestrator_policiesbelongs_to :primary_agentdirectly on modeltopic_jsonto use column directlytopic.primary_agent_idfirst, falls back to orchestration configTest plan