Skip to content

perf: AI 핸들러를 별도 Worker 호출로 분리하여 subrequest 예산 독립화#16

Merged
soobing merged 3 commits intomainfrom
perf/10-reduce-subrequests
Apr 16, 2026
Merged

perf: AI 핸들러를 별도 Worker 호출로 분리하여 subrequest 예산 독립화#16
soobing merged 3 commits intomainfrom
perf/10-reduce-subrequests

Conversation

@soobing
Copy link
Copy Markdown
Contributor

@soobing soobing commented Apr 8, 2026

문제

모든 AI 핸들러(tagPatterns, learningStatus, analyzeComplexity)가 하나의 Worker invocation에서 순차 실행되어 50 subrequest 제한을 공유하는 구조적 문제.

핸들러가 추가될수록 전체 subrequest 합산이 한도를 초과하게 되며, 다른 개발자의 변경사항이 기존 핸들러에 영향을 줌.

해결

self-fetch + ctx.waitUntil() 패턴으로 각 AI 핸들러를 별도 Worker invocation에서 실행.

  • /internal/tag-patterns, /internal/learning-status, /internal/complexity-analysis 내부 엔드포인트 추가
  • handlePullRequestEvent에서 ctx.waitUntil(fetch(...)) 로 3개 핸들러를 병렬 디스패치
  • 각 invocation이 독립적인 50 subrequest 예산을 가짐
  • X-Internal-Secret 헤더로 내부 요청 인증
  • INTERNAL_SECRET 미설정 시 기존 방식(동일 invocation 순차 실행)으로 폴백

필요한 설정

wrangler secret put INTERNAL_SECRET  # 임의의 랜덤 문자열

Test plan

  • INTERNAL_SECRET 설정 후 PR opened 시 3개 AI 댓글이 정상 생성되는지 확인
  • Cloudflare Workers 로그에서 subrequest 에러 없는지 확인
  • INTERNAL_SECRET 미설정 시 기존 방식으로 폴백되는지 확인

Closes #10

🤖 Generated with Claude Code

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 8, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
github b49e8b1 Commit Preview URL

Branch Preview URL
Apr 16 2026, 01:24 PM

@soobing soobing changed the title perf: 복잡도 분석 OpenAI 배치 호출로 전환 perf: AI 핸들러를 별도 Worker 호출로 분리하여 subrequest 예산 독립화 Apr 8, 2026
@soobing soobing closed this Apr 8, 2026
@soobing soobing reopened this Apr 16, 2026
@sounmind sounmind self-requested a review April 16, 2026 12:17
soobing and others added 2 commits April 16, 2026 21:48
self-fetch + ctx.waitUntil() 패턴으로 tagPatterns, learningStatus,
complexityAnalysis 각각을 별도 Worker invocation에서 실행하여
50 subrequest 제한을 공유하지 않도록 개선.

Co-Authored-By: sounmind <noreply@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- tests/subrequest-budget.test.js: 5파일 PR 시나리오에서 tagPatterns(22회), postLearningStatus(15회) fetch 호출 수 검증 (Cloudflare 50 한도 하회)
- handlers/internal-dispatch.test.js: 내부 디스패치 엔드포인트 인증·라우팅·에러 처리 테스트
- handlers/webhooks.test.js: AI 핸들러 self-fetch 디스패치 통합 테스트 추가
- AGENTS.md, README.md: AI 핸들러 Worker 분리 아키텍처 다이어그램 및 테스트 실행 가이드
- integration.yaml: vi.mock 전역 누출 회피를 위해 bun test handlers/, tests/ 를 별도 스텝으로 실행
- handlers/webhooks.js, wrangler.jsonc: WORKER_URL 을 명시적 env 로 요구하고 기본값은 wrangler vars 로 이동

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@soobing soobing force-pushed the perf/10-reduce-subrequests branch from d01cfb5 to aa3313d Compare April 16, 2026 13:20
describe/it 블록 제목을 모두 한국어로 통일.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@soobing soobing merged commit 06e2fb0 into main Apr 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

리트코드 스터디 재수하시는 분들 풀이한 문제 카운팅 해결

2 participants