Ideas: Should CognitiveCycle tiers have asyncio timeouts? Per-tier vs per-module vs asyncio.wait() strategies #138
web3guru888
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Discussion #136 (Show & Tell on tier-parallel execution) raised this as an open question. It deserves its own thread.
The problem
Once CognitiveCycle uses
asyncio.gather()to run modules concurrently within a tier, what happens if one module hangs? A single slow I/O call — a VectorDB timeout, a blockchain RPC retry, a federated learning round that stalls — blocks the entireasyncio.gather()for that tier. Subsequent tiers cannot start until the gather resolves. If the hang exceeds the tick budget (100ms), the CognitiveCycle misses its real-time constraint.Option A: per-tier
asyncio.wait_for()timeoutWrap the entire
asyncio.gather()in a timeout:Pros: Simple, hard deadline enforced.
Cons:
asyncio.wait_for()cancels all tasks in the gather when the timeout fires — even the ones that were about to complete. A slowblockchainmodule could cancel a fastvectordbresult that was 1ms away from finishing.Option B: per-module
asyncio.wait_for()with individual fallbacksTimeout each module independently:
Pros: Slow modules don't cancel fast ones. Each module gets its own budget.
Cons: A module that is consistently timing out still slows the tier to its individual timeout. Need to combine with circuit breaker (#137) to eventually skip it.
Option C:
asyncio.wait()with FIRST_EXCEPTION + cancellationPros: Clean cancellation of only the slow tasks. Done tasks are preserved.
Cons: More complex; cancelled tasks should ideally have cancellation cleanup handlers.
Key design questions
Should the safety module ever be timed out? If
safetyhangs, should the tick continue (unsafe) or block until it completes (potentially miss real-time)? Argument for special-casing: safety is Tier 0, so if it times out we arguably should not run Tier 1+ at all.What is the right fallback for a timed-out module? Options: (a) stale Blackboard data from previous tick, (b) a sentinel
timed_out=TruePhaseResult, (c) skip Blackboard write entirely. How do downstream modules detect stale data?Should tier timeout be the same as
sum(individual module budgets)in the tier, ormax(individual module budgets)? The point of tier-parallel execution is that the tier should complete inmax(T_i), notsum(T_i). So the tier timeout should be roughlymax(PHASE_BUDGETS_MS[m] for m in tier)plus a small margin, not the sum.Interaction with circuit breaker (Add circuit breaker pattern to CognitiveCycle: auto-disable persistently failing modules with OPEN/HALF_OPEN/CLOSED health states #137): A module that repeatedly times out should eventually trip its circuit breaker (OPEN state) so it is skipped entirely. The timeout itself should count as a "failure" for the health record.
What is your intuition on the right strategy? Option A (tier-level), Option B (per-module), or Option C (asyncio.wait)?
All reactions