muse-agent-example/db/ddl/114-example冻结幂等键-清单加上下文对.sql

19 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 114 冻结幂等键:manifest 单键 → (manifest, context) 对
--
-- WHY:检索清单(manifest)可以跨运行保持不变——例如知识检索全空、细纲与基线
-- 未变时,多次运行算出同一个 manifest_sha256;但冻结上下文每次不同
-- (预防合同、规则库版本、生成时间等进 contextSha256)。manifest_sha256
-- 唯一键使新上下文的冻结永远命中 ON CONFLICT DO NOTHING,落不了库;
-- 接受前置检查(acceptance_state)按 context_sha256 查询必查不到,
-- CONTEXT_NOT_FROZEN 阻断人接受通道。
--
-- (manifest, context) 对保持"同一冻结重放幂等":同一份冻结重放,两个
-- SHA 都相同,仍然幂等;不同上下文的冻结各得其所。
-- 2026-08-22/23 两阶段写手烟测实证:候选通过双门后被该缺陷挡在人闸前。
ALTER TABLE example_context_freeze
DROP CONSTRAINT IF EXISTS uk_example_context_freeze_manifest;
CREATE UNIQUE INDEX IF NOT EXISTS uk_example_context_freeze_manifest_context
ON example_context_freeze (manifest_sha256, context_sha256);