@@ -1125,6 +1125,16 @@ async def _execute_content_factory(
11251125 post_message(channel_id, msg, thread_ts)
11261126 return msg
11271127
1128+ # Refresh integration with domain context once we know the target domain.
1129+ # The generic top-level integration response may still show repo drift,
1130+ # while the domain-specific response can correctly say "research_article"
1131+ # or "write_article" without forcing a re-scan.
1132+ if domain:
1133+ domain_integration = await api_client.get_integration(user_id, domain=domain)
1134+ if domain_integration:
1135+ integration = domain_integration
1136+ connected_domains = integration.get("connected_domains", connected_domains)
1137+
11281138 # Look up repo from connected_domains
11291139 repo_name = None
11301140 domain_info = None
@@ -1303,17 +1313,32 @@ async def _execute_content_factory(
13031313 # 4. Check scan status
13041314 needs_scan = False
13051315 scan_reason = ""
1316+ recommended_next_action = integration.get("recommended_next_action")
1317+ scan_completed = bool(
1318+ integration.get("scan_completed")
1319+ or integration.get("content_research_ready")
1320+ or (domain_info and domain_info.get("scanned"))
1321+ )
13061322
1307- if domain_info:
1308- # Use domain-specific scan status
1323+ # Trust the backend's domain-aware contract first.
1324+ if recommended_next_action == "scan":
1325+ needs_scan = True
1326+ scan_reason = "Initial scan required"
1327+ elif domain_info:
13091328 if not domain_info.get("scanned"):
13101329 needs_scan = True
13111330 scan_reason = "Initial scan required"
13121331 elif not integration.get("project_scanned"):
13131332 needs_scan = True
13141333 scan_reason = "Initial scan required"
13151334
1316- if integration.get("has_updates"):
1335+ # Only use legacy has_updates as a fallback when the backend has not
1336+ # already told us that a usable scan exists for this domain.
1337+ if (
1338+ not scan_completed
1339+ and recommended_next_action in (None, "scan")
1340+ and integration.get("has_updates")
1341+ ):
13171342 needs_scan = True
13181343 scan_reason = "🔄 Updates detected in repository"
13191344
0 commit comments