Repository navigation
perf(session): 매 스텝 summarize 가 세션 전체를 읽지 않게 하기 (upstream #30127) - #335
Merged
Merged
Conversation
…0127) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
배경
opencode 컨테이너(2GiB) OOM 대응의 세 번째 단계입니다(#333 턴 요약, #334 prune). dev 실측(#334)에서 남은 OOM 은 매 스텝 도는
SessionSummary.summarize가 세션 전체를 읽는 구간에서 났습니다. 이 함수는 스텝마다(processor.tsstep-finish,prompt.ts첫 스텝)Session.messages로 세션 전체를 올린 뒤 snapshot 해시로 diff 를 계산합니다.그런데 우리 환경에서는 snapshot 이 구조적으로 꺼져 있습니다. 작업 폴더의
.git은 project id 마커라(enk/workspace-repo.ts)git rev-parse에 실패해 프로젝트vcs가 비고, snapshot 은vcs === "git"일 때만 켜집니다. 10월 OOM 팀 4곳의 step part 약 2.3만 개, dev 팀 266 의 208개 모두 snapshot 이 없었고, 저장된 턴 diff 도 전부[]였습니다. 즉 매 스텝 세션 전체를 읽고 빈 결과를 쓰고 있었습니다.upstream 은 V1 에서 같은 문제를 anomalyco/opencode#30127(2026-05-31, 포크 분기 이후)로 고쳤고, V2 는 매 스텝 요약을 없애고 요청 시 인덱스로 필요한 행만 읽습니다.
변경사항
summarize: 세션 요약은 0,session.diff이벤트는 빈 목록으로 보낸 뒤,snapshot: false면 세션을 읽지 않고 끝냅니다. snapshot 이 켜진 경우에만 세션을 읽어 턴 diff 를 질문 메시지에 남깁니다.SessionSummary.diff:messageID가 없으면(세션 전체 diff) 빈 목록, 있으면 그 질문 메시지에 저장된 턴 diff 를 돌려줍니다.Session.diff(공유 기능용)도 빈 목록을 돌려줍니다.docker/opencode.jsonc끝에"snapshot": false를 넣어(develop 의 permission 변경과 충돌하지 않게 파일 끝에 둠) 파드에서 위 조기 종료가 타게 했습니다. 원래 꺼져 있던 기능이라 다른 동작은 바뀌지 않습니다.revert.ts)의 diff 계산은 그대로입니다.대안 분석
summary: { diffs: [] }를 쓰지 않습니다. 이 값을 읽는 곳(웹session.tsx, UImessage-nav.tsx·session-turn.tsx, 서버 diff API)은 모두summary?.diffs ?? []로 처리하고, rails·어드민·vite·user-rails 는 읽지 않아 화면과 동작은 같습니다.검증
test/session/summary.test.ts3개Session.messages를 부르지 않고 빈 요약과 빈 diff 이벤트만 남김test/session,test/server,test/share369 pass, typecheck 통과10월 OOM 팀 DB 실측 (로컬 Docker Linux, bun 1.4.4)
운영 어드민에서 받은 10월 OOM 팀 4곳의 DB 사본(현재 저장 형식), 팀별 가장 큰 메인 세션의 마지막 질문으로
SessionSummary.summarize를 5번(스텝 5번) 호출했습니다. 설정은 파드와 같은 방식(OPENCODE_CONFIG_DIR)으로snapshot: false만 넣었고, 예전 코드는 main 입니다. 추가 메모리는 프로세스 기본(약 225MB)을 뺀VmHWM피크의 3회 중앙값입니다.세션 요약 값(추가·삭제 0, 파일 0)은 두 코드가 같습니다. 1955 팀은 해커톤 동안 이 호출이 약 4,400번 있었습니다.
dev 실측: 같은 세션으로 기준(A1+A3) 이미지와 A2 이미지 비교 (2026-11-10)
팀 266 세션(메시지 약 140개)의 오래된 도구 part 20개에 8MB 씩
metadata.diff(약 160MB)를 넣고 그 뒤 도구 결과 하나에 정리 표시를 해 실제 긴 세션처럼 만들었습니다. 화면을 닫고 API 로 같은 요청을 보냈습니다. 파드/config응답에서snapshot: false가 적용된 것을 확인했습니다.2026-11-10T17-20-14(A1, A3)2026-11-10T21-08-25session.diff이벤트와 버전 기록 저장(history … saved)은 매 턴 정상이었고, 참가자 화면도 정상으로 열렸습니다.🤖 Generated with Claude Code