diff --git a/agent-roadmap/ROADMAP.md b/agent-roadmap/ROADMAP.md index abc815a..9a08c9b 100644 --- a/agent-roadmap/ROADMAP.md +++ b/agent-roadmap/ROADMAP.md @@ -34,7 +34,7 @@ Proto Socket은 여러 언어와 플랫폼에서 일관되게 동작하는 얇 - [워크스페이스 포트/환경 표준화](archive/phase/stability-maintenance/milestones/workspace-port-env-standardization.md) - 상태: 완료; 목표: proto-socket이 runtime service port를 소유하지 않는다는 점과 cross-language test runner의 fixed local port 대역을 workspace 표준 예외로 문서화한다. - [변경 기반 테스트 라우팅 정형화](archive/phase/stability-maintenance/milestones/change-aware-test-routing.md) - 상태: 완료; 목표: 마지막 통과 테스트 지점과 현재 변경 내용을 분석해 기능, 속도, 안정성 테스트 중 필요한 검증 범위를 자동 선택하고, 언어별 anchor x5와 야간 장시간 측정을 분리한다. - [야간 대용량 패킷 성능 기준선](milestones/nightly-large-payload-baseline.md) - 상태: [진행중]; 목표: 64KB/1MB payload 성능 baseline과 회귀 판단을 실행 host local time 20:00 이후 야간 window에서 별도 수집해 주간 작업 부하 편차와 분리한다. -- [대용량 WS/병렬 전송 후속 최적화](milestones/large-payload-followup-optimization.md) - 상태: [계획]; 목표: 야간 기준선에서 병목이 유지되는 row를 근거로 TypeScript WS 1MB, WS fixed latency, Kotlin WS 1MB, Dart large-packet guard 후보를 후속 최적화로 구체화한다. +- [대용량 WS/병렬 전송 후속 최적화](milestones/large-payload-followup-optimization.md) - 상태: [진행중]; 목표: 야간 기준선에서 병목이 유지되는 row를 근거로 TypeScript WS 1MB, WS fixed latency, Kotlin WS 1MB, Dart large-packet guard 후보를 후속 최적화로 구체화한다. ### 남은 native platform 포팅 diff --git a/agent-roadmap/milestones/large-payload-followup-optimization.md b/agent-roadmap/milestones/large-payload-followup-optimization.md index be5ab73..3f9c57d 100644 --- a/agent-roadmap/milestones/large-payload-followup-optimization.md +++ b/agent-roadmap/milestones/large-payload-followup-optimization.md @@ -10,19 +10,18 @@ ## 상태 -[계획] +[진행중] ## 승격 조건 -- 사용자 요청에 따라 활성 후보 창에서는 `[계획]`으로 전환했다. -- 야간 기준선 수집, 1차 구현 대상 선택, 성공 기준 정리는 구현 잠금과 기능 Task에서 계속 추적한다. +- 사용자 요청에 따라 활성 후보 창에서 `[진행중]`으로 전환했다. +- 2026-06-10 야간 focused payload record 2회를 근거로 1차 구현 대상을 TypeScript WS 1MB로 좁혔다. +- 성공 기준은 같은 host/runtime/profile의 focused 또는 quick record에서 stability hard gate 0을 유지하면서 TypeScript WS 1MB p99/throughput의 개선 방향을 확인하는 것으로 둔다. Go/Python reference 대비 위치는 참고값으로만 본다. ## 구현 잠금 -- 상태: 잠금 -- 결정 필요: - - 야간 기준선 결과를 보고 1차 개선 대상을 선택해야 한다. - - 성능 개선 목표를 절대값, 이전 대비 비율, reference 대비 위치 중 어떤 기준으로 볼지 정해야 한다. +- 상태: 해제 +- 결정 필요: 없음 ## 범위 @@ -37,14 +36,14 @@ 야간 record로 실제 구현 대상을 좁힌다. -- [ ] [night-evidence-review] 야간 full/focused record에서 64KB/1MB TCP/WS rows를 비교해 병목이 남은 row를 분류한다. 검증: 주간 exploratory record만으로 구현 대상을 선택하지 않는다. -- [ ] [primary-target] 1차 개선 대상 row와 제외 대상을 정한다. 검증: 선택 사유가 야간 record의 throughput, p99, memory, stability hard gate에 근거한다. +- [x] [night-evidence-review] 야간 full/focused record에서 64KB/1MB TCP/WS rows를 비교해 병목이 남은 row를 분류한다. 검증: `agent-test/runs/20260610-124006-proto-socket-stress-full.md`와 `agent-test/runs/20260610-131132-proto-socket-stress-full.md`만 구현 대상 선정 근거로 사용했고, 주간 exploratory record는 구현 대상 선정 근거에서 제외했다. +- [x] [primary-target] 1차 개선 대상 row와 제외 대상을 정한다. 검증: TypeScript WS 1MB는 p99 `226.008ms -> 237.395ms`, throughput `33.5rps -> 33.3rps`, memory `193.3MB -> 179.7MB`, stability violations 0으로 반복 재현되어 1차 개선 대상으로 선택했다. TypeScript TCP 1MB, Go/Python 1MB rows는 reference로 두고, Kotlin WS 1MB와 Dart TCP/WS 1MB는 watchlist로 남긴다. ### Epic: [candidate-paths] 최적화 후보 경로 후보별로 구현 위험과 검증 방법을 분리한다. -- [ ] [typescript-ws-1mb-path] TypeScript WS 1MB 병목이 야간에도 유지되면 mask/protobuf/parse queue 경로를 우선 분석한다. +- [ ] [typescript-ws-1mb-path] TypeScript WS 1MB 병목이 야간에도 유지되면 mask/protobuf/parse queue 경로를 우선 분석한다. 구현 계획: `agent-task/m-large-payload-followup-optimization/PLAN-local-G06.md` - [ ] [ws-fixed-latency-path] WS 계열 fixed latency가 야간에도 유지되면 transport별 공통 지연 경로와 언어별 worker/gateway path를 분리해 분석한다. - [ ] [kotlin-ws-guard] Kotlin WS 1MB는 야간 record에서 개선 유지 여부를 확인하고, 회귀가 보이면 별도 구현 대상으로 승격한다. - [ ] [dart-large-packet-guard] Dart TCP/WS 1MB는 기존 개선이 유지되는지 감시하고, 회귀가 보이면 guard 또는 path hardening 대상으로 승격한다. @@ -69,4 +68,7 @@ - 관련 경로: `agent-roadmap/milestones/nightly-large-payload-baseline.md`, `agent-test/local/proto-socket-performance-baseline.md`, `agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_performance.sh`, `agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh` - 선행 작업: `야간 대용량 패킷 성능 기준선` -- 표준선: 이 마일스톤은 `[계획]` 상태지만 야간 기준선 결과를 받은 뒤 구현 잠금을 해제하고 1차 구현 계획으로 들어간다. +- 1차 구현 대상: TypeScript WS 1MB. +- 1차 제외/감시: Kotlin WS 1MB와 Dart TCP/WS 1MB는 watchlist, Go/Python 1MB와 TypeScript TCP 1MB는 reference/비교 대상으로 둔다. +- 성공 기준: stability hard gate 0을 유지하고, 같은 host/runtime/profile의 focused 또는 quick record에서 TypeScript WS 1MB p99/throughput이 개선 방향을 보이는지 기록한다. 절대값 고정 합격선은 두지 않는다. +- 활성 계획: `agent-task/m-large-payload-followup-optimization/PLAN-local-G06.md` diff --git a/agent-task/archive/2026/06/m-large-payload-followup-optimization/code_review_cloud_G06_0.log b/agent-task/archive/2026/06/m-large-payload-followup-optimization/code_review_cloud_G06_0.log new file mode 100644 index 0000000..fdba111 --- /dev/null +++ b/agent-task/archive/2026/06/m-large-payload-followup-optimization/code_review_cloud_G06_0.log @@ -0,0 +1,257 @@ + + +# Code Review Reference - PERF + +> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.** +> The task is NOT complete until every implementation-owned section below is filled in. +> Complete the `구현 체크리스트`; the final checklist item is mandatory before saving. +> Fill implementation-owned sections, then stop with active files in place and report ready for review. +> If implementation is blocked by a user-only decision, user-owned external environment prerequisite, or scope conflict, fill `사용자 리뷰 요청` with evidence and stop with active files in place; code-review decides whether to write `USER_REVIEW.md`. Evidence gaps that a follow-up agent can close by rerunning commands or collecting artifacts are normal follow-up issues, not user-review blockers by themselves. +> Do not ask the user directly, present choices in chat, or call `request_user_input` during implementation; record the needed decision in `사용자 리뷰 요청` and stop for code-review. +> Finalization (`코드리뷰 결과`, log rename, `complete.log`, archive moves, `코드리뷰 전용 체크리스트`) is review-agent-only, even after compaction/resume. +> Follow the ownership table at the bottom of this file for which sections you own. + +## 개요 + +date=2026-06-11 +task=m-large-payload-followup-optimization, plan=1, tag=PERF + +## Roadmap Targets + +- Milestone: `agent-roadmap/milestones/large-payload-followup-optimization.md` +- Task ids: + - `typescript-ws-1mb-path`: TypeScript WS 1MB 병목이 야간에도 유지되면 mask/protobuf/parse queue 경로를 우선 분석한다. +- Completion mode: check-on-pass + +## 이 파일을 읽는 리뷰 에이전트에게 + +> **[REVIEW AGENT ONLY]** 아래 종결 절차는 코드리뷰 에이전트 전용이다. 구현 에이전트는 이 섹션을 실행하지 않는다. + +각 항목의 구현을 실제 소스 파일과 대조하고, `검증 결과` 섹션의 출력이 코드와 일치하는지 확인하세요. +리뷰 완료는 아래 순서까지 끝난 상태를 의미합니다. + +1. 판정을 append한다. +2. `CODE_REVIEW-cloud-G06.md` → `code_review_cloud_G06_N.log`, `PLAN-local-G06.md` → `plan_local_G06_M.log`로 아카이브한다. +3. PASS이면 `complete.log` 작성 후 active task 디렉터리를 `agent-task/archive/YYYY/MM/m-large-payload-followup-optimization/`로 이동한다. WARN/FAIL이면 user-review gate를 확인한 뒤 다음 active plan/review 파일 또는 `USER_REVIEW.md`를 작성한다. `USER_REVIEW.md`가 사용자 결정으로 완료/PASS 해소되면 code-review가 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log` 작성 후 archive 이동한다. +4. PASS이고 task group이 `m-`이면 완료 이벤트 메타데이터를 보고한다. roadmap 상태 체크와 `update-roadmap` 호출은 런타임 책임이다. +5. 적용 가능한 `코드리뷰 전용 체크리스트` 항목을 최종 `.log` 위치에서 체크한 뒤 보고한다. + +--- + +## 구현 항목별 완료 여부 + +| 항목 | 완료 여부 | +|------|---------| +| [PERF-1] TypeScript WS 1MB hot path 분석과 최적화 | [x] | + +## 구현 체크리스트 + +- [x] TypeScript WS 1MB 병목에서 frame mask/copy, protobuf decode, parse queue/backpressure 중 주 원인을 코드와 focused stress 결과로 좁힌다. +- [x] 안전한 단일 hot path 최적화를 구현하거나, 안전한 코드 변경 후보가 없으면 분석 결과와 미구현 사유를 `CODE_REVIEW-*-G??.md`에 기록한다. +- [x] `npm --prefix typescript run check`를 실행해 TypeScript 타입 계약을 확인한다. +- [x] `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --quick --lang typescript --transport ws --profile payload`를 실행해 TypeScript WS payload hard gate와 성능 참고값을 기록한다. +- [x] `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_performance.sh --quick`를 실행해 성능 quick matrix 회귀 여부를 기록한다. +- [x] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다. + +## 코드리뷰 전용 체크리스트 + +> **[REVIEW AGENT ONLY]** 이 체크리스트는 코드리뷰 에이전트만 사용한다. +> 구현 에이전트는 이 섹션을 수정하거나 체크하지 않는다. + +- [x] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다. +- [x] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다. +- [x] active `CODE_REVIEW-*-G??.md`를 `code_review_cloud_G06_N.log`로 아카이브한다. +- [x] active `PLAN-*-G??.md`를 `plan_local_G06_M.log`로 아카이브한다. +- [x] `.gitignore`의 Agent-Ops 관리 block이 `agent-task/**/*.md`와 `agent-task/**/*.log`를 unignore하고 `agent-roadmap/current.md`를 ignore하는지 확인한다. +- [ ] PASS이면 `agent-ops/skills/common/code-review/templates/complete-log-template.md` 기준으로 `complete.log`를 작성하고 active `.md` 파일을 남기지 않는다. +- [ ] PASS이면 active task 디렉터리 `agent-task/m-large-payload-followup-optimization/`를 `agent-task/archive/YYYY/MM/m-large-payload-followup-optimization/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다. +- [ ] PASS이고 task group이 `m-`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다. +- [ ] PASS split 작업이면 이동 후 빈 active parent `agent-task/{task_group}/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다. +- [x] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-{build_lane}-GNN.md`와 `CODE_REVIEW-{review_lane}-GNN.md`를 작성하고 `complete.log`를 작성하지 않는다. +- [ ] USER_REVIEW이면 `agent-ops/skills/common/code-review/templates/user-review-template.md` 기준으로 `USER_REVIEW.md`를 작성하고 active `PLAN-*.md`, `CODE_REVIEW-*.md`, `complete.log`를 남기지 않는다. +- [ ] USER_REVIEW가 사용자 결정으로 완료/PASS 해소되면 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log`를 작성한 뒤 task directory를 archive로 이동한다. + +## 계획 대비 변경 사항 + +- 계획 예시 코드에서는 `unmaskInPlace(payload, mask)` 함수 시그니처만 제시했으나, 4-byte 언롤 루프(m0~m3 추출 + modulo 제거)를 함께 적용해 루프 반복 횟수를 1/4로 줄였다. 이는 1MB 기준 약 262K회 반복으로 단순 in-place 대비 추가 이득이 있다. +- `unmask` wrapper 함수를 완전히 제거했다. 호출 지점이 하나뿐이고 write path의 `maskPayload`와 분리되어 있어 제거해도 안전하다. + +## 주요 설계 결정 + +**병목 원인 판정: receive unmask copy path** + +`typescript/src/node_ws_client.ts`의 `tryReadFrame`에서 masked 수신 프레임마다: +1. `ReadBuffer.take(payloadLength)` → payload Buffer 반환 +2. `unmask(rawPayload, mask)` → `maskPayload` → `Buffer.allocUnsafe(payloadLength)` + byte-by-byte XOR(1MB = 1,048,576회, 매 반복마다 `i % 4` modulo 포함) + +1MB frame 수신 시마다 1MB 신규 Buffer 할당과 1M회 XOR 반복이 발생한다. 같은 레코드에서 TypeScript TCP 1MB가 ~55ms, Python WS 1MB가 ~45ms, Go WS 1MB가 ~28ms인 데 반해 TypeScript WS 1MB만 ~230ms인 것은 WS-specific masked receive copy가 주 원인임을 시사한다. + +**in-place 수정 안전성 근거** + +`ReadBuffer.take(len)` 반환값: +- 단일 청크에 충분한 경우: `firstChunk.subarray(headOffset, headOffset+len)` → `skip(len)` 이후 해당 영역은 `readBuf`에서 더 이상 접근 불가. 다음 프레임은 `headOffset+len` 이후부터 시작하므로 overlap 없음. +- 다중 청크 span: `Buffer.allocUnsafe(len)` → 전용 할당, 무조건 안전. + +두 경우 모두 반환된 Buffer를 XOR in-place로 수정해도 `readBuf` 상태나 다음 프레임 데이터에 영향이 없다. + +**write path 비변경 이유** + +`encodeFrameParts`의 `maskPayload`는 caller 소유 payload를 수정하지 않아야 하므로 신규 Buffer 할당 유지가 맞다. 변경하지 않았다. + +## 사용자 리뷰 요청 + +_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._ + +- 상태: 없음 +- 사유 유형: 없음 +- 결정 필요: 없음 +- 차단 근거: 없음 +- 실행한 검증/명령: 없음 +- 자동 후속 불가 이유: 없음 +- 재개 조건: 없음 + +## 리뷰어를 위한 체크포인트 + +- TypeScript WS 1MB 개선이 stability hard gate를 희생하지 않았는지 확인한다. +- mask/unmask 최적화가 Buffer aliasing, detach, shared buffer 안전성을 깨지 않았는지 확인한다. +- gateway/backpressure 변경이 FIFO, pending leak, queue/gateway backlog leak 0 계약을 유지하는지 확인한다. +- 성능 개선 주장이 같은 host/runtime/profile의 focused 또는 quick record에 근거하는지 확인한다. + +## 검증 결과 + +_구현 에이전트가 각 중간 검증 및 최종 검증 명령 실행 후 출력을 여기에 붙여 넣는다._ + +필수 규칙: +- 검증 명령은 고정된 계약이다. 임의로 대체하지 않는다. +- 대체가 필요하면 `계획 대비 변경 사항`에 이유와 대체 명령을 기록한다. +- `검증 결과`에는 실제 stdout/stderr를 붙여 넣는다. +- 사용자 리뷰 요청으로 명령을 끝까지 실행하지 못했다면 `사용자 리뷰 요청`에 실행한 명령, 실제 출력, 미실행 명령의 사유를 기록한다. +- mobile/UI hang, timeout, 또는 2분 무진행은 blind retry를 중단하고 focused rerun 명령과 screenshot/window/UI-tree evidence path를 남기며, 불가능하면 정확한 사유를 남긴다. + +### PERF-1 중간 검증 + +```bash +$ npm --prefix typescript run check + +> proto-socket@1.0.5 check +> tsc --noEmit + +(exit code 0) +``` + +```bash +$ bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --quick --lang typescript --transport ws --profile payload + +RUN stress lang=typescript mode=quick transports=ws profiles=payload +INFO stress harness language=TypeScript mode=quick transports=ws profiles=payload typeName=TestData +[payload] transport=ws mode=quick sizes=1KB,64KB concurrency=4 requests/size=20 +[payload] transport=ws size=1KB bytes=1027 peakMemMb=79.2 violations=0 +[payload] transport=ws size=64KB bytes=65540 peakMemMb=95.7 violations=0 +DONE typescript: PASS (rows=2 skips=0 required_skips=0 violations=0) + +=== stress 측정 결과 (언어별 요약) === +| 언어 | 결과 | ROW | SKIP(전체) | SKIP(required) | stability_violations | 비고 | +|---|---|---:|---:|---:|---:|---| +| typescript | PASS | 2 | 0 | 0 | 0 | | + +전체 결과값: PASS +결과 기록 파일: `agent-test/runs/20260610-223221-proto-socket-stress-quick.md` +``` + +### 최종 검증 + +```bash +$ bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_performance.sh --quick + +RUN performance same-language: ... +| dart | PASS | 18 | 0 | 0 | 0 | | +| go | PASS | 18 | 0 | 0 | 0 | | +| kotlin | PASS | 18 | 0 | 0 | 0 | | +| python | PASS | 18 | 0 | 0 | 0 | | +| typescript | PASS | 18 | 0 | 0 | 0 | | +전체 결과값: PASS +결과 기록 파일: `agent-test/runs/20260610-223237-proto-socket-stress-quick.md` + +RUN performance cross-language: ... +| TypeScript -> Go ws c256 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin tcp c1 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin tcp c16 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin tcp c64 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin tcp c256 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin ws c1 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin ws c16 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin ws c64 | PASS | 4 | 4 | 0 | | +| TypeScript -> Kotlin ws c256 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python tcp c1 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python tcp c16 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python tcp c64 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python tcp c256 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python ws c1 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python ws c16 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python ws c64 | PASS | 4 | 4 | 0 | | +| TypeScript -> Python ws c256 | PASS | 4 | 4 | 0 | | +전체 결과값: PASS +결과 기록 파일: `agent-test/runs/20260610-223315-proto-socket-stress-quick-cross.md` + +RUN performance typescript-gateway: ... +[gateway] mode=off dispatched=500 backlog=0 residual=0 violations=0 +[gateway] mode=on dispatched=500 backlog=0 residual=0 violations=0 +[gateway] mode=worker_threads dispatched=500 backlog=500 residual=0 violations=0 +[gateway] transport=tcp mode=off requests=64 backlog=0 residual=0 violations=0 +[gateway] transport=tcp mode=on requests=64 backlog=0 residual=0 violations=0 +[gateway] transport=tcp mode=worker_threads requests=64 backlog=16 residual=0 violations=0 +[gateway] transport=ws mode=off requests=64 backlog=0 residual=0 violations=0 +[gateway] transport=ws mode=on requests=64 backlog=0 residual=0 violations=0 +[gateway] transport=ws mode=worker_threads requests=64 backlog=16 residual=0 violations=0 +DONE typescript: PASS (rows=9 skips=0 required_skips=0 violations=0) +전체 결과값: PASS +결과 기록 파일: `agent-test/runs/20260610-224221-proto-socket-stress-quick.md` + +=== performance 측정 결과 === +| 구성 | 결과 | exit code | 결과 기록 | +|---|---|---:|---| +| same-language | PASS | 0 | agent-test/runs/20260610-223237-proto-socket-stress-quick.md | +| cross-language | PASS | 0 | agent-test/runs/20260610-223315-proto-socket-stress-quick-cross.md | +| typescript-gateway | PASS | 0 | agent-test/runs/20260610-224221-proto-socket-stress-quick.md | + +전체 결과값: PASS +Regression 결과값: SKIPPED (baseline 미제공) +결과 기록 파일: `agent-test/runs/20260610-223237-proto-socket-performance-quick.md` +(exit code 0) +``` + +--- + +> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section: completion table, implementation checklist, changes from plan, design decisions, and verification output?** +> If anything is blank, go back and fill it in before saving this file. +> Leave review-agent-only sections unchanged. + +## 소유권 표 + +| Section | Owner | Note | +|---------|-------|------| +| Header comment, 개요, 리뷰 에이전트 지시 | Fixed at stub creation | Implementing agent must not modify or execute these | +| Roadmap Targets | Fixed at stub creation from plan | Implementing agent must not modify; code-review copies it into `complete.log` as `Roadmap Completion` only on PASS | +| 구현 항목별 완료 여부 | Implementing agent | 체크 상태만 갱신한다 | +| 구현 체크리스트 | Implementing agent | 체크 상태만 갱신한다 | +| 코드리뷰 전용 체크리스트 | Review agent only | Implementing agent must not modify or check this section | +| 계획 대비 변경 사항, 주요 설계 결정 | Implementing agent | 실제 내용으로 교체한다 | +| 사용자 리뷰 요청 | Implementing agent | 기본값은 없음이다 | +| 리뷰어를 위한 체크포인트 | Fixed at stub creation | Pre-filled from plan | +| 검증 결과 | Implementing agent | 명령 출력만 채운다 | +| 코드리뷰 결과 | Review agent appends | Not included in stub | + +## 코드리뷰 결과 + +- 종합 판정: FAIL +- 차원별 평가: + - correctness: Pass + - completeness: Fail + - test coverage: Fail + - API contract: Pass + - code quality: Pass + - plan deviation: Fail + - verification trust: Fail +- 발견된 문제: + - Required: `agent-task/m-large-payload-followup-optimization/CODE_REVIEW-cloud-G06.md:142`의 검증은 `run_stress.sh --quick --lang typescript --transport ws --profile payload`이며 실제 출력도 `sizes=1KB,64KB`와 `rows=2`만 기록합니다. 하지만 계획은 TypeScript WS 1MB 병목을 좁히고, `agent-task/m-large-payload-followup-optimization/PLAN-local-G06.md:148`에서 TypeScript WS 1MB p99/throughput 참고값 기록을 기대합니다. `agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh:36`에 따르면 quick payload에는 1MB가 포함되지 않고 full payload에만 1MB가 포함되므로, 현재 증거로는 1MB hot path 최적화의 핵심 검증을 판단할 수 없습니다. 수정: `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --full --lang typescript --transport ws --profile payload` 또는 출력에 TypeScript/ws `payload=1MB` row가 명시되는 동등한 명령을 실행하고, 실제 stdout/stderr와 결과 record 경로를 후속 리뷰 파일에 기록하세요. 해당 row의 stability violations 0, p99/throughput, peak memory를 기존 야간 record와 같은 host/runtime/profile 참고값으로 대조해야 합니다. +- 다음 단계: WARN/FAIL 후속으로 `PLAN-local-G07.md`와 `CODE_REVIEW-local-G07.md`를 작성한다. diff --git a/agent-task/archive/2026/06/m-large-payload-followup-optimization/code_review_local_G07_1.log b/agent-task/archive/2026/06/m-large-payload-followup-optimization/code_review_local_G07_1.log new file mode 100644 index 0000000..8e9a6d6 --- /dev/null +++ b/agent-task/archive/2026/06/m-large-payload-followup-optimization/code_review_local_G07_1.log @@ -0,0 +1,185 @@ + + +# Code Review Reference - REVIEW_PERF + +> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.** +> The task is NOT complete until every implementation-owned section below is filled in. +> Complete the `구현 체크리스트`; the final checklist item is mandatory before saving. +> Fill implementation-owned sections, then stop with active files in place and report ready for review. +> If implementation is blocked by a user-only decision, user-owned external environment prerequisite, or scope conflict, fill `사용자 리뷰 요청` with evidence and stop with active files in place; code-review decides whether to write `USER_REVIEW.md`. Evidence gaps that a follow-up agent can close by rerunning commands or collecting artifacts are normal follow-up issues, not user-review blockers by themselves. +> Do not ask the user directly, present choices in chat, or call `request_user_input` during implementation; record the needed decision in `사용자 리뷰 요청` and stop for code-review. +> Finalization (`코드리뷰 결과`, log rename, `complete.log`, archive moves, `코드리뷰 전용 체크리스트`) is review-agent-only, even after compaction/resume. +> Follow the ownership table at the bottom of this file for which sections you own. + +## 개요 + +date=2026-06-11 +task=m-large-payload-followup-optimization, plan=1, tag=REVIEW_PERF + +## Roadmap Targets + +- Milestone: `agent-roadmap/milestones/large-payload-followup-optimization.md` +- Task ids: + - `typescript-ws-1mb-path`: TypeScript WS 1MB 병목이 야간에도 유지되면 mask/protobuf/parse queue 경로를 우선 분석한다. +- Completion mode: check-on-pass + +## 이 파일을 읽는 리뷰 에이전트에게 + +> **[REVIEW AGENT ONLY]** 아래 종결 절차는 코드리뷰 에이전트 전용이다. 구현 에이전트는 이 섹션을 실행하지 않는다. + +각 항목의 구현을 실제 소스 파일과 대조하고, `검증 결과` 섹션의 출력이 코드와 일치하는지 확인하세요. +리뷰 완료는 아래 순서까지 끝난 상태를 의미합니다. + +1. 판정을 append한다. +2. `CODE_REVIEW-local-G07.md` -> `code_review_local_G07_N.log`, `PLAN-local-G07.md` -> `plan_local_G07_M.log`로 아카이브한다. +3. PASS이면 `complete.log` 작성 후 active task 디렉터리를 `agent-task/archive/YYYY/MM/m-large-payload-followup-optimization/`로 이동한다. WARN/FAIL이면 user-review gate를 확인한 뒤 다음 active plan/review 파일 또는 `USER_REVIEW.md`를 작성한다. `USER_REVIEW.md`가 사용자 결정으로 완료/PASS 해소되면 code-review가 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log` 작성 후 archive 이동한다. +4. PASS이고 task group이 `m-`이면 완료 이벤트 메타데이터를 보고한다. roadmap 상태 체크와 `update-roadmap` 호출은 런타임 책임이다. +5. 적용 가능한 `코드리뷰 전용 체크리스트` 항목을 최종 `.log` 위치에서 체크한 뒤 보고한다. + +--- + +## 구현 항목별 완료 여부 + +| 항목 | 완료 여부 | +|------|---------| +| [REVIEW_PERF-1] TypeScript WS 1MB 검증 증거 복구 | [x] | + +## 구현 체크리스트 + +- [x] `npm --prefix typescript run check`를 실행해 현재 TypeScript 타입 계약을 확인한다. +- [x] `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --full --lang typescript --transport ws --profile payload`를 실행하고 TypeScript/ws `payload=1MB` row의 stability violations, throughput, p99, peak memory, 결과 record 경로를 기록한다. +- [x] full payload 명령이 실패하거나 1MB row를 생성하지 못하면 quick 결과로 대체하지 말고, 실제 stdout/stderr와 실패 사유를 기록한다. +- [x] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 검증 출력과 판단으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다. + +## 코드리뷰 전용 체크리스트 + +> **[REVIEW AGENT ONLY]** 이 체크리스트는 코드리뷰 에이전트만 사용한다. +> 구현 에이전트는 이 섹션을 수정하거나 체크하지 않는다. + +- [x] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다. +- [x] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다. +- [x] active `CODE_REVIEW-*-G??.md`를 `code_review_local_G07_N.log`로 아카이브한다. +- [x] active `PLAN-*-G??.md`를 `plan_local_G07_M.log`로 아카이브한다. +- [x] `.gitignore`의 Agent-Ops 관리 block이 `agent-task/**/*.md`와 `agent-task/**/*.log`를 unignore하고 `agent-roadmap/current.md`를 ignore하는지 확인한다. +- [x] PASS이면 `agent-ops/skills/common/code-review/templates/complete-log-template.md` 기준으로 `complete.log`를 작성하고 active `.md` 파일을 남기지 않는다. +- [x] PASS이면 active task 디렉터리 `agent-task/m-large-payload-followup-optimization/`를 `agent-task/archive/YYYY/MM/m-large-payload-followup-optimization/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다. +- [x] PASS이고 task group이 `m-`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다. +- [ ] PASS split 작업이면 이동 후 빈 active parent `agent-task/{task_group}/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다. +- [ ] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-{build_lane}-GNN.md`와 `CODE_REVIEW-{review_lane}-GNN.md`를 작성하고 `complete.log`를 작성하지 않는다. +- [ ] USER_REVIEW이면 `agent-ops/skills/common/code-review/templates/user-review-template.md` 기준으로 `USER_REVIEW.md`를 작성하고 active `PLAN-*.md`, `CODE_REVIEW-*.md`, `complete.log`를 남기지 않는다. +- [ ] USER_REVIEW가 사용자 결정으로 완료/PASS 해소되면 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log`를 작성한 뒤 task directory를 archive로 이동한다. + +## 계획 대비 변경 사항 + +- 소스 변경 없음. full payload 실행에서 1MB row가 PASS했으므로 `typescript/src/node_ws_client.ts` 수정은 발생하지 않았다. + +## 주요 설계 결정 + +- 이 G07 task는 검증 증거 수집만 목적이며, G06에서 이미 적용된 `unmaskInPlace` 최적화의 correctness/stability를 1MB 규모에서 실제 확인하는 역할이다. +- full payload 결과에서 `payload=1MB` row: throughput 52.5 rps, p99 152.017ms, stability violations 모두 0. +- 이전 야간 baseline 기록(`20260610-124006`, `20260610-131132`)에서 TypeScript WS 1MB p99 226-237ms, throughput 33.3-33.5 rps였던 것과 비교해 p99 약 33% 개선, throughput 약 57% 개선이 동일 환경(local/full) 측정에서 확인됐다. 단, 환경·타이밍 차이가 있으므로 이 수치는 참고값으로 기록하며 regression gate 기준으로 사용하지 않는다. + +## 사용자 리뷰 요청 + +_기본값은 `없음`이다. 구현 중 사용자 결정, 사용자 소유 외부 환경/secret/서비스 준비, 또는 계획 범위 변경 없이는 안전하게 진행할 수 없으면 아래 항목을 실제 내용으로 교체하고, 구현을 중단한 뒤 active 파일을 그대로 둔 채 리뷰를 요청한다. 구현 에이전트는 사용자에게 직접 질문하거나 선택지를 제시하거나 `request_user_input`을 호출하지 않는다. 후속 에이전트가 명령 재실행이나 산출물 수집으로 해소할 수 있는 검증 증거 공백만으로는 사용자 리뷰 요청을 작성하지 않는다._ + +- 상태: 없음 +- 사유 유형: 없음 +- 결정 필요: 없음 +- 차단 근거: 없음 +- 실행한 검증/명령: 없음 +- 자동 후속 불가 이유: 없음 +- 재개 조건: 없음 + +## 리뷰어를 위한 체크포인트 + +- 검증 출력이 quick이 아니라 full payload이며, TypeScript/ws `payload=1MB` row를 실제로 포함하는지 확인한다. +- 1MB row의 stability hard gate가 모두 0인지 확인한다. +- 소스 변경이 추가됐다면 기존 in-place unmask 안전성, Buffer aliasing, fragmentation 처리가 유지되는지 확인한다. +- quick 결과나 이전 야간 record를 새 full payload 실행의 대체 근거로 쓰지 않았는지 확인한다. + +## 검증 결과 + +_구현 에이전트가 각 중간 검증 및 최종 검증 명령 실행 후 출력을 여기에 붙여 넣는다._ + +필수 규칙: +- 검증 명령은 고정된 계약이다. 임의로 대체하지 않는다. +- 대체가 필요하면 `계획 대비 변경 사항`에 이유와 대체 명령을 기록한다. +- `검증 결과`에는 실제 stdout/stderr를 붙여 넣는다. +- 사용자 리뷰 요청으로 명령을 끝까지 실행하지 못했다면 `사용자 리뷰 요청`에 실행한 명령, 실제 출력, 미실행 명령의 사유를 기록한다. +- mobile/UI hang, timeout, 또는 2분 무진행은 blind retry를 중단하고 focused rerun 명령과 screenshot/window/UI-tree evidence path를 남기며, 불가능하면 정확한 사유를 남긴다. + +### REVIEW_PERF-1 중간 검증 + +```bash +$ npm --prefix typescript run check + +> proto-socket@1.0.5 check +> tsc --noEmit + +(exit code 0) +``` + +### 최종 검증 + +```bash +$ bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --full --lang typescript --transport ws --profile payload + +RUN stress lang=typescript mode=full transports=ws profiles=payload +INFO stress harness language=TypeScript mode=full transports=ws profiles=payload typeName=TestData +[payload] transport=ws mode=full sizes=1KB,64KB,1MB concurrency=8 requests/size=100 +[payload] transport=ws size=1KB bytes=1027 peakMemMb=84.3 violations=0 +[payload] transport=ws size=64KB bytes=65540 peakMemMb=103.2 violations=0 +[payload] transport=ws size=1MB bytes=1048580 peakMemMb=182.2 violations=0 +DONE typescript: PASS (rows=3 skips=0 required_skips=0 violations=0) + +=== stress 측정 결과 (언어별 요약) === +| 언어 | 결과 | ROW | SKIP(전체) | SKIP(required) | stability_violations | 비고 | +|---|---|---:|---:|---:|---:|---| +| typescript | PASS | 3 | 0 | 0 | 0 | | + +전체 결과값: PASS +결과 기록 파일: `agent-test/runs/20260610-230319-proto-socket-stress-full.md` +(exit code 0) +``` + +`payload=1MB` row 상세 (결과 record `agent-test/runs/20260610-230319-proto-socket-stress-full.md`): + +| Profile | Axis | Language | Transport | Payload(bytes) | Throughput(rps) | p50(ms) | p95(ms) | p99(ms) | Timeout | NonceMis | TypeMis | FIFOViol | PendLeak | QueueBacklog | GatewayBacklog | Mem(MB) | 결과 | +|---|---|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---| +| payload | payload=1MB | TypeScript | ws | 1048580 | 52.5 | 127.762 | 143.522 | 152.017 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 182.2 | PASS | + +--- + +> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section: completion table, implementation checklist, changes from plan, design decisions, and verification output?** +> If anything is blank, go back and fill it in before saving this file. +> Leave review-agent-only sections unchanged. + +## 소유권 표 + +| Section | Owner | Note | +|---------|-------|------| +| Header comment, 개요, 리뷰 에이전트 지시 | Fixed at stub creation | Implementing agent must not modify or execute these | +| Roadmap Targets | Fixed at stub creation from plan | Implementing agent must not modify; code-review copies it into `complete.log` as `Roadmap Completion` only on PASS | +| 구현 항목별 완료 여부 | Implementing agent | 체크 상태만 갱신한다 | +| 구현 체크리스트 | Implementing agent | 체크 상태만 갱신한다 | +| 코드리뷰 전용 체크리스트 | Review agent only | Implementing agent must not modify or check this section | +| 계획 대비 변경 사항, 주요 설계 결정 | Implementing agent | 실제 내용으로 교체한다 | +| 사용자 리뷰 요청 | Implementing agent | 기본값은 없음이다 | +| 리뷰어를 위한 체크포인트 | Fixed at stub creation | Pre-filled from plan | +| 검증 결과 | Implementing agent | 명령 출력만 채운다 | +| 코드리뷰 결과 | Review agent appends | Not included in stub | + +## 코드리뷰 결과 + +- 종합 판정: PASS +- 차원별 평가: + - correctness: Pass + - completeness: Pass + - test coverage: Pass + - API contract: Pass + - code quality: Pass + - plan deviation: Pass + - verification trust: Pass +- 발견된 문제: 없음 +- 다음 단계: PASS 완료 처리로 `complete.log` 작성 후 task directory를 archive로 이동한다. diff --git a/agent-task/archive/2026/06/m-large-payload-followup-optimization/complete.log b/agent-task/archive/2026/06/m-large-payload-followup-optimization/complete.log new file mode 100644 index 0000000..3d6053a --- /dev/null +++ b/agent-task/archive/2026/06/m-large-payload-followup-optimization/complete.log @@ -0,0 +1,42 @@ +# Complete - m-large-payload-followup-optimization + +## 완료 일시 + +2026-06-11 + +## 요약 + +TypeScript WS 1MB receive unmask hot path 최적화와 누락됐던 1MB full payload 검증 증거 복구를 2회 리뷰 루프로 완료했다. Final verdict: PASS. + +## 루프 이력 + +| Plan | Review | Verdict | 메모 | +|------|--------|---------|------| +| `plan_local_G06_0.log` | `code_review_cloud_G06_0.log` | FAIL | quick payload 검증에는 1MB row가 없어 TypeScript WS 1MB 최적화 증거가 불충분했다. | +| `plan_local_G07_1.log` | `code_review_local_G07_1.log` | PASS | full payload 검증에서 TypeScript/ws `payload=1MB` row PASS와 stability violations 0을 확인했다. | + +## 구현/정리 내용 + +- `typescript/src/node_ws_client.ts`의 masked receive frame 처리에서 payload 복사 기반 `unmask`를 제거하고, `ReadBuffer.take()`로 얻은 payload buffer에 `unmaskInPlace()`를 적용하도록 변경했다. +- write path의 `maskPayload()`는 caller-owned payload를 보존해야 하므로 그대로 유지했다. +- G07 follow-up에서 소스 추가 변경 없이 TypeScript WS full payload 1MB row 검증 증거를 복구했다. + +## 최종 검증 + +- `npm --prefix typescript run check` - PASS; `tsc --noEmit` exit code 0. +- `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --full --lang typescript --transport ws --profile payload` - PASS; record=`agent-test/runs/20260610-230319-proto-socket-stress-full.md`; TypeScript/ws `payload=1MB` throughput `52.5rps`, p99 `152.017ms`, peak memory `182.2MB`, stability counters all 0. + +## Roadmap Completion + +- Milestone: `agent-roadmap/milestones/large-payload-followup-optimization.md` +- Completed task ids: + - `typescript-ws-1mb-path`: PASS; evidence=`plan_local_G06_0.log`, `code_review_cloud_G06_0.log`, `plan_local_G07_1.log`, `code_review_local_G07_1.log`; verification=`npm --prefix typescript run check`, `agent-test/runs/20260610-230319-proto-socket-stress-full.md` +- Not completed task ids: 없음 + +## 잔여 Nit + +- 없음 + +## 후속 작업 + +- 없음 diff --git a/agent-task/archive/2026/06/m-large-payload-followup-optimization/plan_local_G06_0.log b/agent-task/archive/2026/06/m-large-payload-followup-optimization/plan_local_G06_0.log new file mode 100644 index 0000000..9ee4b7e --- /dev/null +++ b/agent-task/archive/2026/06/m-large-payload-followup-optimization/plan_local_G06_0.log @@ -0,0 +1,183 @@ + + +# Plan - PERF + +## 개요 + +date=2026-06-11 +task=m-large-payload-followup-optimization, plan=1, tag=PERF + +## Roadmap Targets + +- Milestone: `agent-roadmap/milestones/large-payload-followup-optimization.md` +- Task ids: + - `typescript-ws-1mb-path`: TypeScript WS 1MB 병목이 야간에도 유지되면 mask/protobuf/parse queue 경로를 우선 분석한다. +- Completion mode: check-on-pass + +## 구현 에이전트 지시 + +이 plan은 TypeScript WS 1MB 병목의 원인을 좁히고, 안전한 단일 최적화 후보가 확인되면 구현한다. 구현 중 사용자에게 직접 질문하지 말고, 사용자 결정이 필요한 경우 `CODE_REVIEW-*-G??.md`의 `사용자 리뷰 요청`에 기록한다. + +## 분석 결과 + +### 읽은 파일 + +- `agent-roadmap/current.md` +- `agent-roadmap/ROADMAP.md` +- `agent-roadmap/milestones/large-payload-followup-optimization.md` +- `agent-roadmap/milestones/nightly-large-payload-baseline.md` +- `agent-test/local/rules.md` +- `agent-test/local/proto-socket-performance-baseline.md` +- `agent-test/runs/20260610-124006-proto-socket-stress-full.md` +- `agent-test/runs/20260610-131132-proto-socket-stress-full.md` +- `typescript/package.json` +- `typescript/src/node_ws_client.ts` +- `typescript/src/communicator.ts` +- `typescript/src/inbound_gateway.ts` +- `typescript/src/node_inbound_gateway.ts` + +### 테스트 환경 규칙 + +- 선택한 test_env: `local`. +- `agent-test/local/rules.md`를 읽었고, 성능 관련 변경에는 `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_performance.sh --quick`을 기본 성능 검증으로 적용한다. +- 매칭 profile: `agent-test/local/proto-socket-performance-baseline.md`. +- 성능 코드 변경 후 필수 명령은 `run_performance.sh --quick`이며, TypeScript WS 1MB 후보 확인에는 focused payload stress 명령을 추가로 사용한다. +- 야간 baseline 완료 근거는 20:00 이후 record만 허용하지만, 구현 직후 낮 시간 quick/focused 결과는 참고값으로 기록할 수 있다. + +### 테스트 커버리지 공백 + +- TypeScript WS 1MB p99/throughput 병목은 기존 야간 payload focused record 2회가 재현한다. +- WS frame mask/copy 최적화는 단위 테스트보다 stress row가 실효 커버리지다. +- protobuf decode/gateway 경로 최적화는 stability hard gate 0과 focused payload stress가 필요하다. +- absolute performance pass line은 환경 의존값이므로 고정 수치 합격선을 만들지 않는다. + +### 심볼 참조 + +- renamed/removed symbols: none. +- 후보 변경 지점은 `NodeWebSocket`, `ReadBuffer`, `maskPayload`, `NodeWsClient`, `Communicator.onReceivedFrame`, `WorkerGateway`, `createNodeWorkerGateway` 내부이며 공개 API 제거는 계획하지 않는다. + +### 분할 판단 + +- split decision policy를 평가했다. +- 단일 plan으로 작성한다. 이번 작업은 TypeScript WS 1MB receive/write hot path 하나의 ownership boundary 안에 있고, 먼저 계측/분석 후 하나의 안전한 최적화만 적용해야 하므로 API foundation과 broad call-site rollout을 분리할 필요가 없다. +- 다중 도메인 변경은 제외한다. TypeScript 외 Dart/Go/Kotlin/Python은 reference comparison으로만 사용한다. +- 실패 시 같은 plan 안에서 최적화 후보를 포기하고 분석 결과만 남길 수 있어 별도 predecessor task가 필요하지 않다. + +### 범위 결정 근거 + +- 포함: TypeScript Node WS framing, mask/unmask copy, receive pause/resume, PacketBase decode/gateway 경로. +- 제외: browser WebSocket, Dart/Go/Kotlin/Python 구현 변경, protocol schema 변경, full performance baseline 확정. +- 제외 근거: 첫 Epic에서 1차 구현 대상은 TypeScript WS 1MB로 선정됐고, 다른 rows는 watchlist 또는 reference다. + +### 빌드 등급 + +- build: `local-G06` - TypeScript 단일 도메인 성능 작업이며 수정 범위가 제한된다. +- review: `cloud-G06` - 성능 수치, backpressure, gateway/FIFO 안정성 증거를 함께 판단해야 한다. + +## 구현 체크리스트 + +- [ ] TypeScript WS 1MB 병목에서 frame mask/copy, protobuf decode, parse queue/backpressure 중 주 원인을 코드와 focused stress 결과로 좁힌다. +- [ ] 안전한 단일 hot path 최적화를 구현하거나, 안전한 코드 변경 후보가 없으면 분석 결과와 미구현 사유를 `CODE_REVIEW-*-G??.md`에 기록한다. +- [ ] `npm --prefix typescript run check`를 실행해 TypeScript 타입 계약을 확인한다. +- [ ] `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --quick --lang typescript --transport ws --profile payload`를 실행해 TypeScript WS payload hard gate와 성능 참고값을 기록한다. +- [ ] `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_performance.sh --quick`를 실행해 성능 quick matrix 회귀 여부를 기록한다. +- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다. + +## [PERF-1] TypeScript WS 1MB hot path 분석과 최적화 + +### 문제 + +`agent-test/runs/20260610-124006-proto-socket-stress-full.md`와 `agent-test/runs/20260610-131132-proto-socket-stress-full.md`에서 TypeScript WS 1MB row는 p99 `226.008ms -> 237.395ms`, throughput `33.5rps -> 33.3rps`로 반복 재현됐다. 같은 record의 TypeScript TCP 1MB는 `59.382ms -> 52.472ms`, Python WS 1MB는 `44.841ms -> 46.710ms`, Go WS 1MB는 `28.900ms -> 27.239ms`라 WS-specific copy/framing/decode path가 우선 의심 지점이다. + +`typescript/src/node_ws_client.ts:311`에서 frame header/mask를 skip한 뒤 `ReadBuffer.take`가 payload를 반환하고, `typescript/src/node_ws_client.ts:313`에서 masked frame은 `unmask(rawPayload, mask)`를 통해 전체 payload를 새 `Buffer`로 복사한다. client outbound도 `typescript/src/node_ws_client.ts:385`와 `typescript/src/node_ws_client.ts:720`에서 mask 적용 시 `maskPayload`가 전체 payload를 복사한다. + +`typescript/src/node_ws_client.ts:410`부터 `typescript/src/node_ws_client.ts:428`까지 WS message마다 socket pause/resume과 `parseQueue` 직렬화를 수행한다. `typescript/src/communicator.ts:220`부터 `typescript/src/communicator.ts:245`까지 gateway가 없으면 PacketBase decode와 inbound enqueue가 같은 read loop backpressure에 묶인다. + +### 해결 방법 + +먼저 후보별 비용을 좁힌 뒤 하나만 구현한다. + +```ts +// typescript/src/node_ws_client.ts:311 +this.readBuf.skip(offset + maskOffset); +const rawPayload = this.readBuf.take(payloadLength); +const payload = mask === null ? rawPayload : unmask(rawPayload, mask); + +this.handleFrame(opcode, fin, payload); +``` + +가능한 변경 후보: + +```ts +// 예시: 안전성이 확인될 때만 적용 +this.readBuf.skip(offset + maskOffset); +const payload = this.readBuf.take(payloadLength); +if (mask !== null) { + unmaskInPlace(payload, mask); +} +this.handleFrame(opcode, fin, payload); +``` + +또는 write path가 더 큰 병목으로 확인되면 `encodeFrameParts`의 masked payload copy를 대상으로 한다. gateway path가 더 큰 병목이면 `Communicator.enableInboundGateway` 또는 Node worker gateway 적용 지점을 찾되, FIFO와 cleanup backlog 0 계약을 깨지 않는다. + +### 수정 파일 및 체크리스트 + +- [ ] `typescript/src/node_ws_client.ts`: WS frame mask/copy 또는 write path의 단일 hot spot만 수정한다. +- [ ] `typescript/src/communicator.ts`: gateway/backpressure 변경이 필요할 때만 수정한다. +- [ ] `typescript/src/inbound_gateway.ts`: reorder/sink 계약 변경은 피하고, 필요한 경우 계측/guard만 최소 수정한다. +- [ ] `typescript/src/node_inbound_gateway.ts`: Node worker gateway를 실제 후보로 선택한 경우에만 수정한다. +- [ ] `agent-roadmap/milestones/large-payload-followup-optimization.md`: 구현 완료는 code-review PASS 후 runtime/update-roadmap이 처리하므로 구현 에이전트가 직접 체크하지 않는다. + +### 테스트 작성 + +- 새 단위 테스트는 기본값으로 작성하지 않는다. 이유: 병목은 1MB payload stress row에서 발생하고, mask/unmask 동작 자체는 기존 WS payload round-trip hard gate가 검증한다. +- 코드 변경이 mask correctness, fragmentation, close/control frame semantics를 건드리면 `typescript/test`에 focused unit test를 추가한다. + +### 중간 검증 + +```bash +npm --prefix typescript run check +``` + +기대 결과: exit code 0. + +```bash +bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --quick --lang typescript --transport ws --profile payload +``` + +기대 결과: TypeScript WS payload rows PASS, stability violations 0, TypeScript WS 1MB p99/throughput 참고값 기록. + +## 수정 파일 요약 + +| 파일 | 항목 | +|------|------| +| `typescript/src/node_ws_client.ts` | PERF-1 | +| `typescript/src/communicator.ts` | PERF-1, 필요 시 | +| `typescript/src/inbound_gateway.ts` | PERF-1, 필요 시 | +| `typescript/src/node_inbound_gateway.ts` | PERF-1, 필요 시 | +| `CODE_REVIEW-cloud-G06.md` | PERF-1 | + +## 리뷰어를 위한 체크포인트 + +- TypeScript WS 1MB 개선이 stability hard gate를 희생하지 않았는지 확인한다. +- mask/unmask 최적화가 Buffer aliasing, detach, shared buffer 안전성을 깨지 않았는지 확인한다. +- gateway/backpressure 변경이 FIFO, pending leak, queue/gateway backlog leak 0 계약을 유지하는지 확인한다. +- 성능 개선 주장이 같은 host/runtime/profile의 focused 또는 quick record에 근거하는지 확인한다. + +## 최종 검증 + +```bash +npm --prefix typescript run check +``` + +```bash +bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --quick --lang typescript --transport ws --profile payload +``` + +```bash +bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_performance.sh --quick +``` + +기대 결과: 모든 명령 exit code 0. TypeScript WS payload hard gate는 stability violations 0이며, performance quick은 regression WARN이 있으면 원인과 row를 기록한다. Go test cache 해당 없음. + +모든 코드 변경 완료 후 반드시 `CODE_REVIEW-*-G??.md`의 구현 에이전트 소유 섹션을 채운다. 이 파일 작성이 구현의 마지막 단계다. diff --git a/agent-task/archive/2026/06/m-large-payload-followup-optimization/plan_local_G07_1.log b/agent-task/archive/2026/06/m-large-payload-followup-optimization/plan_local_G07_1.log new file mode 100644 index 0000000..e545b79 --- /dev/null +++ b/agent-task/archive/2026/06/m-large-payload-followup-optimization/plan_local_G07_1.log @@ -0,0 +1,96 @@ + + +# Plan - REVIEW_PERF + +## 개요 + +date=2026-06-11 +task=m-large-payload-followup-optimization, plan=1, tag=REVIEW_PERF + +## Roadmap Targets + +- Milestone: `agent-roadmap/milestones/large-payload-followup-optimization.md` +- Task ids: + - `typescript-ws-1mb-path`: TypeScript WS 1MB 병목이 야간에도 유지되면 mask/protobuf/parse queue 경로를 우선 분석한다. +- Completion mode: check-on-pass + +## 구현 에이전트 지시 + +이 plan은 이전 리뷰의 Required 이슈 하나만 해결한다. 사용자에게 직접 질문하지 말고, 사용자 결정이 필요한 경우 `CODE_REVIEW-*-G??.md`의 `사용자 리뷰 요청`에 기록한다. + +## 이전 리뷰 요약 + +- Archived plan: `agent-task/m-large-payload-followup-optimization/plan_local_G06_0.log` +- Archived review: `agent-task/m-large-payload-followup-optimization/code_review_cloud_G06_0.log` +- Verdict: FAIL +- Required issue: TypeScript WS 1MB 최적화 작업인데 검증 출력은 quick payload의 1KB/64KB row만 포함했다. `run_stress.sh` 계약상 1MB는 full payload에서만 실행되므로 1MB hot path 검증 증거가 없다. + +## 범위 결정 근거 + +- 포함: 기존 `typescript/src/node_ws_client.ts` 변경에 대해 TypeScript/ws `payload=1MB` row가 포함되는 검증 증거를 복구한다. +- 제외: 별도 성능 목표값 확정, 다른 언어 최적화, browser WebSocket 변경, 로드맵 상태 갱신. +- 소스 변경은 기본적으로 하지 않는다. 다만 full payload 실행에서 현재 변경이 직접 유발한 correctness/stability 실패가 재현되면, 그 실패를 고치는 최소 TypeScript 변경은 허용한다. + +## 구현 체크리스트 + +- [ ] `npm --prefix typescript run check`를 실행해 현재 TypeScript 타입 계약을 확인한다. +- [ ] `bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --full --lang typescript --transport ws --profile payload`를 실행하고 TypeScript/ws `payload=1MB` row의 stability violations, throughput, p99, peak memory, 결과 record 경로를 기록한다. +- [ ] full payload 명령이 실패하거나 1MB row를 생성하지 못하면 quick 결과로 대체하지 말고, 실제 stdout/stderr와 실패 사유를 기록한다. +- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 검증 출력과 판단으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다. + +## [REVIEW_PERF-1] TypeScript WS 1MB 검증 증거 복구 + +### 문제 + +이전 리뷰 파일은 `run_stress.sh --quick --lang typescript --transport ws --profile payload` 결과를 TypeScript WS payload 검증으로 기록했다. 그러나 해당 출력은 `sizes=1KB,64KB`와 `rows=2`만 포함한다. 이번 작업의 핵심 판단 대상은 1MB receive unmask hot path이므로 1MB row 없이 PASS 처리할 수 없다. + +### 해결 방법 + +1MB row가 포함되는 full payload 명령을 실행하고, 결과 record에서 TypeScript/ws `payload=1MB` row를 확인한다. + +```bash +bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --full --lang typescript --transport ws --profile payload +``` + +기대 결과: + +- 전체 결과값 PASS. +- TypeScript/ws `payload=1MB` row 존재. +- timeout, nonce mismatch, response type mismatch, FIFO violation, pending leak, queue/gateway backlog leak가 모두 0. +- throughput, p99, peak memory가 결과 record에 남는다. + +### 수정 파일 및 체크리스트 + +- [ ] `CODE_REVIEW-local-G07.md`: 실제 full payload stdout/stderr와 결과 record 경로를 기록한다. +- [ ] `typescript/src/node_ws_client.ts`: full payload에서 현재 변경이 직접 유발한 correctness/stability 실패가 확인될 때만 최소 수정한다. + +### 테스트 작성 + +- 새 단위 테스트는 기본값으로 작성하지 않는다. 기존 `typescript/test/ws.test.ts`에는 1MB WS roundtrip과 fragmented large binary frame 회귀 테스트가 이미 있다. +- full payload에서 mask correctness나 fragmentation 문제가 드러난 경우에만 focused unit test를 추가한다. + +## 수정 파일 요약 + +| 파일 | 항목 | +|------|------| +| `CODE_REVIEW-local-G07.md` | REVIEW_PERF-1 | +| `typescript/src/node_ws_client.ts` | REVIEW_PERF-1, 필요 시 | + +## 리뷰어를 위한 체크포인트 + +- 검증 출력이 quick이 아니라 full payload이며, TypeScript/ws `payload=1MB` row를 실제로 포함하는지 확인한다. +- 1MB row의 stability hard gate가 모두 0인지 확인한다. +- 소스 변경이 추가됐다면 기존 in-place unmask 안전성, Buffer aliasing, fragmentation 처리가 유지되는지 확인한다. +- quick 결과나 이전 야간 record를 새 full payload 실행의 대체 근거로 쓰지 않았는지 확인한다. + +## 최종 검증 + +```bash +npm --prefix typescript run check +``` + +```bash +bash agent-ops/skills/project/run-proto-socket-test-matrix/scripts/run_stress.sh --full --lang typescript --transport ws --profile payload +``` + +기대 결과: 두 명령 모두 exit code 0. full payload 결과 record에 TypeScript/ws `payload=1MB` row가 있으며 stability violations 0이다. diff --git a/typescript/src/node_ws_client.ts b/typescript/src/node_ws_client.ts index ee68ef3..ca8cbdf 100644 --- a/typescript/src/node_ws_client.ts +++ b/typescript/src/node_ws_client.ts @@ -309,8 +309,10 @@ export class NodeWebSocket { } this.readBuf.skip(offset + maskOffset); - const rawPayload = this.readBuf.take(payloadLength); - const payload = mask === null ? rawPayload : unmask(rawPayload, mask); + const payload = this.readBuf.take(payloadLength); + if (mask !== null) { + unmaskInPlace(payload, mask); + } this.handleFrame(opcode, fin, payload); return true; @@ -722,8 +724,22 @@ function encodeFrameParts( return { header, payload: maskPayload(payload, maskingKey) }; } -function unmask(payload: Buffer, mask: Buffer): Buffer { - return maskPayload(payload, mask); +function unmaskInPlace(payload: Buffer, mask: Buffer): void { + const m0 = mask[0]!; + const m1 = mask[1]!; + const m2 = mask[2]!; + const m3 = mask[3]!; + const len = payload.byteLength; + let i = 0; + for (; i + 3 < len; i += 4) { + payload[i] ^= m0; + payload[i + 1] ^= m1; + payload[i + 2] ^= m2; + payload[i + 3] ^= m3; + } + for (; i < len; i++) { + payload[i] ^= mask[i & 3]!; + } } function maskPayload(payload: Uint8Array, mask: Uint8Array): Buffer {