Rename journal, steps and recovery: rename.json (RENAME_JOURNAL_FILE) records each step, documents are written whole and committed alone (FlowStore.replace_documents, identity.write_documents) and rolled back before the journal goes forward; history per run scoped by flow id, alert ledger, alerts.json, state and queue steps idempotent and checkpointed; audit row once per op; recover_documents before assign_ids and recover_runtime before the engine is built, retried until done; repeated requests get the stored result, stale ones 409; plan refuses rename_in_progress; alerts.json written atomically; completeness scanner in the test utilities

This commit is contained in:
2026-11-02 21:30:01 +01:00
parent fa2a213631
commit 2d65118d82
9 changed files with 1420 additions and 25 deletions
+28 -11
View File
@@ -49,7 +49,12 @@ from fluksio.flow.plugins import load_plugins
from fluksio.flow.provision import load_provisioners
from fluksio.flow.queue import MemoryWorkQueue, RedisWorkQueue, WorkQueue
from fluksio.flow.remote import RemoteWorkerHub
from fluksio.flow.rename import RenameGate
from fluksio.flow.rename import (
RenameGate,
recover_documents,
recover_runtime,
retry_until_done,
)
from fluksio.flow.resources import (
ResourceAccountant,
fair_share_env,
@@ -295,15 +300,10 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
# Connectors register their node types before any flow is built with them.
load_plugins()
alerts = AlertManager(
event_bus, config=read_alerts_config(), ledger=AlertLedger()
)
execution = ExecutionService(
queue=_work_queue(),
max_workers=settings.FLOW_MAX_WORKERS,
events=event_bus,
max_cascades=settings.FLOW_MAX_CASCADES,
)
# A rename the last process left half done settles its documents
# first: a published document and its draft written apart would
# have different keys, which assigning ids refuses.
await run_in_threadpool(recover_documents, settings.FLOWS_DIR)
# Every flow and dashboard has an id before anything reads one: the
# store's own `_migrate`, the device migrations below and every cache
# after them write documents back with whatever id they read.
@@ -313,6 +313,23 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
# no flow holds any more is passed on as it is, which is the id of a
# flow from before ids.
event_bus.flow_id_of = lambda key: store.key_index().get(key, key)
state = _state_backend()
queue = _work_queue()
# Then the rest of it, before anything reads alerts, devices, modules,
# metrics, flows or runs. Until it is finished nothing is served.
await retry_until_done(lambda: recover_runtime(state, queue), event_bus)
# Work that arrived while a rename held the queue, which a crash
# left behind.
await run_in_threadpool(queue.release_held)
alerts = AlertManager(
event_bus, config=read_alerts_config(), ledger=AlertLedger()
)
execution = ExecutionService(
queue=queue,
max_workers=settings.FLOW_MAX_WORKERS,
events=event_bus,
max_cascades=settings.FLOW_MAX_CASCADES,
)
# The packages node code imports. In the background, because a first
# install of anything substantial takes minutes and `uv` is given five
# of them twice over — held here, the container never answers its
@@ -376,7 +393,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
app.state.worker_hub = worker_hub
controller = FlowController(
store=store,
state=_state_backend(),
state=state,
events=event_bus,
max_workers=settings.FLOW_MAX_WORKERS,
fastapi_app=app,