Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions application/workflows/auto_novel_generation_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,12 @@ def _get_workflow_system_template(self) -> str:
"PromptRegistry 不可用 (node_key=%s): %s", _WORKFLOW_CHAPTER_GEN_NODE_KEY, exc
)

logger.debug("CPMS: 使用硬编码回退 system 模板")
# ★ 修复 #146:将降级日志提升至 WARNING,便于排查提示词广场编辑不生效的问题
logger.warning(
"CPMS: 使用硬编码回退 system 模板 (node_key=%s)。"
"可能原因:PromptRegistry 不可用,或数据库中该节点未正确播种。",
_WORKFLOW_CHAPTER_GEN_NODE_KEY,
)
return _FALLBACK_SYSTEM_TEMPLATE

def _get_workflow_user_template(self) -> str:
Expand All @@ -1768,7 +1773,11 @@ def _get_workflow_user_template(self) -> str:
"PromptRegistry 不可用 (node_key=%s): %s", _WORKFLOW_CHAPTER_GEN_NODE_KEY, exc
)

logger.debug("CPMS: 使用硬编码回退 user_template")
logger.warning(
"CPMS: 使用硬编码回退 user_template (node_key=%s)。"
"可能原因:PromptRegistry 不可用,或数据库中该节点未正确播种。",
_WORKFLOW_CHAPTER_GEN_NODE_KEY,
)
return _FALLBACK_USER_TEMPLATE

async def _extract_chapter_state(self, content: str, chapter_number: int) -> ChapterState:
Expand Down
18 changes: 18 additions & 0 deletions infrastructure/ai/prompt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ def update_node(
db.execute(sql, params)
db.commit()

# ★ 修复 #146:节点更新后使 PromptRegistry 缓存失效,
# 确保生成管线能立即读取到最新模板。
self._invalidate_registry_cache(node_id)

return self.get_node(node_id, by_key=False)

def rollback_node(self, node_id: str,
Expand Down Expand Up @@ -1083,6 +1087,20 @@ def _attach_active_versions(self, nodes: List[NodeInfo]) -> None:
if node.active_version_id and node.active_version_id in ver_map:
node.set_active_version(ver_map[node.active_version_id])

@staticmethod
def _invalidate_registry_cache(node_key_or_id: str) -> None:
"""使 PromptRegistry 缓存失效(node_key 或 node_id 均可)。"""
try:
from infrastructure.ai.prompt_registry import get_prompt_registry
registry = get_prompt_registry()
# 尝试按 node_key 失效;如果是 node_id 则清除全部缓存(更安全)
if '-' in node_key_or_id and len(node_key_or_id) < 50:
registry.invalidate_cache(node_key_or_id)
else:
registry.invalidate_cache()
except Exception:
pass # Registry 不可用时静默跳过

@staticmethod
def _get_current_version(db, node_id: str) -> Optional[VersionInfo]:
"""获取节点当前激活版本。"""
Expand Down
9 changes: 9 additions & 0 deletions interfaces/api/v1/workbench/llm_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ def _invalidate_plaza_cache() -> None:
_plaza_cache = {}
_plaza_cache_ts = 0.0

# ★ 修复 #146:同时清除 PromptRegistry 缓存(TTL=300s),否则
# 生成管线在 5 分钟内仍会读取旧版 DB 快照,导致提示词广场编辑不生效。
try:
from infrastructure.ai.prompt_registry import get_prompt_registry
registry = get_prompt_registry()
registry.invalidate_cache()
except Exception:
pass # Registry 不可用时静默跳过,不影响 API 层功能


@router.get('/prompts/plaza-init')
async def plaza_init() -> Dict[str, Any]:
Expand Down