refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조

에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Antigravity Agent
2026-07-11 11:05:56 +09:00
parent 6549ead309
commit c24165b8bc
6193 changed files with 1717 additions and 31 deletions
@@ -0,0 +1,103 @@
---
id: web-websocket-reconnect
title: WebSocket 재연결 패턴
category: Coding
status: draft
source_trust_level: B
verification_status: conceptual
created_at: 2026-05-09
updated_at: 2026-05-09
tags: [web, websocket, networking, resilience, vibe-coding]
tech_stack: { language: "TypeScript / browser", applicable_to: ["Web", "Mobile"] }
applied_in: []
aliases: [reconnect, exponential backoff, ping/pong, heartbeat]
---
# WebSocket 재연결 패턴
> 모바일 / 약한 네트워크에서 WebSocket 은 끊긴다. **재연결 + 지수 백오프 + heartbeat + resume offset** 4가지를 안 하면 사용자 경험 박살.
## 📖 핵심 개념
- 끊김 감지: `onclose`, `onerror`, ping timeout
- 재연결: 즉시 X. 지수 백오프 + jitter (1s, 2s, 4s, 8s, max 30s).
- Heartbeat: 30~60초마다 ping. 응답 없으면 재연결.
- Resume: 마지막 받은 메시지 id 보내고 그 이후만 받기.
## 💻 코드 패턴
```ts
class ReliableSocket {
private ws: WebSocket | null = null;
private retries = 0;
private heartbeatTimer: any = null;
private lastSeq = 0;
private closed = false;
constructor(private readonly url: () => string, private readonly onMessage: (data: any) => void) {
this.connect();
}
private connect() {
if (this.closed) return;
const url = new URL(this.url());
url.searchParams.set('lastSeq', String(this.lastSeq)); // resume
this.ws = new WebSocket(url.toString());
this.ws.onopen = () => { this.retries = 0; this.startHeartbeat(); };
this.ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.type === 'pong') return;
if (typeof msg.seq === 'number') this.lastSeq = msg.seq;
this.onMessage(msg);
};
this.ws.onerror = () => this.ws?.close();
this.ws.onclose = () => this.scheduleReconnect();
}
private startHeartbeat() {
this.stopHeartbeat();
this.heartbeatTimer = setInterval(() => {
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(JSON.stringify({ type: 'ping' }));
}, 30_000);
}
private stopHeartbeat() { if (this.heartbeatTimer) clearInterval(this.heartbeatTimer); }
private scheduleReconnect() {
this.stopHeartbeat();
if (this.closed) return;
const base = Math.min(30_000, 1000 * Math.pow(2, this.retries++));
const jitter = Math.random() * base * 0.3;
setTimeout(() => this.connect(), base + jitter);
}
send(data: any) {
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(JSON.stringify(data));
// else: 큐잉 정책 결정 필요 (drop / queue / reject)
}
close() { this.closed = true; this.stopHeartbeat(); this.ws?.close(); }
}
```
## 🤔 의사결정 기준
| 메시지 종류 | 끊김 동안 정책 |
|---|---|
| 실시간 채팅 메시지 | 재연결 후 resume offset 으로 누락 fetch |
| 라이브 시세 / 메트릭 | drop. 최신만 중요 |
| 사용자 액션 (버튼 클릭) | 큐 + 재연결 후 send (idempotency key 필수) |
| 동시 sub 다수 | 한 socket 으로 multiplex (channel id) |
## ❌ 안티패턴
- **즉시 재연결 루프**: 서버 부하 + 네트워크 폭주. 백오프 필수.
- **jitter 없음**: 모든 클라이언트가 같은 시간에 동시 재연결 — thundering herd.
- **heartbeat 없음**: NAT/proxy 가 idle 끊음 (보통 60초). 끊긴지 모름.
- **resume 없음**: 끊긴 동안 메시지 손실. lastSeq 추적.
- **큐 무한 누적**: 끊김 길면 OOM. bounded queue + drop 정책.
- **인증 토큰 만료된 채 재연결**: 401 무한 재시도. 만료면 토큰 갱신 후 재연결.
## 🤖 LLM 활용 힌트
- "지수 백오프 + jitter + heartbeat + resume + bounded queue" 5종 세트 명시.
- 라이브러리 권장: `partysocket`, `socket.io-client`, `reconnecting-websocket`.
## 🔗 관련 문서
- [[Backpressure_Patterns]]
- [[Idempotent_Operations]]