[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
+222 -42
View File
@@ -2,66 +2,246 @@
id: wiki-2026-0508-workflow-integrity
title: Workflow Integrity
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [P-Reinforce-AUTO-WFIN-001]
aliases: [Workflow Integrity, Pipeline Integrity, Process Integrity]
duplicate_of: none
source_trust_level: A
confidence_score: 0.94
tags: [auto-reinforced, workflow, inteGrity, Quality-Control, Operations, process-Optimization]
confidence_score: 0.9
verification_status: applied
tags: [workflow, integrity, reliability, idempotency, saga, durable-execution]
raw_sources: []
last_reinforced: 2026-04-20
last_reinforced: 2026-05-10
github_commit: pending
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
tech_stack:
language: TypeScript
framework: Temporal / Inngest / Restate
---
# [[Workflow-Integrity|Workflow-Integrity]]
# Workflow Integrity
## 📌 한 줄 통찰 (The Karpathy Summary)
> "무너지지 않는 업무의 흐름: 각 단계가 약속된 규칙과 품질 기준을 충실히 지키며 유기적으로 연결되어, 전체 결과물의 신뢰성을 보장하는 업무 프로세스의 도덕성."
## 한 줄
> **"매 step 의 fail 해도, 매 workflow 의 correct"**. 매 distributed workflow 의 integrity property — 매 idempotency, 매 atomicity, 매 ordering, 매 exactly-once effect 의 통한 매 partial failure 의 resilience. 매 2026 의 표준 tooling: Temporal / Inngest / Restate / Cloudflare Durable Objects — 매 durable execution 의 paradigm.
## 📖 구조화된 지식 (Synthesized Content)
워크플로우 무결성(Workflow-Integrity)은 업무의 전 과정이 변조되거나 생략됨 없이 설계된 표준 절차에 따라 정확하고 일관되게 수행되고 있음을 보장하는 품질 관리 개념입니다.
## 매 핵심
1. **무결성 유지 요소**:
* **Data Consistency**: 전 단계의 산출물이 다음 단계의 입력물과 논리적으로 일치해야 함.
* **Process Verification**: 각 단계가 완료될 때마다 사전에 정의된 체크리스트를 통과해야 함 (Gatekeepers).
* **Audit Trail**: 업무의 이력과 결정 근거가 투명하게 기록되어 사후 추적이 가능해야 함.
* **Error Handling**: 예외 상황 발생 시 프로세스가 붕괴하지 않고 정해진 복구 경로(Recovery Path)를 따라야 함.
2. **지능형 워크플로우**:
* AI 에이전트 간의 협업(Chain)에서 앞 단계의 AI가 생성한 오답(Hallucination)이 전체 워크플로우를 오염시키지 않도록 하는 'Cross-check' 메커니즘 구축.
### 매 integrity properties
- **Idempotency**: 매 same input 의 retry 가 매 single effect.
- **Atomicity**: 매 step 의 all-or-nothing — 매 partial commit 의 X.
- **Ordering**: 매 causally-dependent step 의 sequence 의 preserve.
- **Exactly-once effect**: 매 at-least-once delivery + idempotent handler.
- **Compensation**: 매 saga — 매 forward fail 의 rollback action.
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌**: 과거에는 결과만 좋으면 과정의 사소한 누락은 묵인하는 정책이었으나, 현대의 고신뢰 사회 정책은 '과정의 정당성'이 결과의 가치를 결정한다는 '무결성 제일 정책'으로 이동함(RL Update).
- **정책 변화(RL Update)**: 특히 AI 모델 학습 및 배포 정책에서, 데이터 수집부터 최종 모델 서빙까지의 전 과정(Lineage)을 투명하게 증명하지 못하면 상용화할 수 없는 'AI 공급망 무결성 정책'이 강화됨.
### 매 failure modes
- **Crash mid-step**: 매 worker 의 die — 매 durable log 의 resume.
- **Duplicate delivery**: 매 message broker 의 redeliver — 매 idempotency key 의 dedupe.
- **Out-of-order**: 매 parallel branch 의 racing — 매 versioned write.
- **Network partition**: 매 split-brain — 매 fencing token 의 exclude stale leader.
## 🔗 지식 연결 (Graph)
- [[Operations-Research|Operations-Research]], [[Safety & Reliability|Safety & Reliability]], [[Theory of Constraints (TOC)|Theory of Constraints (TOC)]], [[Software-Design-Principles|Software-Design-Principles]], [[Ps-Reinforce|Ps-Reinforce]]
- **Modern Tech/Tools**: CI/CD pipelines, [[Blockchain|Blockchain]] for audit logs, Workflow orchestration (Airflow, Temporal).
---
### 매 응용
1. 매 payment processing — 매 charge + ledger + email 의 saga.
2. 매 onboarding workflow — 매 user create + Stripe customer + Slack notify.
3. 매 ETL pipeline — 매 extract + transform + load 의 retry safe.
4. 매 LLM agent loop — 매 tool call 의 durable resume.
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
## 💻 패턴
**언제 이 지식을 쓰는가:**
- *(TODO)*
### Idempotency key (HTTP)
```typescript
import { Hono } from "hono";
**언제 쓰면 안 되는가:**
- *(TODO)*
const app = new Hono();
const seen = new Map<string, { status: number; body: unknown }>(); // 매 prod 의 Redis
## 🧪 검증 상태 (Validation)
app.post("/charge", async (c) => {
const key = c.req.header("Idempotency-Key");
if (!key) return c.json({ error: "Idempotency-Key required" }, 400);
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
const cached = seen.get(key);
if (cached) return c.json(cached.body, cached.status);
## 🧬 중복 검사 (Duplicate Check)
const result = await stripe.charges.create(await c.req.json());
seen.set(key, { status: 200, body: result });
return c.json(result);
});
```
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
### Temporal workflow (durable execution)
```typescript
import { proxyActivities, defineSignal, setHandler } from "@temporalio/workflow";
## 🕓 변경 이력 (Changelog)
const { chargeCard, sendEmail, recordLedger } = proxyActivities<typeof activities>({
startToCloseTimeout: "30s",
retry: { maximumAttempts: 5, initialInterval: "1s", backoffCoefficient: 2 },
});
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
export async function processOrderWorkflow(orderId: string, amount: number) {
// 매 step 1: charge — 매 retry 의 idempotent (Stripe idempotency key)
const charge = await chargeCard({ orderId, amount });
// 매 step 2: ledger — 매 fail 시 charge 의 refund (compensation)
try {
await recordLedger({ orderId, chargeId: charge.id, amount });
} catch (err) {
await proxyActivities({ ...defaults, scheduleToCloseTimeout: "1m" })
.refundCard({ chargeId: charge.id });
throw err;
}
// 매 step 3: email — 매 fail 의 non-blocking (best effort)
await sendEmail({ orderId }).catch(() => {});
return { orderId, chargeId: charge.id };
}
```
### Saga compensation pattern
```typescript
class Saga {
private compensations: Array<() => Promise<void>> = [];
async run<T>(forward: () => Promise<T>, backward: (result: T) => Promise<void>): Promise<T> {
const result = await forward();
this.compensations.push(() => backward(result));
return result;
}
async rollback() {
for (const comp of this.compensations.reverse()) {
try { await comp(); }
catch (e) { logger.error("매 compensation failed", e); }
}
}
}
async function bookTrip() {
const saga = new Saga();
try {
const flight = await saga.run(() => bookFlight(), f => cancelFlight(f.id));
const hotel = await saga.run(() => bookHotel(), h => cancelHotel(h.id));
const car = await saga.run(() => bookCar(), c => cancelCar(c.id));
return { flight, hotel, car };
} catch (err) {
await saga.rollback();
throw err;
}
}
```
### Inngest function (event-driven durable)
```typescript
import { inngest } from "./client";
export const onUserSignup = inngest.createFunction(
{ id: "user-signup", retries: 3 },
{ event: "user/created" },
async ({ event, step }) => {
const customer = await step.run("create-stripe-customer", () =>
stripe.customers.create({ email: event.data.email })
);
await step.run("save-customer-id", () =>
db.user.update({ where: { id: event.data.userId }, data: { stripeId: customer.id } })
);
await step.sleep("wait-1h", "1h");
await step.run("send-welcome-email", () =>
resend.emails.send({ to: event.data.email, subject: "환영합니다", html: "..." })
);
}
);
```
### Outbox pattern (transactional message)
```typescript
async function createOrderWithOutbox(order: Order) {
await db.$transaction([
db.order.create({ data: order }),
db.outbox.create({ data: {
topic: "order.created",
payload: order,
status: "pending",
}}),
]);
// 매 separate worker 의 outbox 의 poll, 매 message broker 의 publish
}
// Worker
async function flushOutbox() {
const pending = await db.outbox.findMany({ where: { status: "pending" }, take: 100 });
for (const row of pending) {
await broker.publish(row.topic, row.payload);
await db.outbox.update({ where: { id: row.id }, data: { status: "sent", sentAt: new Date() } });
}
}
```
### Fencing token (split-brain prevention)
```typescript
async function acquireLockWithFencing(key: string, ttl: number): Promise<number> {
const token = await redis.incr(`fencing:${key}`); // 매 monotonic
const ok = await redis.set(`lock:${key}`, token, "PX", ttl, "NX");
if (!ok) throw new Error("매 lock held");
return token;
}
async function writeWithFence(key: string, value: unknown, fenceToken: number) {
// 매 storage layer 의 fence token 의 check — 매 stale leader 의 reject.
await db.execute(sql`
UPDATE resource SET value = ${value}, fence = ${fenceToken}
WHERE key = ${key} AND fence < ${fenceToken}
`);
}
```
### Exactly-once via dedupe table
```sql
CREATE TABLE message_dedupe (
message_id TEXT PRIMARY KEY,
processed_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- 매 handler 의 inside transaction
INSERT INTO message_dedupe(message_id) VALUES ($1)
ON CONFLICT DO NOTHING RETURNING message_id;
-- 매 RETURNING 의 empty 면 already processed.
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| 매 simple webhook | Idempotency key + dedupe table |
| 매 multi-step business workflow | Temporal / Inngest — durable execution |
| 매 cross-service transaction | Saga + compensation |
| 매 transactional msg dispatch | Outbox pattern mandatory |
| 매 leader election + write | Fencing token mandatory |
**기본값**: Inngest (small / event-driven) → Temporal (large / mission-critical) → Saga (cross-service).
## 🔗 Graph
- 부모: [[Distributed_Systems]] · [[Reliability_Engineering]]
- 변형: [[Saga]] · [[Outbox_Pattern]] · [[Two_Phase_Commit]]
- 응용: [[Payment_Processing]] · [[Order_Workflow]] · [[Agent_Loop]]
- Adjacent: [[Idempotency]] · [[Durable_Execution]] · [[Event_Sourcing]] · [[CQRS]]
## 🤖 LLM 활용
**언제**: 매 workflow design 의 review, 매 failure mode enumeration, 매 saga compensation 의 draft.
**언제 X**: 매 fencing token 의 storage check 의 hand-write — 매 race subtle.
## ❌ 안티패턴
- **Retry without idempotency**: 매 double-charge.
- **Atomicity by hope**: 매 try/catch 의 의지 — 매 crash 의 ignore.
- **Ordering via timestamp**: 매 clock skew — 매 logical clock 의 use.
- **Saga without compensation**: 매 partial state forever.
- **Outbox 의 skip**: 매 DB commit + publish 의 separate — 매 lost message.
## 🧪 검증 / 중복
- Verified (Temporal docs, Inngest engineering blog, Pat Helland "Life beyond Distributed Transactions").
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — full content with idempotency/Temporal/saga/outbox/fencing patterns |