fix: improve SSE heartbeat and session retry logic in TUI#22151
fix: improve SSE heartbeat and session retry logic in TUI#22151rudalsgecko wants to merge 1 commit intoanomalyco:devfrom
Conversation
- Implement 20s heartbeat timeout in TUI SDKProvider - Add 250ms delay between SSE reconnection attempts to avoid tight loops - Add retry limit (10 attempts) to SessionProcessor - Handle retry exhaustion by halting session with a resumeable AbortedError - Trigger re-sync in SyncProvider on server.connected or reconnectToken change
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Found 1 potential related PR: PR #15436: fix(tui): recover event stream after lock/sleep disconnect This PR addresses similar SSE connection reliability concerns - specifically recovering event streams when the connection is lost (e.g., after lock/sleep). It may have overlapping solutions or context relevant to the heartbeat and retry logic improvements in PR #22151. |
리뷰 의견 (임시)작성자 본인의 셀프 리뷰입니다. 주요 확인 필요 항목을 남깁니다. 🔴 Blocker1. create: (input: Input) => create(input) as Effect.Effect<Handle, never, never>,
🟠 의심2. SessionRetry.exponentialBackoff(...).pipe(Schedule.recurs(RETRY_MAX_ATTEMPTS))Effect에서 두 Schedule을 교차 적용하려면 보통 🟡 개선 포인트3. 들여쓰기 불균형 4. 고정 250ms 재연결 지연 5. 20s heartbeat 타임아웃의 서버 의존성 6. if ((event.payload.type as string) === \"server.heartbeat\") continue
🟢 minor7. 8. 👍 좋은 점
우선순위: 1 → 2 → 3 순서로 확인 권장합니다. |
Blocker / 의심 항목 상세 조사 (업데이트)로컬에서 PR 브랜치를 체크아웃해 실측 에러근본 원인
제안 수정 (diff)- const process = (streamInput: LLM.StreamInput): Effect.Effect<Result, never, never> => {
- return Effect.gen(function* () {
- yield* slog.info(\"process\")
- ctx.needsCompaction = false
- ctx.shouldBreak = (yield* config.get()).experimental?.continue_loop_on_deny !== true
+ const process = Effect.fn(\"SessionProcessor.process\")(function* (streamInput: LLM.StreamInput) {
+ yield* slog.info(\"process\")
+ ctx.needsCompaction = false
+ ctx.shouldBreak = (yield* config.get()).experimental?.continue_loop_on_deny !== true
+ return yield* Effect.gen(function* () {
yield* Effect.gen(function* () {
@@
- }).pipe(Schedule.recurs(SessionRetry.RETRY_MAX_ATTEMPTS)),
+ }).pipe(Schedule.both(Schedule.recurs(SessionRetry.RETRY_MAX_ATTEMPTS))),
),
- Effect.catchAll((e) => {
+ Effect.catch((e) => {
const error = parse(e)
if (MessageV2.APIError.isInstance(error) && error.data.isRetryable) {
return halt(
new MessageV2.AbortedError(
{ message: \"Retry limit reached. Please check your network and continue.\" },
{ cause: e },
),
)
}
- return Effect.fail(e)
+ return halt(e)
}),
- Effect.catchAll((e) => halt(e)),
Effect.ensuring(cleanup()),
)
@@
- }
+ })
return {
...
} satisfies Handle
- })
+ })
- return Service.of({
- create: (input: Input) => create(input) as Effect.Effect<Handle, never, never>,
- })
+ return Service.of({ create })수정 요지
검증수정 후 |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Summary
This PR improves the reliability of SSE connections and session error handling in the TUI by:
SDKProviderto detect stalled connections.SessionProcessorto avoid infinite retry cycles.AbortedErrorwhen the retry limit is reached.SyncProviderupon reconnection.How to use this branch locally
To test or use these improvements, install this branch directly from GitHub:
Using bun:
Using npm: