Here’s a minimal, idiomatic Effect integration based on current repo structure.
What I found
- PR context loading is currently orchestrated in UI (
Promise.all in Sidebar) at
/home/mark/sandbox/personal/pr-review-chatbot/src/components/Sidebar.tsx (around loadPullRequestContext).
- GitHub error mapping logic already exists via
GitHubApiError / parseGitHubError in
/home/mark/sandbox/personal/pr-review-chatbot/src/services/github.ts.
GitHubApiErrorData shape is defined in
/home/mark/sandbox/personal/pr-review-chatbot/src/types/index.ts.
- Redux resource state is already structured to hold PR context pieces in
/home/mark/sandbox/personal/pr-review-chatbot/src/store/slices/prsSlice.ts.
Exact files to touch (minimal)
/home/mark/sandbox/personal/pr-review-chatbot/package.json
/home/mark/sandbox/personal/pr-review-chatbot/src/services/prContextLoader.ts (new)
- single Effect program that loads PR metadata + files/comments/reviews/commits.
/home/mark/sandbox/personal/pr-review-chatbot/src/services/github.ts
- export a reusable
toGitHubApiErrorData(error, fallbackUserMessage) helper (so Effect path and thunks share one mapper).
/home/mark/sandbox/personal/pr-review-chatbot/src/store/slices/prsSlice.ts
- add
fetchPRContext thunk that runs the Effect program (Effect.runPromise) and writes all resources.
/home/mark/sandbox/personal/pr-review-chatbot/src/components/Sidebar.tsx
- replace manual metadata +
Promise.all([...]) orchestration with one dispatch(fetchPRContext(...)).
/home/mark/sandbox/personal/pr-review-chatbot/src/store/slices/prsSlice.test.ts
- add/adjust tests for single-loader success/failure/stale-request behavior.
/home/mark/sandbox/personal/pr-review-chatbot/src/services/prContextLoader.test.ts (new)
- focused tests for timeout/retry/error mapping behavior.
Optional cleanup (small):
8. /home/mark/sandbox/personal/pr-review-chatbot/src/store/slices/watchedReposSlice.ts
- reuse shared
toGitHubApiErrorData to remove duplicate mapper.
Idiomatic Effect pattern to use
Use a small wrapper for Promise interop + timeout + conditional retry + error mapping:
import { Effect, Schedule } from "effect";
import { GitHubApiError, toGitHubApiErrorData } from "./github";
const withResilience = <A>(
thunk: () => Promise<A>,
fallbackUserMessage: string
) =>
Effect.tryPromise({
try: thunk,
catch: (error) => toGitHubApiErrorData(error, fallbackUserMessage),
}).pipe(
Effect.timeoutFail(() =>
toGitHubApiErrorData(
new Error("GitHub request timed out"),
"GitHub request timed out. Please retry."
)
, "12 seconds"),
Effect.retry({
schedule: Schedule.exponential("250 millis").pipe(Schedule.recurs(2)),
while: (e) => e.code === "NETWORK_ERROR", // keep minimal + safe
})
);
Then compose context loading with parallel fetches:
const loadPRContextEffect = Effect.gen(function* () {
const pr = yield* withResilience(
() => service.getPullRequest(owner, repo, prNumber),
"Failed to load pull request metadata."
);
const [files, comments, reviewComments, reviews, commits] = yield* Effect.all(
[
withResilience(() => service.getPRFiles(owner, repo, prNumber), "Failed to load pull request files."),
withResilience(() => service.getPRComments(owner, repo, prNumber), "Failed to load pull request comments."),
withResilience(() => service.getPRReviewComments(owner, repo, prNumber), "Failed to load pull request review comments."),
withResilience(() => service.getPRReviews(owner, repo, prNumber), "Failed to load pull request reviews."),
withResilience(() => service.getPRCommits(owner, repo, prNumber), "Failed to load pull request commits."),
],
{ concurrency: "unbounded" }
);
return { pr, files, comments, reviewComments, reviews, commits };
});
Why this is the best minimal path
- Keeps your existing Redux/UI shape intact.
- Moves orchestration out of component code.
- Gives declarative timeout/retry/parallel semantics in one place.
- Preserves existing
GitHubApiErrorData contract for rejected thunks and UI error display.