feat: add shared Time_compat, Resilience, Result_extra modules#34
feat: add shared Time_compat, Resilience, Result_extra modules#34
Conversation
Provides Result combinators for list traversal, eliminating the ubiquitous fold_left + Result pattern across MCP projects. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Unified timestamp API for gradual migration from Unix.gettimeofday to Eio.Time.now. Canonical source from masc-mcp, now shared across projects. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Circuit breaker, exponential retry with jitter, and Eio-based timeout. Based on figma-mcp mcp_resilience.ml with Unix.gettimeofday replaced by Time_compat.now for Eio-native timestamp consistency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6eeb58180a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| | CircuitOpen -> CircuitOpen | ||
| | TimedOut -> TimedOut |
There was a problem hiding this comment.
Record circuit failure on TimedOut/CircuitOpen outcomes
When retry runs with a circuit breaker in HalfOpen, circuit_allows sets probe_in_progress <- true before calling f. If f returns TimedOut or CircuitOpen, this branch exits immediately without circuit_record_failure or circuit_record_success, so the probe flag is never cleared and subsequent circuit_allows checks in HalfOpen keep rejecting requests, effectively wedging the breaker.
Useful? React with 👍 / 👎.
| try | ||
| Eio.Time.sleep clock timeout_sec; | ||
| Error "Timeout" | ||
| with Eio.Cancel.Cancelled _ -> Error "Cancelled") |
There was a problem hiding this comment.
Let cancellation propagate from timeout sentinel fiber
Catching Eio.Cancel.Cancelled here converts cancellation into a normal Error path, and the outer match then maps it to Error "Timeout". Under parent-fiber cancellation (e.g., shutdown/abort), this can mask cooperative cancellation as a timeout result instead of propagating cancellation upstream, which breaks expected Eio cancellation behavior.
Useful? React with 👍 / 👎.
Summary
lib/):traverse_listandfilter_map_listcombinators that eliminate the repeated fold_left + Result pattern across MCP projects.eio/): Eio-native timestamp API with Unix fallback, copied verbatim from masc-mcp as the canonical source.eio/): Circuit breaker, exponential retry with jitter, and Eio-based timeout. Based on figma-mcp withUnix.gettimeofdayreplaced byTime_compat.now().Version bumped from 0.12.4 to 0.13.0 (new features, no breaking changes).
Test plan
dune buildpasses with all new modulesdune runtestpasses (490 existing tests unaffected)Generated with Claude Code