fix(py/core): dynamic action provider cache hardening follow-ups
Found while reviewing #6396. All predate that work, all reproduced, none block the MCP plugin (#6193). Filed so they are not lost.
The first three share a root cause: _do_fetch writes and clears self._cache unconditionally, with no generation or epoch check.
1. invalidate_cache() is dropped when a fetch is in flight. The in-flight _do_fetch overwrites the cache with the pre-invalidation value on completion, so the next caller is served data it was just told was stale. Bounded by the TTL, 3s by default. The MCP client and host call invalidate_cache() from connect, disconnect, reconnect, restart, close and the failed-call path, so a tool listing can lag a server change by one TTL.
2. A failing trace span fails the resolution. _do_fetch runs await self.action.run(metadata) inside the same try that invalidates on error, so an exporter problem both wipes the cache and propagates out of get_action. Observability is load-bearing for action resolution. The listing path passes skip_trace=True and is immune, so this is generate-time only.
3. A failing fetch on one loop wipes a fresh cache from another. except Exception: self.invalidate_cache() is unconditional, so a failure discards a valid entry another loop just wrote. Costs an extra fetch.
4. skip_trace is fixed by whichever caller creates the shared fetch. A listing and a tool resolution inherit each other's tracing intent whenever they coalesce on one loop. #6378 added the first production caller of the listing path, so this is newly reachable. Effect is a missing span, bounded by action.run already being per fetch rather than per resolution.
5. ActionKind.TOOL is the one bucket key that does not work. A dap_fn returning {'tool.v2': [...]} contributes zero catalog rows, because parse_dap_qualified_name rejects inner_kind == ActionKind.TOOL and that enum member is 'tool.v2'. {'tool': ...} is the working spelling, and it does warn, but the constraint is stated nowhere in DapFn or define_dynamic_action_provider. A provider name containing / loses its whole child catalog the same way.
Lower still: listing tasks accumulate in _dap_listing_tasks while a provider is wedged, since the timeout deliberately does not cancel and nothing caps the fetch; and a one-event-loop-iteration window after a fetch fails lets a caller reuse the failure before the done callback clears the entry.
Source: genkit-ai/genkit