CODE-DESIGN-ANA-SEMI-ROOT-PREFLIGHT-ORCHESTRATION-V007-V022dev.developer.ana.cai2026-07-26T19:13:59.9078142+08:00CODE-DESIGN-ANA-SEMI-ROOT-PREFLIGHT-ORCHESTRATION-V007-V021 / 14491/f58cf05e58a9d098c539e18da4f9155557c0d0340f11406907da48674dcd3630AUDIT-DEV-ANA-SEMI-ROOT-PREFLIGHT-ORCHESTRATION-V007-PYTHON-STAGE-P-REPAIR-PLAN-V021=HOLD/5/4 / 217531/d036ea3ede335ddff82d83886867bc6dbaad625efac4201081a16d5b9dd8c31c / line 1743PENDING_INDEPENDENT_PYTHON_ARCHITECTURE_REPAIR_PLAN_REREVIEWNOT_ISSUEDNOT_ISSUEDV022 只修复 V021 四个 blocking findings,并关闭一个目录登记问题。V021、V020、V007 与历史失败包均保持 append-only 不变。
| consumer | V020 可观察合同 | V022 处理 | compatibility |
|---|---|---|---|
| case-analysis V007 | implementation gate 的 PASS/STOP、零数据库、root never readonly、BATCH-001 HELD | 值域与判定不变 | exact |
| management authorization | run/authorization/attempt、target paths、process counts、time window、STOP/no-retry | 每条新链本来就动态绑定;仅 runtime/paths 更新 | exact-by-new-binding |
| dev reviewer | API 结果、test totals、artifact rows、native closure、bytes/hash | wire schema/field/status/state 均保持;实现语言字段另行附加 | backward compatible |
| future root preflight | confirmed-zero、time-window、single invocation、native byte capture 可用性 | 同名字段、同状态语义;不消费 PowerShell CLR 名称 | exact |
| database/auth layer | 不从 Stage P 读取密码;只在独立授权后使用 named login-path | 不变 | exact |
因此无需修改 case-analysis 专业设计。V022 不改变任何 formal case target、SQL、业务结论或数据库权限;它只替换开发实现证据的内部 runtime。
四个 API 的外部 api_id/schema_id/property order/status/stop_code 继承 V020;Python wire object 使用 JSON,不删除、不重命名、不重排字段。
| API | V020 fields(ordinal) | Python value mapping |
|---|---|---|
| CONVERT | authorized_at_raw,authorized_at_utc_ticks,expires_at_raw,expires_at_utc_ticks,schema_id,status,stop_code |
string/int/string/int/string/string/null-or-string |
| TEST | authorized_at_utc_ticks,expires_at_utc_ticks,inside_window,now_utc_ticks,schema_id,status,stop_code |
int/int/bool/int/string/string/null-or-string |
| SELECTOR | confirmed_zero,duplicate_process_id_count,exact_outer_count,matched_process_ids,prohibited_process_count,related_process_count,schema_id,snapshot_row_count,status,stop_code,uncertain_fields,unknown_relevant_count |
bool/int/int/list[int]/int/int/string/int/string/null-or-string/null-or-list[string]/int |
| INVOKE | V020 authoritative 22-name vector/hash=403/4c3f8d873a6be20c0e449c6c6d1f196204ec8c3dfa399e3a5ee0e19f5fa153a2 |
exact same names/order; CLR evidence becomes non-authoritative runtime_type_evidence adjunct |
runtime_type_evidence 是 test evidence 的新增旁路字段,不进入上述 API wire object,也不被 V007/management/root preflight 消费。V020 的 System.UInt32[]/System.String[] 验证只属于旧 PowerShell implementation test;Python 等价验证为 list[int]/list[str],wire JSON 仍是相同 array number/string。
functional_case_total=30、provider precedence=4、API negative=8、selector=15 保持。state_id=C00-C40、state count=41、timeout-known=18 保持。C00-C40 的 top-level status,stop_code,final_exit_code,prepackage_terminal_state,package_closure_state 值逐项不变。P01..P08 -> Y01..Y08;每个 state 的八行 A/I/N/U/V tuple、upstream stop、external manifest nullability 均不变。T(state)=V020_state.replace_target_id(Pnn,Ynn).replace_run_id(future_run).replace_plan_id(V022);除此之外任何字段差异为 STOP_COMPATIBILITY_DRIFT/27。以下 marker 之间、UTF-8、无 BOM/CR、含最后一行 LF 的字节是唯一 executable bootstrap preimage。其 bytes/hash 与 base64 在本文件结尾“固定向量”登记;不得由 management 临时改写。
import ast,base64,hashlib,json,os,pathlib,runpy,sys
SCHEMA="ANA-SEMI-PYTHON-SOURCE-BUNDLE-JCS-V002"
ROOT=pathlib.Path(r"E:\mb-ms-doc\project-info").resolve()
ALLOW={
"Y01":pathlib.Path("dev/ana-dev/ana_semi_preconsumption_v002.py"),
"Y02":pathlib.Path("dev/ana-dev/test/test_ana_semi_preconsumption_v002.py"),
"Y03":pathlib.Path("dev/ana-dev/test/ana_semi_preconsumption_vectors_v002.json"),
"Y04":pathlib.Path("dev/ana-dev/test/run_ana_semi_preconsumption_validation_v002.py")}
def die(code,msg):
sys.stderr.buffer.write((msg+"\n").encode("utf-8"));raise SystemExit(code)
def canonical(obj):
return json.dumps(obj,ensure_ascii=False,allow_nan=False,sort_keys=True,separators=(",",":")).encode("utf-8")
def validate_py(data,name):
if data[:3]==b"\xef\xbb\xbf" or b"\r" in data or b"\x00" in data: die(11,"SOURCE_BYTES_INVALID:"+name)
try: text=data.decode("utf-8",errors="strict");tree=ast.parse(text,filename=name,mode="exec")
except Exception as e: die(11,"SOURCE_AST_INVALID:"+name+":"+type(e).__name__)
denied_imports={"subprocess","socket","urllib","http","requests","pymysql","mysql","sqlalchemy"}
for n in ast.walk(tree):
if isinstance(n,(ast.Import,ast.ImportFrom)):
names=[a.name.split(".")[0] for a in n.names] if isinstance(n,ast.Import) else [(n.module or "").split(".")[0]]
if any(x in denied_imports for x in names): die(11,"SOURCE_IMPORT_DENIED:"+name)
if isinstance(n,ast.Call) and isinstance(n.func,ast.Name) and n.func.id in {"eval","exec","compile","__import__"}: die(11,"SOURCE_CALL_DENIED:"+name)
def create_new_verified(path,data):
import ctypes
from ctypes import wintypes
k=ctypes.WinDLL("kernel32",use_last_error=True)
CreateFileW=k.CreateFileW;CreateFileW.argtypes=[wintypes.LPCWSTR,wintypes.DWORD,wintypes.DWORD,wintypes.LPVOID,wintypes.DWORD,wintypes.DWORD,wintypes.HANDLE];CreateFileW.restype=wintypes.HANDLE
WriteFile=k.WriteFile;WriteFile.argtypes=[wintypes.HANDLE,wintypes.LPCVOID,wintypes.DWORD,ctypes.POINTER(wintypes.DWORD),wintypes.LPVOID]
ReadFile=k.ReadFile;ReadFile.argtypes=[wintypes.HANDLE,wintypes.LPVOID,wintypes.DWORD,ctypes.POINTER(wintypes.DWORD),wintypes.LPVOID]
FlushFileBuffers=k.FlushFileBuffers;CloseHandle=k.CloseHandle
GENERIC_READ=0x80000000;GENERIC_WRITE=0x40000000;CREATE_NEW=1;OPEN_EXISTING=3;FILE_ATTRIBUTE_NORMAL=0x80;FILE_FLAG_WRITE_THROUGH=0x80000000
p=str(path);h=CreateFileW(p,GENERIC_WRITE,0,None,CREATE_NEW,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH,None)
if h==wintypes.HANDLE(-1).value: die(11,"CREATE_NEW_FAILED:"+p)
try:
off=0
while off<len(data):
chunk=data[off:off+1048576];buf=ctypes.create_string_buffer(chunk);done=wintypes.DWORD(0)
if not WriteFile(h,buf,len(chunk),ctypes.byref(done),None) or done.value!=len(chunk): die(27,"WRITE_UNCERTAIN:"+p)
off+=done.value
if not FlushFileBuffers(h): die(27,"FLUSH_UNCERTAIN:"+p)
finally:
if not CloseHandle(h): die(27,"CLOSE_UNCERTAIN:"+p)
h=CreateFileW(p,GENERIC_READ,0,None,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,None)
if h==wintypes.HANDLE(-1).value: die(27,"REOPEN_UNCERTAIN:"+p)
try:
out=bytearray();buf=ctypes.create_string_buffer(1048576)
while True:
done=wintypes.DWORD(0)
if not ReadFile(h,buf,len(buf),ctypes.byref(done),None): die(27,"READ_UNCERTAIN:"+p)
if done.value==0: break
out.extend(buf.raw[:done.value])
finally:
if not CloseHandle(h): die(27,"RECLOSE_UNCERTAIN:"+p)
if bytes(out)!=data: die(27,"REOPEN_BYTES_DRIFT:"+p)
raw=sys.stdin.buffer.read(4194305)
if len(raw)>4194304 or raw[:3]==b"\xef\xbb\xbf" or b"\r" in raw or b"\x00" in raw or raw.endswith(b"\n"): die(11,"BUNDLE_BYTES_INVALID")
try: bundle=json.loads(raw.decode("utf-8",errors="strict"))
except Exception as e: die(11,"BUNDLE_JSON_INVALID:"+type(e).__name__)
if canonical(bundle)!=raw or bundle.get("schema_id")!=SCHEMA: die(11,"BUNDLE_CANONICAL_DRIFT")
items=bundle.get("targets")
if not isinstance(items,list) or [x.get("artifact_id") for x in items]!=["Y01","Y02","Y03","Y04"]: die(11,"BUNDLE_TARGET_ORDER_DRIFT")
decoded={}
for x in items:
aid=x["artifact_id"];rel=pathlib.Path(x["relative_path"])
if rel!=ALLOW[aid] or rel.is_absolute() or ".." in rel.parts: die(11,"BUNDLE_PATH_DRIFT:"+aid)
try: data=base64.b64decode(x["content_base64"],validate=True)
except Exception: die(11,"BUNDLE_BASE64_INVALID:"+aid)
if len(data)!=x["bytes"] or hashlib.sha256(data).hexdigest()!=x["sha256"]: die(11,"BUNDLE_HASH_DRIFT:"+aid)
if aid in {"Y01","Y02","Y04"}: validate_py(data,aid)
else:
try: obj=json.loads(data.decode("utf-8",errors="strict"))
except Exception as e: die(11,"Y03_JSON_INVALID:"+type(e).__name__)
if canonical(obj)!=data: die(11,"Y03_CANONICAL_DRIFT")
decoded[aid]=data
if ROOT!=pathlib.Path.cwd().resolve(): die(11,"CWD_DRIFT")
for aid in ["Y01","Y02","Y03","Y04"]:
path=(ROOT/ALLOW[aid]).resolve()
if ROOT not in path.parents: die(11,"PATH_ESCAPE:"+aid)
create_new_verified(path,decoded[aid])
ns=runpy.run_path(str((ROOT/ALLOW["Y04"]).resolve()),run_name="__ana_semi_stage_p__")
main=ns.get("main")
if not callable(main): die(11,"Y04_MAIN_MISSING")
rc=main(str(ROOT),bundle["run_id"],str((ROOT/pathlib.Path(bundle["output_relative_path"])).resolve()))
if type(rc) is not int: die(27,"Y04_RETURN_TYPE_DRIFT")
raise SystemExit(rc)
固定 API 只允许 ast/base64/hashlib/json/os/pathlib/runpy/sys/ctypes。bootstrap 自身只允许一次 runpy.run_path(Y04);Y01/Y02/Y04 AST 禁止 eval/exec/compile/__import__ 与所有外部进程、网络和 database import。
python.exe,-I,-B,-c,<base64-wrapper-token>。<base64-wrapper-token> 唯一形式:import base64;exec(compile(base64.b64decode('<BOOTSTRAP_BASE64>'),'<ana-semi-bootstrap>','exec'))。Arguments、Win32 CommandLine、token preimage/hash 在“固定向量”中登记;管理只能复算,不能生成新值。read(4194305) 一次到 EOF;stdout/stderr 是分离的内存 byte stream;任何 short write、父端 pipe 异常、child read >4MiB、EOF 不确定均 STOP/27。runpy.run_path(Y04,run_name='__ana_semi_stage_p__') → Y04 通过 exact importlib.util.spec_from_file_location 各加载 Y01/Y02 一次 → Y04.main 一次。Y03 只作为 bytes/JSON 读取,不加载。sys.modules keys 固定为 ana_semi_preconsumption_v002 与 test_ana_semi_preconsumption_v002;加载前必须 absent,加载后 identity/path/hash 必须匹配;禁止 reload、第二 spec、第二 main、第二 provider 调用。bootstrap/Y01 共用唯一 writer primitive,直接调用 Win32:
CreateFileW(GENERIC_WRITE,share=0,CREATE_NEW,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH);WriteFile 循环,逐次 written==chunk_length;FlushFileBuffers;CloseHandle;CreateFileW(GENERIC_READ,share=0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL) → ReadFile 到 EOF → CloseHandle → bytes/hash equal。每个 API 的 false/invalid handle/close uncertainty 都映射 27;不得以 Python open('w')、Path.write_text、rename、replace、temp file 或非排他 reopen 替代。run root 下 test/receipt/manifest 目录必须由 CreateDirectoryW 逐层创建;future run 预存在或 ERROR_ALREADY_EXISTS 为 STOP,已存在的 dev/ana-dev、test、tmp 只读验证不创建。
唯一 provider 为 WIN32_TOOLHELP_PROCESS_SNAPSHOT_V001,由 Y01 在当前 Python 进程内调用一次:
CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);Process32FirstW/Process32NextW 枚举 pid,parent_pid,exe_name;OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,False,pid) + QueryFullProcessImageNameW 获取 exe_path;CloseHandle;snapshot handle 也必须关闭。相关候选 image basename 固定为:python.exe,powershell.exe,pwsh.exe,csc.exe,mysql.exe,mysql_config_editor.exe,node.exe(ordinal case-insensitive basename),但 exact matching 使用规范化绝对 image path;source PID 先排除,PID 去重后排序。
provider schema ANA-SEMI-WIN32-PROCESS-SNAPSHOT-JCS-V001:
schema_id,provider_id,as_of_utc,source_pid,call_count,rows,status,stop_code
row ordered keys:exe_name,exe_path,exe_path_status,parent_pid,pid;types=string,string|null,KNOWN|ACCESS_DENIED|EXITED_DURING_QUERY|ERROR,uint32,uint32。rows 按 pid 升序;canonical JSON 为 UTF-8 no BOM/CR/NUL/trailing LF;运行时记录 bytes/SHA-256 到 Y06。
call_count 必须恰好 1;第二调用直接 STOP_PROVIDER_REENTRANT/27,不打开 snapshot。as_of_utc 由同一 owner clock 在 snapshot 返回后立即读取一次;从 snapshot handle 创建到 as_of 不得超过 1000ms,否则 stale STOP。confirmed_zero=true 仅当相关 rows 排除 source 后为 0、unknown_relevant_count=0、duplicate=0。pid==os.getpid() 排除;不使用 substring、当前 command line 或名称近似证明自身。Y03 schema=ANA-SEMI-PRECONSUMPTION-VECTORS-JCS-PY-V001,top-level ordered keys:
api_contracts,compatibility,state_contracts,target_contracts,test_cases,version
api_contracts 固定四行 CONVERT/TEST/SELECTOR/INVOKE,每行 api_id,field_names,field_rules,schema_id;顺序固定。test_cases 固定 30 functional + 4 provider precedence + 8 api negative + 15 selector + 9 source/JCS/AST regression = 66;每行 case_id,expected_status,expected_stop_code,input,group。state_contracts 固定 41 行 C00-C40,每行包含 state_id,status,stop_code,final_exit_code,prepackage_terminal_state,package_closure_state,artifact_state_vector,external_manifest_rule。target_contracts 固定八行 Y01-Y08 与 path/media_type/schema/expected_presence。Y05 schema=ANA-SEMI-PRECONSUMPTION-STATIC-RESULT-JCS-PY-V001,ordered keys:
case_results,case_total,failed_case_ids,passed_case_count,schema_id,status,stop_code
仅包含 9 source/JCS/AST regression;case_total=9。PASS 时 failed=[]、passed=9、status=TEST_PASS、stop=null。
Y06 schema=ANA-SEMI-PRECONSUMPTION-CONTRACT-RESULT-JCS-PY-V001,ordered keys:
api_negative_results,api_results,functional_results,process_snapshot,provider_precedence_results,schema_id,selector_results,status,stop_code,summary
summary ordered keys:api_negative_total,functional_case_total,provider_precedence_total,selector_total,total_failed,total_passed,固定 totals=8,30,4,15。process_snapshot 使用第 3 节 schema、call_count=1、bytes/hash 非 null。
Y03/Y05/Y06 均 strict JCS:UTF-8、no BOM/CR/NUL/trailing LF,sort_keys=True,separators=(',',':'),ensure_ascii=False,allow_nan=False。所有动态数组按已冻结 ordinal 排序。
Y07 schema=ANA-SEMI-PRECONSUMPTION-RECEIPT-MD-PY-V001,UTF-8 no BOM/CR/NUL,恰好一个 final LF。唯一模板字段顺序:
receipt_schema_id,run_id,plan_id,as_of_artifact_id,prepackage_status,prepackage_stop_code,Y05_status,Y06_status,python_process_count,prohibited_process_count,network_access,credential_access,database_connection_performed
PASS literal 的后三个 bool 固定 false,process=1/0,as_of=Y06,status=PASS/null,Y05/Y06=TEST_PASS/TEST_PASS。STATIC 与 CONTRACT literal 分别为 TEST_FAIL/STATIC_TEST_FAILED/Y05=TEST_FAIL/Y06=NOT_RUN_UPSTREAM_STOP、TEST_FAIL/CONTRACT_TEST_FAILED/Y05=TEST_PASS/Y06=TEST_FAIL。完整 bytes/hash 必须在 implementation source bundle 送审时冻结;模板外任何字段或顺序差异 STOP。
CSV columns 固定为:
artifact_id,relative_path,artifact_role,media_type,schema_id,expected_presence,materialized,exists,status,bytes,sha256,upstream_stop_code
固定八行:
| id | role | media | schema | expected_presence |
|---|---|---|---|---|
| Y01 | SOURCE | text/x-python | ANA-SEMI-PY-MODULE-V001 | REQUIRED_ON_SOURCE_STAGE |
| Y02 | TEST_SOURCE | text/x-python | ANA-SEMI-PY-TEST-V001 | REQUIRED_ON_SOURCE_STAGE |
| Y03 | VECTOR | application/json | ANA-SEMI-PRECONSUMPTION-VECTORS-JCS-PY-V001 | REQUIRED_ON_SOURCE_STAGE |
| Y04 | ENTRY_SOURCE | text/x-python | ANA-SEMI-PY-ENTRY-V001 | REQUIRED_ON_SOURCE_STAGE |
| Y05 | STATIC_RESULT | application/json | ANA-SEMI-PRECONSUMPTION-STATIC-RESULT-JCS-PY-V001 | CONDITIONAL_ON_STATIC_STAGE |
| Y06 | CONTRACT_RESULT | application/json | ANA-SEMI-PRECONSUMPTION-CONTRACT-RESULT-JCS-PY-V001 | CONDITIONAL_ON_CONTRACT_STAGE |
| Y07 | RECEIPT | text/markdown | ANA-SEMI-PRECONSUMPTION-RECEIPT-MD-PY-V001 | CONDITIONAL_ON_PREPACKAGE_VALID |
| Y08 | MANIFEST | text/csv | ANA-SEMI-PRECONSUMPTION-MANIFEST-CSV-PY-V001 | SELF_CONDITIONAL_ON_RECEIPT_VALID |
Y08 RFC4180 CRLF + final CRLF;Y08 self row materialized/exists=true 时 bytes/hash 必须为空;external Y08 bytes/hash 只进入 native terminal/audit。
每个 state 的 artifact_state_vector 是 8 字符,alphabet=N,A,I,V,U:
false,false,NOT_RUN_UPSTREAM_STOP,null,null,upstream stopfalse,false,ATTEMPTED_NO_OUTPUT,null,null,current writer stoptrue,true,MATERIALIZED_INVALID_KNOWN,non-null,non-null,current validation stoptrue,true,MATERIALIZED_VALID,non-null,non-null,nullnull,null,STATE_UNCERTAIN,null,null,uncertainty stopV022 权威映射等于 V020 C00-C40 的 41 个向量经 P→Y 变换;实现必须从 Y03 中读取 41 行并逐行验证,没有 default/fallback state。任何实况不命中唯一 state 为 STOP_NATIVE_STATE_UNMAPPED/27。
native schema=ANA-SEMI-PRECONSUMPTION-NATIVE-FINAL-PY-V001,ordered keys:
artifact_rows,attempt_id,authorization_id,credential_access,database_connection_performed,external_manifest_bytes,external_manifest_sha256,final_exit_code,finished_at,network_access,package_closure_state,prepackage_terminal_state,prohibited_process_count,python_process_count,run_id,schema_id,started_at,state_id,status,stop_code
cross-field:PASS 只能 C00/exit0/stop=null/CLOSED;unknown 只能 V020 C10 对应 state/exit27;timeout-known 只能 18 个继承 states/exit24;receipt/manifest failure 维持 25/26,package uncertainty 27 优先。external manifest 仅 Y08 materialized/exists true 时非 null,若 Y08=I 则必须等于实际 invalid bytes/hash。
DAG 唯一为 V022/audit/auth → stdin bundle → bootstrap in-memory gate → Y01-Y04 → Y05 → Y06 → freeze Y01-Y06 → Y07(as-of Y06) → Y08(self blank,records Y07 hash) → external native terminal(Y08 hash) → independent review。
5236/db8c6ac8160e7d438d8b7690b476b64c141130f1cea0513ecbf2976ec4b8e6a66984/d55c01535e6a2fd5f6fe19784509e590ee15f63ba00e7074ef9bada7ddb42542;其值必须由上述 exact bootstrap bytes 以 RFC4648 standard Base64(无换行)唯一派生,不允许手工转录或替换 alphabet/padding。7063/ffef0cbbb8657e95b5ed9a8e4f405cf779caffe1f01b13e037ca2409b195ef965 tokens/7160/c48ea62776568d3413e0c34fa35a9ba4a14b46cf0b52ffecfbb708e4ce7f0a017074/3313f7b7fdcb6e5f6f27f94488487706c1b59e2b31533dc5f26401dadfae36517164/0d280fba04a1288797630c0ff6e4e0a810f807f89f9563b0e43f5b512c2cacf1所有 hash preimage 使用 strict UTF-8、无 BOM。argv token preimage 是 5 个 token 用单一 LF 连接、无尾 LF。Arguments 固定为 -I -B -c "<wrapper token>"。CommandLine 固定为 "<python absolute path>" <Arguments>;授权时 runtime absolute path 必须与本计划当前 snapshot 相同,否则本向量失效并 HOLD。
dev-doc/ana-doc/目录导读.md 必须 append V021 HOLD 与 V022 successor 入口,关闭 ISSUE-V021-05。
V022 只允许独立计划复审。PASS 后仍只能向 management 申请全新 single-use Python Y01-Y08 implementation authorization。审核/授权前禁止物化 Y01-Y08/run、执行 Python/PowerShell/csc/node/synthetic/proof/config-editor/mysql/SQL/database/network/credential、进入 R3/BATCH-001 或修改旧 P01-P08/Git/配置/角色/权限。