sync update from LAN repo (source master @ ca48c4ec)
This commit is contained in:
1 parent
8bc8b0e082
commit
ea9dcff9c0
873 files changed
+107866
-14011
No files matched your search
@@ -17,7 +17,6 @@ _MUTATION_SYNC_DELAYS_SECONDS = (1.0, 8.0, 30.0, 90.0, 300.0)
|
||||
_MUTATION_SYNC_MAX_SECONDS = 10 * 60.0
|
||||
_MUTATION_SYNC_CONFIRM_GRACE_SECONDS = 30.0
|
||||
_FULL_SCAN_FALLBACK_SECONDS = 10 * 60.0
|
||||
_FOCUS_RECONCILE_SECONDS = 5 * 60.0
|
||||
_WIKI_CONFIG_UPGRADE_RETRY_SECONDS = 5 * 60.0
|
||||
|
||||
|
||||
@@ -200,6 +199,13 @@ async def _upgrade_wiki_generation_configs_once(
|
||||
return {"eligible": len(targets), "upgraded": upgraded, "failed": failed}
|
||||
|
||||
|
||||
def _has_directory_constraints(mapping: dict[str, Any]) -> bool:
|
||||
return bool(
|
||||
mapping.get("wiki_directory_paths")
|
||||
or mapping.get("wiki_parent_directories")
|
||||
)
|
||||
|
||||
|
||||
def _knowledge_base_is_processing(remote: dict[str, Any]) -> bool:
|
||||
"""Normalize processing markers across old/new WeKnora response shapes."""
|
||||
|
||||
@@ -727,71 +733,6 @@ async def _refresh_local_wiki_config(app: FastAPI):
|
||||
return await rebuild_local_wiki_index_runtime(app)
|
||||
|
||||
|
||||
async def _reconcile_focus_constraints_once(app: FastAPI) -> None:
|
||||
"""Resume strict focus filtering after process restarts."""
|
||||
|
||||
mapping_store = getattr(app.state, "llmwiki_store", None)
|
||||
list_visible = getattr(mapping_store, "list_visible", None)
|
||||
if not callable(list_visible):
|
||||
return
|
||||
mappings = [
|
||||
row
|
||||
for row in await list_visible(
|
||||
"system",
|
||||
scope="all",
|
||||
is_admin=True,
|
||||
)
|
||||
if _has_focus_constraint(row)
|
||||
]
|
||||
if not mappings:
|
||||
return
|
||||
service = getattr(app.state, "llmwiki_sync_service", None)
|
||||
client = getattr(service, "client", None)
|
||||
if client is None:
|
||||
from deerflow.integrations.weknora.runtime import (
|
||||
build_weknora_client,
|
||||
get_resolved_llmwiki_runtime,
|
||||
)
|
||||
|
||||
runtime = get_resolved_llmwiki_runtime()
|
||||
if not runtime.weknora_enabled:
|
||||
return
|
||||
client = build_weknora_client(runtime)
|
||||
|
||||
from app.gateway.wiki_directory_constraints import (
|
||||
reconcile_fixed_parent_directories,
|
||||
)
|
||||
|
||||
semaphore = asyncio.Semaphore(4)
|
||||
|
||||
async def run(mapping: dict[str, Any]) -> None:
|
||||
async with semaphore:
|
||||
try:
|
||||
remote = await client.get_knowledge_base(
|
||||
str(mapping.get("weknora_id") or "")
|
||||
)
|
||||
if not isinstance(remote, dict):
|
||||
return
|
||||
processing = await _remote_generation_is_processing(
|
||||
client,
|
||||
mapping,
|
||||
remote=remote,
|
||||
)
|
||||
if processing is not False:
|
||||
return
|
||||
await reconcile_fixed_parent_directories(client, mapping)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"Periodic Wiki focus reconciliation failed mapping_id=%s",
|
||||
mapping.get("id"),
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
await asyncio.gather(*(run(mapping) for mapping in mappings))
|
||||
|
||||
|
||||
def _auto_sync_ready(app: FastAPI, config: Any) -> bool:
|
||||
return bool(
|
||||
config.enabled
|
||||
@@ -915,7 +856,6 @@ async def local_wiki_index_scheduler_loop(app: FastAPI) -> None:
|
||||
last_sync_started_at: float | None = None
|
||||
last_synced_runtime_signature: str | None = None
|
||||
last_full_scan_started_at: float | None = None
|
||||
last_focus_reconcile_started_at: float | None = None
|
||||
last_prompt_schema_upgrade_started_at: float | None = None
|
||||
while True:
|
||||
try:
|
||||
@@ -924,30 +864,22 @@ async def local_wiki_index_scheduler_loop(app: FastAPI) -> None:
|
||||
# cadence. Provider/URL changes therefore take effect promptly.
|
||||
config = await _refresh_local_wiki_config(app)
|
||||
now = monotonic()
|
||||
if (
|
||||
last_prompt_schema_upgrade_started_at is None
|
||||
or now - last_prompt_schema_upgrade_started_at
|
||||
>= _WIKI_CONFIG_UPGRADE_RETRY_SECONDS
|
||||
):
|
||||
last_prompt_schema_upgrade_started_at = now
|
||||
await _upgrade_wiki_generation_configs_once(app)
|
||||
auto_sync_ready = _auto_sync_ready(app, config)
|
||||
if (
|
||||
not auto_sync_ready
|
||||
and (
|
||||
last_focus_reconcile_started_at is None
|
||||
or now - last_focus_reconcile_started_at
|
||||
>= _FOCUS_RECONCILE_SECONDS
|
||||
)
|
||||
):
|
||||
last_focus_reconcile_started_at = now
|
||||
await _reconcile_focus_constraints_once(app)
|
||||
if not auto_sync_ready:
|
||||
# A later disabled -> enabled transition is a new first valid
|
||||
# configuration and should receive an immediate scan.
|
||||
# With automatic sync off, the scheduler must remain local-only:
|
||||
# no periodic WeKnora page scan, prompt rewrite, or directory
|
||||
# reconciliation. Explicit user/API calls remain responsible
|
||||
# for remote refreshes.
|
||||
last_sync_started_at = None
|
||||
last_synced_runtime_signature = None
|
||||
else:
|
||||
if (
|
||||
last_prompt_schema_upgrade_started_at is None
|
||||
or now - last_prompt_schema_upgrade_started_at
|
||||
>= _WIKI_CONFIG_UPGRADE_RETRY_SECONDS
|
||||
):
|
||||
last_prompt_schema_upgrade_started_at = now
|
||||
await _upgrade_wiki_generation_configs_once(app)
|
||||
interval = float(config.sync_interval_seconds)
|
||||
runtime_signature = getattr(
|
||||
app.state,
|
||||
|
||||
Reference in new issue
Block a user