Fix cache invalidation falling back to static files after reprocessing
After processing a new knowledge base spec, invalidate_cache() was clearing the DB spec from the cache without replacing it. The next analysis would then fall back to static prompts/*.md files instead of using the newly generated DB spec. Now invalidate_cache() accepts optional new_spec_content to immediately populate the DB cache, and knowledge_base_service passes the freshly distilled spec content so it's available for the next analysis without a server restart. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
de62fa1f87
commit
1800e71229
2 changed files with 15 additions and 6 deletions
|
|
@ -259,8 +259,8 @@ class KnowledgeBaseService:
|
|||
)
|
||||
await session.commit()
|
||||
|
||||
# Invalidate reference docs cache
|
||||
self.reference_docs.invalidate_cache(agent_key)
|
||||
# Update reference docs cache with new spec content
|
||||
self.reference_docs.invalidate_cache(agent_key, new_spec_content=spec_content)
|
||||
logger.info(f"[KB_SERVICE] Pipeline complete for {agent_key}, spec version {spec.version_number}")
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -47,8 +47,14 @@ class ReferenceDocsService:
|
|||
self._db_specs[key] = spec.content
|
||||
print(f" Loaded DB spec for {key}: {len(spec.content)} chars (v{spec.version_number})")
|
||||
|
||||
def invalidate_cache(self, agent_key: str | None = None) -> None:
|
||||
"""Clear cached specs. If agent_key is None, clear all."""
|
||||
def invalidate_cache(self, agent_key: str | None = None, new_spec_content: str | None = None) -> None:
|
||||
"""Clear cached specs and optionally replace with new content.
|
||||
|
||||
Args:
|
||||
agent_key: The agent key to invalidate (or None for all).
|
||||
new_spec_content: If provided, immediately populate the DB cache
|
||||
with this content so the next analysis uses it without a restart.
|
||||
"""
|
||||
if agent_key is None:
|
||||
self._db_specs.clear()
|
||||
self._barclaycard_brand_spec = None
|
||||
|
|
@ -57,8 +63,11 @@ class ReferenceDocsService:
|
|||
self._channel_tech_specs_spec = None
|
||||
self._legal_spec = None
|
||||
else:
|
||||
self._db_specs.pop(agent_key, None)
|
||||
# Also clear the file-based cache so next call re-checks DB
|
||||
if new_spec_content is not None:
|
||||
self._db_specs[agent_key] = new_spec_content
|
||||
else:
|
||||
self._db_specs.pop(agent_key, None)
|
||||
# Also clear the file-based cache so it won't be stale
|
||||
cache_map = {
|
||||
"legal": "_legal_spec",
|
||||
"brand_barclays": "_barclays_brand_spec",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue