Technical Architecture
Named after Hangu Pass (函谷关)—the fortified chokepoint where a single gate held off coalition armies—Hangoo separates perimeter deception from deterministic database commit verification across three workspace packages:
@sentinel-gate/edge-sensor: Cloudflare Worker + SQLite Durable Object (SESSION_DO) performing in-memory OpenAPI 3.1 canary injection, HMAC-SHA256__Host-sg_sidsession cookies, UI route dwell checks (≥ 800ms), andHTTP 200 OKslow-drip tarpits.@sentinel-gate/policy-pdp: Model-free TypeScript Policy Decision Point stripping untrusted prompt text (ticket_body,llm_summary), enforcingX-Agent-Capability(kya.v1) scopes, and locking SMS/email OTP for72hafter contact edits.@sentinel-gate/commit-pep: Inline Policy Enforcement Point verifying cached WebCryptoEd25519key-rings,RFC 8785canonicalSHA-256parameter and pre-state hashes, and single-use RedisSET ... EX 300 NXnonces insideSELECT ... FOR UPDATE.
MandateV1 Wire Specification
Consequential mutations follow a deterministic 3-step handshake: POST /v1/evaluate returns 428 STEP_UP_REQUIRED (or mints immediately for low-tier autonomous KYA caps), step-up approval mints a 90-second MandateV1, and the backend burns jti atomically before committing.
{
"ver": "mandate.v1",
"jti": "019386b4-7c2a-7000-8a11-9f4c2e10b831",
"iat": 1796179500,
"exp": 1796179590,
"actor": {
"sub": "usr_94821",
"actor_type": "delegated_agent",
"agent_id": "agt_support_tier2",
"kya_scope": "propose_only"
},
"intent": {
"method": "POST",
"route": "/api/v1/payouts/destination",
"target_account": "acct_demo_88210",
"params_jcs_sha256": "38b58f24d1e2ef84b838c17a9f2f95d629d4781f9be9c8e18cf4a8c32a9d2210",
"pre_state_sha256": "8f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4"
},
"approval": {
"policy_rev": "2026-12-03.1",
"decision": "ALLOW_COMMIT",
"verified_channel": "pre_recovery_passkey",
"approver_sub": "usr_94821"
},
"sig": "ed25519:9d5a8b03c142f019e7a2b44c98e120f7b3a1c55d..."
}
15-Line Backend Commit SDK
Acquire the database row lock first so currentPreState reflects any concurrent account recovery edits, then call actionGate.verifyAndConsume() before executing UPDATE.
export async function updatePayoutAccount(req: Request, dto: PayoutDto) {
return db.transaction(async (tx) => {
const [account] = await tx
.select()
.from(accounts)
.where(eq(accounts.id, dto.accountId))
.for("update");
await actionGate.verifyAndConsume({
mandateHeader: req.headers.get("x-action-mandate") ?? undefined,
expectedMethod: "POST",
expectedRoute: "/api/v1/payouts/destination",
targetAccount: account.id,
canonicalParams: dto, // binds dto.newAccountNo & dto.bankBic
currentPreState: toCanonicalPreState(account),
});
return tx.update(accounts)
.set({ payoutDest: dto.newAccountNo })
.where(eq(accounts.id, account.id));
});
}
Coding Agent Integration Prompt
Paste this specification into Cursor, Claude Code, or Codex to wire Stage 1 (Monitor) and Stage 2 (Enforce) automatically:
# Hangoo (T800 // Sentinel-Gate v0.2.0) — Integration Spec 1. Stage 1 (Passive Edge Monitor — Zero Backend Edits): - Deploy `@sentinel-gate/edge-sensor` on Cloudflare Workers (`GATEWAY_MODE=MONITOR`, `SESSION_DO` SQLite Durable Object). - Inject OpenAPI decoys (`/api/v1/internal/tpa-balance-sync`, `_bypass_cooldown`) and allowlist QA/partner `X-Agent-Capability` tokens. 2. Stage 2 (Authoritative Commit Gate — 15 Lines): - Install `@sentinel-gate/commit-pep` and `@sentinel-gate/mandate-core`. - Inside `SELECT ... FOR UPDATE`, call `await actionGate.verifyAndConsume(...)` before `UPDATE`. - On `GATE_UNAVAILABLE_QUEUE_REVIEW`, return HTTP 202 and queue into `pending_mutations`.
Allowlists, Recovery Locks & Outage Fail-Safes
Partner SDKs, Postman & Watermarks
Compiled production UIs only call documented routes, giving near-zero end-user noise. Automated schema readers (Postman imports, SDK generators, DAST scanners) bypass decoys via CIDR allowlists or signed X-Agent-Capability headers. Every synthetic tarpit stream embeds an explicit canary_trace_id so developers recognize decoy responses immediately in logs.
72h Post-Recovery Quarantine & Redis Outages
If contact_changed_at is within 72 hours, sms_otp and email_otp are stripped (403 UNTRUSTED_RECOVERY_CHANNEL), requiring a pre-recovery passkey or dual-control ops approval. If Redis drops in ENFORCE mode, reads stay live while writes queue safely as HTTP 202 PENDING_OUTAGE_REVIEW.
Measured Latency Benchmarks (0.187 ms p99)
Measured across 1,000 warm samples after 200 warmups on Apple M4 / Node.js v24.14.1 (pnpm bench:assert) over localhost TCP Redis 7. Excludes application database row-lock contention and wide-area network RTT.
| Component | Store | p50 | p95 | p99 | PRD Budget |
|---|---|---|---|---|---|
| Edge Sensor (GET pass-through) | in-memory |
0.010 ms | 0.019 ms | 0.028 ms | ≤ 1.5 ms |
| Edge Sensor (GET pass-through) | redis-tcp |
0.415 ms | 0.510 ms | 0.879 ms | ≤ 1.5 ms |
Policy PDP (/v1/evaluate + sign) |
redis-tcp |
0.237 ms | 0.281 ms | 0.321 ms | ≤ 8.0 ms |
Commit PEP (verifyAndConsume) |
in-memory |
0.067 ms | 0.081 ms | 0.095 ms | ≤ 1.5 ms |
Commit PEP (verifyAndConsume) |
redis-tcp |
0.145 ms | 0.166 ms | 0.187 ms | ≤ 1.5 ms |