dellweb3 commited on
Commit
75835df
·
verified ·
1 Parent(s): 253a5d4

Deploy verified conversational workbench and isolated Java application previews

Browse files

Source baseline: 2971ce3dda5fd36e58778f27148f2a56c94d0a66. Credentials are runtime Secrets only.

AGENTS.md CHANGED
@@ -1,4 +1,10 @@
1
- # Vibe Coding 项目协作约束
 
 
 
 
 
 
2
 
3
  ## 指定HF空间发布授权(2026-10-24最新)
4
 
 
1
+ # Vibe Coding 项目协作约束
2
+
3
+ ## Java 依赖与重复失败定位补充(2026-10-24)
4
+
5
+ 用户要求云端自动引用适用的开源 Java 库,内网使用统一镜像预存。实现须将依赖下载与无网代码执行分离,仓库由服务端配置,记录固定版本、完整闭包、许可证、来源和摘要。允许完成该依赖适配,不因此放开宿主执行生成的 POM/插件/Java,不能将批准目录缓存冒称完整 Maven 解析。设计与当前实现边界见 `docs/java-dependency-gateway.md`。
6
+
7
+ 重复已知失败可在原任务预算内增加一次故障定位;建议属于模型假设,必须保留来源、原失败和独立复测。建议不能解释实际错误分支时不得直接宣布根因或修复成功。用户最新强调本地测试通过后再上传,只传变化文件,不重复上传未变镜像/知识库;云端运行与浏览器验证仍须单列。
8
 
9
  ## 指定HF空间发布授权(2026-10-24最新)
10
 
deploy/hf/package-manifest.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "git_commit": "d9f38c51afab6b76db8cd42679961d03b4cc7d80",
3
  "files": {
4
  ".local/dependencies/pdfbox/3.0.8/pdfbox-app-3.0.8.jar": {
5
  "sha256": "f6b3a80c39747ff0ef5d06708bc03882152403de58dbef4a1fbffbee568eceb1",
@@ -18,8 +18,8 @@
18
  "bytes": 94203974
19
  },
20
  "AGENTS.md": {
21
- "sha256": "0558bea7a0b928553961086897c325cc61f774aabf1ed67ee65dc87fe891dc86",
22
- "bytes": 21341
23
  },
24
  "deploy/hf/adapter.py": {
25
  "sha256": "0088b19648ab9661bb6eb6bdf4fa34de368f5fe5d6c347a58504c60331f42e95",
@@ -193,6 +193,18 @@
193
  "sha256": "97813aa23893a9d66445f2480ac4173442f11864b3a95f3e18932e9e4e9bc8cd",
194
  "bytes": 43909
195
  },
 
 
 
 
 
 
 
 
 
 
 
 
196
  "examples/calculator-web/README.md": {
197
  "sha256": "3d46ea9ea1b48b96ee94ef35da4300c301f98c77349c39d2c82a08ce916e4b71",
198
  "bytes": 1442
@@ -217,6 +229,10 @@
217
  "sha256": "1bd72676e17489c4203ef34fce6eb6a2182e647624dd81cce42753df06f9dd88",
218
  "bytes": 88082
219
  },
 
 
 
 
220
  "examples/development-system-validation.json": {
221
  "sha256": "2b10fcf8e4b8ac58ebcbe666f3d9a45fa65320780f8a871904c24c5dc234503a",
222
  "bytes": 13044
@@ -265,6 +281,10 @@
265
  "sha256": "09875990f95708d4bf53a243a38fdd2635bb6adf48ad1d468e8ce7fda1e1c14b",
266
  "bytes": 13493
267
  },
 
 
 
 
268
  "examples/hf-cloud-second-candidate.json": {
269
  "sha256": "6b5a73f3e45c68af96f65f7b47295650bef04e99dc085cb4c53484befbed4fda",
270
  "bytes": 3529
@@ -322,7 +342,7 @@
322
  "bytes": 29132
323
  },
324
  "examples/hf-ingress-validation.json": {
325
- "sha256": "e70502ab97c0eac9eca2393becda36fce6ffed69f20ed2e807c01e5cce513c1f",
326
  "bytes": 2410
327
  },
328
  "examples/multi-sandbox-validation.json": {
@@ -426,8 +446,8 @@
426
  "bytes": 8560
427
  },
428
  "sites/zkcoding-workbench/dist/runtime.js": {
429
- "sha256": "537ed5a50032695e7561a0e4f603d69e338ebd2ccd784c282df9cf052b00dfa2",
430
- "bytes": 37325
431
  },
432
  "sites/zkcoding-workbench/dist/workos-base.css": {
433
  "sha256": "2df5773982c004d4f1ed6cf14ed166409be21b05b49164ba6e77e13ab2f8f5e7",
@@ -578,12 +598,12 @@
578
  "bytes": 8477
579
  },
580
  "src/apps/workbench/development.py": {
581
- "sha256": "4383601a8df21fbc3d1b56d79280102eb4b3f5250fb5518507bb962d26523d72",
582
- "bytes": 4189
583
  },
584
  "src/apps/workbench/engine.py": {
585
- "sha256": "78ac072e787d5855341c599038d510c207d62c427235e196c1754cd939bda4e2",
586
- "bytes": 30280
587
  },
588
  "src/apps/workbench/erp_flow.py": {
589
  "sha256": "fb2034555165b8c2b28f6a8ac88ec6d239f8eaf5a0b4828e9b9c649f284b0844",
@@ -673,6 +693,10 @@
673
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
674
  "bytes": 0
675
  },
 
 
 
 
676
  "src/modules/artifact_catalog/ports/.gitkeep": {
677
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
678
  "bytes": 0
@@ -922,12 +946,12 @@
922
  "bytes": 997
923
  },
924
  "src/modules/llm_gateway/routing.py": {
925
- "sha256": "6e1c60e5eb5540d482639e0cb7a85757fc420125316d4dedf5093f98ba1efcb5",
926
- "bytes": 2913
927
  },
928
  "src/modules/llm_gateway/service.py": {
929
- "sha256": "cca8f721beddcb8ed6af3c3249520aeb22715c9c60a4df83739fced037a68a38",
930
- "bytes": 10048
931
  },
932
  "src/modules/llm_gateway/tests/.gitkeep": {
933
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
@@ -958,8 +982,8 @@
958
  "bytes": 1200
959
  },
960
  "src/modules/orchestrator/service.py": {
961
- "sha256": "f59fdfdc13291f2149e1ac60a215f63f9c8a74eadf1f28ac31c5b6eda4aa3c12",
962
- "bytes": 26692
963
  },
964
  "src/modules/orchestrator/skill_runner/.gitkeep": {
965
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
@@ -1177,10 +1201,18 @@
1177
  "sha256": "100c83992ebde6c6263da9a8457541933a717a94c219cc6719227124f346563c",
1178
  "bytes": 6630
1179
  },
 
 
 
 
1180
  "src/tests/runtime/test_harness.py": {
1181
  "sha256": "b7835daecb16ef058049dc38a7ed67b70799c02584d3c580e7ae7471181bd666",
1182
  "bytes": 2435
1183
  },
 
 
 
 
1184
  "src/tests/runtime/test_key_modules.py": {
1185
  "sha256": "850e3cc5bff290a6e3cfe392fd8ede8ab100be0b704016e7e1737ff6228df2d2",
1186
  "bytes": 8130
 
1
  {
2
+ "git_commit": "2971ce3dda5fd36e58778f27148f2a56c94d0a66",
3
  "files": {
4
  ".local/dependencies/pdfbox/3.0.8/pdfbox-app-3.0.8.jar": {
5
  "sha256": "f6b3a80c39747ff0ef5d06708bc03882152403de58dbef4a1fbffbee568eceb1",
 
18
  "bytes": 94203974
19
  },
20
  "AGENTS.md": {
21
+ "sha256": "efdcd5f5ffaf23f5f270ff8d3153d07e3d3ccb19bafa047bc43f630fd2cb776a",
22
+ "bytes": 22229
23
  },
24
  "deploy/hf/adapter.py": {
25
  "sha256": "0088b19648ab9661bb6eb6bdf4fa34de368f5fe5d6c347a58504c60331f42e95",
 
193
  "sha256": "97813aa23893a9d66445f2480ac4173442f11864b3a95f3e18932e9e4e9bc8cd",
194
  "bytes": 43909
195
  },
196
+ "examples/calculator-state-repair/diagnosis.md": {
197
+ "sha256": "ecc8d80d8694098ef48bb984956c38dc9902de74c1c46821afcff6b1880ac365",
198
+ "bytes": 914
199
+ },
200
+ "examples/calculator-state-repair/requirement.md": {
201
+ "sha256": "c6fe434066913db8049c0be37faab89a81afbd616bcfbf6a219837d4ce67f04b",
202
+ "bytes": 4108
203
+ },
204
+ "examples/calculator-state-repair/src/main/java/demo/App.java": {
205
+ "sha256": "96b1cea52bcce483c6d62ed02f2aeb9f34368c90f0709de769c3ef93761c760b",
206
+ "bytes": 7306
207
+ },
208
  "examples/calculator-web/README.md": {
209
  "sha256": "3d46ea9ea1b48b96ee94ef35da4300c301f98c77349c39d2c82a08ce916e4b71",
210
  "bytes": 1442
 
229
  "sha256": "1bd72676e17489c4203ef34fce6eb6a2182e647624dd81cce42753df06f9dd88",
230
  "bytes": 88082
231
  },
232
+ "examples/dependency-recovery-validation.json": {
233
+ "sha256": "d023925a537ba9191d397f7a37d782b3e7749eb136728b6916953d0296f32206",
234
+ "bytes": 29499
235
+ },
236
  "examples/development-system-validation.json": {
237
  "sha256": "2b10fcf8e4b8ac58ebcbe666f3d9a45fa65320780f8a871904c24c5dc234503a",
238
  "bytes": 13044
 
281
  "sha256": "09875990f95708d4bf53a243a38fdd2635bb6adf48ad1d468e8ce7fda1e1c14b",
282
  "bytes": 13493
283
  },
284
+ "examples/hf-cloud-fourth-candidate.json": {
285
+ "sha256": "35d4471b051291ac7a515d55e86007e918b199eea6f9c5691496dd55365e93aa",
286
+ "bytes": 15703
287
+ },
288
  "examples/hf-cloud-second-candidate.json": {
289
  "sha256": "6b5a73f3e45c68af96f65f7b47295650bef04e99dc085cb4c53484befbed4fda",
290
  "bytes": 3529
 
342
  "bytes": 29132
343
  },
344
  "examples/hf-ingress-validation.json": {
345
+ "sha256": "0d6f9dee343fbff6d6012f19ecc5b0a39e71312eaf64bac93c28264357f75650",
346
  "bytes": 2410
347
  },
348
  "examples/multi-sandbox-validation.json": {
 
446
  "bytes": 8560
447
  },
448
  "sites/zkcoding-workbench/dist/runtime.js": {
449
+ "sha256": "13462c01b78d4e57241f888a2fc3c54a66bd9df446935a3e08b6c09c25de393c",
450
+ "bytes": 37537
451
  },
452
  "sites/zkcoding-workbench/dist/workos-base.css": {
453
  "sha256": "2df5773982c004d4f1ed6cf14ed166409be21b05b49164ba6e77e13ab2f8f5e7",
 
598
  "bytes": 8477
599
  },
600
  "src/apps/workbench/development.py": {
601
+ "sha256": "5d7925b8a93f39d946600d601193b9270b003bfd72102c8975cbbaab850f04e5",
602
+ "bytes": 4245
603
  },
604
  "src/apps/workbench/engine.py": {
605
+ "sha256": "a1b62e3aa4a46dfe97236f66847fa745220c3386c02a09f1f4bb85439fb6f7d7",
606
+ "bytes": 30338
607
  },
608
  "src/apps/workbench/erp_flow.py": {
609
  "sha256": "fb2034555165b8c2b28f6a8ac88ec6d239f8eaf5a0b4828e9b9c649f284b0844",
 
693
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
694
  "bytes": 0
695
  },
696
+ "src/modules/artifact_catalog/java_dependencies.py": {
697
+ "sha256": "c31824e412d850d32f5b27a15ea0de430fe018684ed0c9e2eed8606441866004",
698
+ "bytes": 9265
699
+ },
700
  "src/modules/artifact_catalog/ports/.gitkeep": {
701
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
702
  "bytes": 0
 
946
  "bytes": 997
947
  },
948
  "src/modules/llm_gateway/routing.py": {
949
+ "sha256": "a00214e3ea026307932b8925777d36f0ea8ac12574f0bc8e93aa86836109aa2d",
950
+ "bytes": 3048
951
  },
952
  "src/modules/llm_gateway/service.py": {
953
+ "sha256": "55cea1f55a078e3c4c10c5a6467d8fee32ab514e096c481fcb16256bd6ebea21",
954
+ "bytes": 11153
955
  },
956
  "src/modules/llm_gateway/tests/.gitkeep": {
957
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
 
982
  "bytes": 1200
983
  },
984
  "src/modules/orchestrator/service.py": {
985
+ "sha256": "62a5065eb0a1c85e0751b0c501d2c292c86cf90224c5b21c63a82d303f0150d6",
986
+ "bytes": 29007
987
  },
988
  "src/modules/orchestrator/skill_runner/.gitkeep": {
989
  "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
 
1201
  "sha256": "100c83992ebde6c6263da9a8457541933a717a94c219cc6719227124f346563c",
1202
  "bytes": 6630
1203
  },
1204
+ "src/tests/runtime/test_failure_localization.py": {
1205
+ "sha256": "ade8bcccbd8f0e86c39d8bc8e0bb8b253872e900789394d6c6c2178fcf04a4d9",
1206
+ "bytes": 4540
1207
+ },
1208
  "src/tests/runtime/test_harness.py": {
1209
  "sha256": "b7835daecb16ef058049dc38a7ed67b70799c02584d3c580e7ae7471181bd666",
1210
  "bytes": 2435
1211
  },
1212
+ "src/tests/runtime/test_java_dependencies.py": {
1213
+ "sha256": "16814a902682fee9e841e66bf24a5edef173eb4b577cd247bb93b67293dfee4c",
1214
+ "bytes": 6883
1215
+ },
1216
  "src/tests/runtime/test_key_modules.py": {
1217
  "sha256": "850e3cc5bff290a6e3cfe392fd8ede8ab100be0b704016e7e1737ff6228df2d2",
1218
  "bytes": 8130
examples/calculator-state-repair/diagnosis.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # 模型故障定位建议
2
+
3
+ Root cause: The trailing-character check in calc() uses a fresh local `int pos=0` instead of the parser's mutable cursor `p[0]`. After parseSum("2+3", p) returns, p[0]==3 (end of input), but `pos` is reset to 0. The loop `while(pos<expr.length()&&expr.charAt(pos)==' ') pos++;` finds no spaces, leaving pos==0. Then `if(pos!=expr.length())` evaluates `0!=3`, which is true, so every valid expression incorrectly returns 400 INVALID_EXPRESSION. This branch is the only path producing that exact status and body for these inputs. Fix: Replace `int pos=0; while(pos<expr.length()&&expr.charAt(pos)==' ') pos++; if(pos!=expr.length())` with `int[] p=new int[]{0}; ... int pos=p[0]; while(pos<expr.length()&&expr.charAt(pos)==' ') pos++; if(pos!=expr.length())`. Pass `p` into parseSum and reuse it for the end-of-input check.
4
+
5
+ 独立39项HTTP测试已通过,未进行用户验收。
examples/calculator-state-repair/requirement.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # DEMO-CALC-01:可操作的网页计算器
2
+
3
+ ## 背景与用户
4
+ 员工需要在内网快速核算公式,现有简单输入框不能解释优先级或处理错误。本场景交付可直接使用的计算器网站,运算由Java服务执行,页面负责输入和结果展示。
5
+
6
+ ## 页面与交互
7
+ 标题“工程计算器”,主卡片包含表达式输入框、结果显示区、数字键盘0–9、小数点、加减乘除、左右括号、退格、清空和等号;旁边显示最近10条成功计算记录,窄屏放到下方。默认示例(12.5+7.5)*3,等于60。历史记录点击后回填输入,不自动重新执行。
8
+ 物理键盘可输入公式,Enter计算,Escape清空;每个按钮有明确标签,焦点可见。计算时按钮显示忙碌且防止重复请求;服务返回后再显示结果,不演示虚假延迟。除零或非法表达式在结果区给可理解错误并保留输入。成功结果可作为下次运算起点;结果字符串可复制。
9
+ 修改输入、历史回填或清空后,旧结果与复制状态立即失效,重新计算后才能复制。应用只展示输入、结果、历史和业务错误,不显示原始接口JSON、源码摘要、沙箱步骤或代码下载;开发证据保留在工作台。预览准备由平台内部完成,成果页面使用独立端口。
10
+
11
+ ## 编程需求与验收
12
+ - CALC-01:Java17标准库HttpServer,GET /health。GET /api/calculate的唯一参数expression64为UTF-8表达式的无填充base64url;公开凭据demo-calculator,不接受任意脚本、eval或脚本引擎。
13
+ - CALC-02:实现真正的表达式解析,支持+-*/、括号、空格、一元正负。乘除优先于加减,括号优先。2+3*4=14,(2+3)*4=20,-3+5=2。
14
+ - CALC-03:用BigDecimal和DECIMAL128处理中间运算,最终最多12位小数,HALF_UP,去除尾零,不用科学记数法。0.1+0.2=0.3;1/3显示0.333333333333;连续运算可使用上次结果。
15
+ - CALC-04:除零400 DIVISION_BY_ZERO;缺括号、连续非法运算、字母等400 INVALID_EXPRESSION;1+-2、--1属于合法一元符号。缺失、重复、未知参数及非法编码400 INVALID_INPUT。
16
+ - CALC-05:表达式最多128字符、括号16层、64次运算;单个数字字面量最多24位(不含小数点),数值绝对值≤1e24;超限422 LIMIT_EXCEEDED。编码参数最多256字符,超限400 INVALID_INPUT。无身份401、非GET405、未知路径404,线程与输入有界。
17
+ - CALC-06:独立HTTP系统测试覆盖算术、精度、结合顺序、负号、边界和错误;网页测试点击键盘与Enter、历史回填、连续运算、除零展示、窄屏布局。
18
+
19
+ ### 接口与Java实现补充约束
20
+
21
+ 成功和失败都必须返回UTF-8 JSON对象,不能直接返回错误码文本或HttpServer默认HTML。成功包络为`{"expression":"原始表达式(保留空格)","result":"结果字符串"}`,错误包络统一为`{"error":"对应错误码"}`;未知路径也返回404 `{"error":"NOT_FOUND"}`。可注册统一根处理器,再精确匹配路径和方法,避免默认路由漏出HTML。
22
+
23
+ 数字语法为`digits ('.' digits+)?`或`'.' digits+`;`.5`合法,`1.`非法。允许标记之间的ASCII空格,保留原输入;` 12 + ( 3 * 2 ) `等于18,`1 2`仍非法,不能简单删除全部空白。严格UTF-8解码须使用CharsetDecoder的REPORT模式,不能用会替换非法字节的默认字符串构造。需要ByteBuffer/CharBuffer时应显式导入`java.nio.ByteBuffer`和`java.nio.CharBuffer`,或使用完整类名,确保Java17实际编译。此处是公开接口和编程约束,不允许修改保护测试。
24
+
25
+ ## 交付与完成条件
26
+ 交付Java源码、配套HTML/CSS/JS页面、需求与技术说明、差异、测试对应表、实际沙箱编译和测试证据、可下载ZIP及本地网站。生成源码限定src/main/java/demo/App.java及可选docs,不引入框架或修改保护测试;受控网页模板作为独立交付文件明确来源。失败必须留存诊断并修复复测,不以静态数字冒充Java执行结果。
examples/calculator-state-repair/src/main/java/demo/App.java ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package demo;
2
+
3
+ import com.sun.net.httpserver.HttpServer;
4
+ import com.sun.net.httpserver.HttpExchange;
5
+ import java.io.*;
6
+ import java.math.*;
7
+ import java.net.InetSocketAddress;
8
+ import java.nio.ByteBuffer;
9
+ import java.nio.CharBuffer;
10
+ import java.nio.charset.*;
11
+ import java.util.Base64;
12
+
13
+ public class App {
14
+ static int ops, depth;
15
+ public static void main(String[] args) throws Exception {
16
+ HttpServer s = HttpServer.create(new InetSocketAddress(8080), 0);
17
+ s.createContext("/", App::handle);
18
+ s.setExecutor(null);
19
+ s.start();
20
+ }
21
+ static void handle(HttpExchange x) throws IOException {
22
+ try { doHandle(x); } finally { x.close(); }
23
+ }
24
+ static void doHandle(HttpExchange x) throws IOException {
25
+ String p = x.getRequestURI().getPath();
26
+ if (p.equals("/health")) {
27
+ if (!x.getRequestMethod().equals("GET")) { send(x,405,"{\"error\":\"METHOD_NOT_ALLOWED\"}"); return; }
28
+ send(x,200,"{\"status\":\"ok\"}"); return;
29
+ }
30
+ if (p.equals("/api/calculate")) {
31
+ if (!x.getRequestMethod().equals("GET")) { send(x,405,"{\"error\":\"METHOD_NOT_ALLOWED\"}"); return; }
32
+ String a = x.getRequestHeaders().getFirst("Authorization");
33
+ if (a==null||!a.equals("Bearer demo-calculator")) { send(x,401,"{\"error\":\"UNAUTHORIZED\"}"); return; }
34
+ calc(x); return;
35
+ }
36
+ send(x,404,"{\"error\":\"NOT_FOUND\"}");
37
+ }
38
+ static void calc(HttpExchange x) throws IOException {
39
+ String q = x.getRequestURI().getRawQuery();
40
+ if (q==null||q.isEmpty()) { send(x,400,"{\"error\":\"INVALID_INPUT\"}"); return; }
41
+ String[] ps = q.split("&");
42
+ if (ps.length!=1) { send(x,400,"{\"error\":\"INVALID_INPUT\"}"); return; }
43
+ int eq = ps[0].indexOf('=');
44
+ if (eq<0||!ps[0].substring(0,eq).equals("expression64")) { send(x,400,"{\"error\":\"INVALID_INPUT\"}"); return; }
45
+ String v = ps[0].substring(eq+1);
46
+ if (v.isEmpty()||v.length()>256) { send(x,400,"{\"error\":\"INVALID_INPUT\"}"); return; }
47
+ for (int i=0;i<v.length();i++) { char c=v.charAt(i); if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||c=='-'||c=='_')) { send(x,400,"{\"error\":\"INVALID_INPUT\"}"); return; } }
48
+ byte[] b; try { b=Base64.getUrlDecoder().decode(v); } catch(Exception e) { send(x,400,"{\"error\":\"INVALID_INPUT\"}"); return; }
49
+ CharsetDecoder d=StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
50
+ CharBuffer cb; try { cb=d.decode(ByteBuffer.wrap(b)); } catch(Exception e) { send(x,400,"{\"error\":\"INVALID_INPUT\"}"); return; }
51
+ String expr=cb.toString();
52
+ if (expr.length()>128) { send(x,422,"{\"error\":\"LIMIT_EXCEEDED\"}"); return; }
53
+ ops=0; depth=0;
54
+ int[] p=new int[]{0};
55
+ BigDecimal r; try { r=parseSum(expr,p); } catch(RE e) { send(x,e.c,e.m); return; }
56
+ int pos=p[0]; while(pos<expr.length()&&expr.charAt(pos)==' ') pos++;
57
+ if (pos!=expr.length()) { send(x,400,"{\"error\":\"INVALID_EXPRESSION\"}"); return; }
58
+ r=r.setScale(12,RoundingMode.HALF_UP).stripTrailingZeros();
59
+ String rs=r.compareTo(BigDecimal.ZERO)==0?"0":r.toPlainString();
60
+ String j="{\"expression\":\""+expr.replace("\\","\\\\").replace("\"","\\\"")+"\",\"result\":\""+rs+"\"}";
61
+ send(x,200,j);
62
+ }
63
+ static void send(HttpExchange x,int c,String b) throws IOException {
64
+ byte[] by=b.getBytes(StandardCharsets.UTF_8);
65
+ x.getResponseHeaders().set("Content-Type","application/json;charset=utf-8");
66
+ x.sendResponseHeaders(c,by.length);
67
+ try(OutputStream o=x.getResponseBody()){o.write(by);}
68
+ }
69
+ static class RE extends RuntimeException { String m; int c; RE(int c,String m){this.c=c;this.m="{\"error\":\""+m+"\"}";} }
70
+ static void chk(BigDecimal v) { if(v.abs().compareTo(new BigDecimal("1E+24"))>0) throw new RE(422,"LIMIT_EXCEEDED"); }
71
+ static BigDecimal parseSum(String e,int[] p) {
72
+ BigDecimal l=parseProduct(e,p);
73
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
74
+ while(p[0]<e.length()&&(e.charAt(p[0])=='+'||e.charAt(p[0])=='-')) {
75
+ char op=e.charAt(p[0]); p[0]++; if(++ops>64) throw new RE(422,"LIMIT_EXCEEDED");
76
+ BigDecimal r=parseProduct(e,p);
77
+ l=op=='+'?l.add(r,MathContext.DECIMAL128):l.subtract(r,MathContext.DECIMAL128); chk(l);
78
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
79
+ }
80
+ return l;
81
+ }
82
+ static BigDecimal parseProduct(String e,int[] p) {
83
+ BigDecimal l=parseUnary(e,p);
84
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
85
+ while(p[0]<e.length()&&(e.charAt(p[0])=='*'||e.charAt(p[0])=='/')) {
86
+ char op=e.charAt(p[0]); p[0]++; if(++ops>64) throw new RE(422,"LIMIT_EXCEEDED");
87
+ BigDecimal r=parseUnary(e,p);
88
+ if(op=='*'){l=l.multiply(r,MathContext.DECIMAL128);}else{if(r.signum()==0)throw new RE(400,"DIVISION_BY_ZERO");l=l.divide(r,30,RoundingMode.HALF_UP);}
89
+ chk(l); while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
90
+ }
91
+ return l;
92
+ }
93
+ static BigDecimal parseUnary(String e,int[] p) {
94
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
95
+ if(p[0]>=e.length()) throw new RE(400,"INVALID_EXPRESSION");
96
+ if(e.charAt(p[0])=='+'||e.charAt(p[0])=='-') {
97
+ int s=1;
98
+ while(p[0]<e.length()&&(e.charAt(p[0])=='+'||e.charAt(p[0])=='-')) {
99
+ if(e.charAt(p[0])=='-') s=-s; p[0]++; if(++ops>64) throw new RE(422,"LIMIT_EXCEEDED");
100
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
101
+ }
102
+ BigDecimal v=parseAtom(e,p); return s==-1?v.negate():v;
103
+ }
104
+ return parseAtom(e,p);
105
+ }
106
+ static BigDecimal parseAtom(String e,int[] p) {
107
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
108
+ if(p[0]>=e.length()) throw new RE(400,"INVALID_EXPRESSION");
109
+ if(e.charAt(p[0])=='(') {
110
+ p[0]++; if(++depth>16) throw new RE(422,"LIMIT_EXCEEDED");
111
+ BigDecimal v=parseSum(e,p);
112
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
113
+ if(p[0]>=e.length()||e.charAt(p[0])!=')') throw new RE(400,"INVALID_EXPRESSION");
114
+ p[0]++; depth--; return v;
115
+ }
116
+ return parseNum(e,p);
117
+ }
118
+ static BigDecimal parseNum(String e,int[] p) {
119
+ while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;
120
+ int s=p[0]; boolean dot=false; boolean hasDigit=false;
121
+ while(p[0]<e.length()&&(e.charAt(p[0])>='0'&&e.charAt(p[0])<='9'||e.charAt(p[0])=='.')) {
122
+ if(e.charAt(p[0])=='.') { if(dot) break; dot=true; } else { hasDigit=true; } p[0]++;
123
+ }
124
+ if(!hasDigit) throw new RE(400,"INVALID_EXPRESSION");
125
+ if(dot&&p[0]>s+1&&e.charAt(p[0]-1)=='.') throw new RE(400,"INVALID_EXPRESSION");
126
+ String t=e.substring(s,p[0]);
127
+ int dc=0; for(int i=0;i<t.length();i++) if(t.charAt(i)>='0'&&t.charAt(i)<='9') dc++;
128
+ if(dc>24) throw new RE(422,"LIMIT_EXCEEDED");
129
+ BigDecimal v=new BigDecimal(t); chk(v); return v;
130
+ }
131
+ }
examples/dependency-recovery-validation.json ADDED
@@ -0,0 +1,460 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "platform_code_digest": "93df1f49cf2297ffdb8edeff3a27e300025e5d62eb18e0aaf6d2a584950f070e",
3
+ "browser": {
4
+ "localization": {
5
+ "checks": [
6
+ "Original wizard submits an explicit recovery policy; conversation tail shows actual phase, elapsed time and read freshness instead of dots",
7
+ "Controlled GET interruption is visible and retries the same task without re-submitting",
8
+ "Repeated compile failure is localized, repaired within the original budget and reaches 39 protected HTTP passes",
9
+ "Recovered files and diff are reviewable; separate Java website calculates and rejects division by zero; original workbench and narrow layout remain usable"
10
+ ],
11
+ "errors": [],
12
+ "controlled_failure": true,
13
+ "external_model_calls": 0,
14
+ "platform_code_digest": "93df1f49cf2297ffdb8edeff3a27e300025e5d62eb18e0aaf6d2a584950f070e",
15
+ "fixture_budget_max_repairs": 2,
16
+ "original_run": "run-62d7d9dde0b34cfeafda9355f01eb185",
17
+ "final_run": "run-62d7d9dde0b34cfeafda9355f01eb185",
18
+ "protected_http_cases": 39,
19
+ "controlled_provider_calls": 5,
20
+ "passed": 4
21
+ },
22
+ "https": {
23
+ "checks": [
24
+ "original conversation shell and all three real sessions work over HTTPS with secure cookies",
25
+ "foreign-origin mutation is rejected before entering the local app",
26
+ "workbench preview click opens the actual Java calculator on the same public HTTPS origin; decimal and error paths operate",
27
+ "application refresh is usable and original workbench remains at root",
28
+ "fresh third-party iframe and null WindowProxy popup receive only an authorized manager lease capability and run real Java",
29
+ "popup receives the exact parent identity; an independent programmer remains denied"
30
+ ],
31
+ "errors": [],
32
+ "platform_code_digest": "93df1f49cf2297ffdb8edeff3a27e300025e5d62eb18e0aaf6d2a584950f070e",
33
+ "cloud_runtime_files": {
34
+ "deploy/hf/adapter.py": "0088b19648ab9661bb6eb6bdf4fa34de368f5fe5d6c347a58504c60331f42e95",
35
+ "deploy/hf/app.py": "0e8a5729b5e99aae88c277d718e0afa6de21350515f92452996d10deac7612f3",
36
+ "deploy/hf/prepare_image.py": "8c548bf8881ee0510fd65e5d2de6b464df3d4212bcc5f736363bbdaac32ff0c7",
37
+ "deploy/hf/Dockerfile": "e18a9d956fec5943436409223be6ec5df6f85be46980a58458e02c9ce3439f31",
38
+ "deploy/hf/preview_bridge.py": "9a5fe782621e8a9afe2ff199f294018ae4910c007244e350c31829eaaf19d093",
39
+ "deploy/hf/scoped_preview.py": "278f70a4cff3b6fabf26d66a648910518356aa6efeba2a46b4a45f4332eee5bf",
40
+ "deploy/hf/preview-parent.js": "3f4dcde23d39cce65b597059ad42d759f8c4b35a76813a2c0f6ffb7483f9a442",
41
+ "deploy/hf/preview-bridge.js": "436c295efd8631f88cbcc46021a14f53173e3c4f6e471e63fcf8b3c1fe6ec014",
42
+ "deploy/hf/preview-bridge.html": "0f709ec2027d6f623cfa5c4b6aad4f104355895fdc768907b8c6dd31a52b06cc"
43
+ },
44
+ "scope": "local HTTPS ingress, not HF runtime",
45
+ "receipt": {
46
+ "source_digest": "b80e5c95d1153f8e664d4b7bac3701d52fecab2a41de12e5a49ea0fd795cd7a4",
47
+ "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
48
+ "config_digest": "ec1c941302d1f0bf34512b9b524f7c8dc5bfd523f22fe50093f8cd757cdfc848",
49
+ "classes_digest": "779f483b28864a212c3e199cedc317c3664d207bc8eab14f7d48e47d6be085ad",
50
+ "tests": 39,
51
+ "network": "none",
52
+ "host_mounts": []
53
+ },
54
+ "passed": 6,
55
+ "tested_at_utc": "2026-10-24T05:48:36.861647+00:00"
56
+ },
57
+ "three_apps": {
58
+ "checks": [
59
+ "erp: exact HF-generated source passes protected tests again, real website operates and refreshes independently",
60
+ "calculator: exact HF-generated source passes protected tests again, real website operates and refreshes independently",
61
+ "pdf: exact HF-generated source passes protected tests again, real website operates and refreshes independently",
62
+ "All three independent real Java websites coexist; original conversation workbench stays at its entry"
63
+ ],
64
+ "errors": [],
65
+ "scenarios": {
66
+ "erp": {
67
+ "generation_run": "run-8f523ff16b6b4c95832e46b4b6110a8d",
68
+ "source_digest": "86f2fd3b99c6f8b21ceb2595171ed841194fcc7c791b60ea1a8cf0d90d6ba1be",
69
+ "lease": "3e50b8de27e94ce78901cbfb5b62cf5d",
70
+ "receipt": {
71
+ "source_digest": "86f2fd3b99c6f8b21ceb2595171ed841194fcc7c791b60ea1a8cf0d90d6ba1be",
72
+ "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
73
+ "config_digest": "841129aac9dd785fe877d72002533547377a93994d0afb830dadb1273b51389a",
74
+ "classes_digest": "ba589b760a2583fe523da87f68e84a69e3914972b2cb6417c9a44f768ba604a1",
75
+ "tests": 25,
76
+ "network": "none",
77
+ "host_mounts": []
78
+ }
79
+ },
80
+ "calculator": {
81
+ "generation_run": "run-4e2329b555864957bc5b477ae1432717",
82
+ "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798",
83
+ "lease": "c2c0b69ee9fe42788c640bbbc41b721c",
84
+ "receipt": {
85
+ "source_digest": "e1c26eeccec092a09b3481bc6f601f6f02b043b0e0e41219ff67a2e295b6a798",
86
+ "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
87
+ "config_digest": "ec1c941302d1f0bf34512b9b524f7c8dc5bfd523f22fe50093f8cd757cdfc848",
88
+ "classes_digest": "31888e310a086e6807cc096b7bdb06164ae9a556c8f582228d9e9d7b43b0b6cf",
89
+ "tests": 39,
90
+ "network": "none",
91
+ "host_mounts": []
92
+ }
93
+ },
94
+ "pdf": {
95
+ "generation_run": "run-415025244a2a42f09cb63bc4e17902ca",
96
+ "source_digest": "9f3208baf0d4fa933050bde2753eee151517a6e197f2983a14bfdc7c92d9e79b",
97
+ "lease": "1303f1ab52e943f68fb29389516cc6c6",
98
+ "receipt": {
99
+ "source_digest": "9f3208baf0d4fa933050bde2753eee151517a6e197f2983a14bfdc7c92d9e79b",
100
+ "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
101
+ "config_digest": "128defe2109c8b7693134f252f9235bc863b5915fc11d640b8bd52394e589c72",
102
+ "classes_digest": "84d779e18a69c02f3dd173aa8899c5eb2a4688958424aebdacb467c44c50e3fe",
103
+ "tests": 23,
104
+ "network": "none",
105
+ "host_mounts": []
106
+ }
107
+ }
108
+ },
109
+ "external_model_calls": 0,
110
+ "platform_code_digest": "93df1f49cf2297ffdb8edeff3a27e300025e5d62eb18e0aaf6d2a584950f070e",
111
+ "scope": "Exact prior HF-generated source replay on local QEMU, not a new cloud generation",
112
+ "passed": 4
113
+ },
114
+ "main": {
115
+ "passed": 3,
116
+ "checks": [
117
+ "Original 8789 shell and three real users remain usable",
118
+ "8810 QA was separate: production workbench still uses 8789 and independent 8791 previews",
119
+ "Wizard injects full brief into original composer and discloses bounded recovery before send"
120
+ ],
121
+ "errors": [],
122
+ "model_calls_started": 0,
123
+ "platform_code_digest": "93df1f49cf2297ffdb8edeff3a27e300025e5d62eb18e0aaf6d2a584950f070e"
124
+ }
125
+ },
126
+ "unit_tests": {
127
+ "total": 255,
128
+ "passed": 253,
129
+ "skipped": 2
130
+ },
131
+ "hf_unit_tests": {
132
+ "passed": 27
133
+ },
134
+ "real_model_repair": {
135
+ "status": "verified",
136
+ "origin": "run-5f29adca2f124701a0833fefb0ea2ff1",
137
+ "run_id": "run-fa45e3ec4b2e48e599c6e799a6f51547",
138
+ "analysis": {
139
+ "summary": "Root cause: The trailing-character check in calc() uses a fresh local `int pos=0` instead of the parser's mutable cursor `p[0]`. After parseSum(\"2+3\", p) returns, p[0]==3 (end of input), but `pos` is reset to 0. The loop `while(pos<expr.length()&&expr.charAt(pos)==' ') pos++;` finds no spaces, leaving pos==0. Then `if(pos!=expr.length())` evaluates `0!=3`, which is true, so every valid expression incorrectly returns 400 INVALID_EXPRESSION. This branch is the only path producing that exact status and body for these inputs. Fix: Replace `int pos=0; while(pos<expr.length()&&expr.charAt(pos)==' ') pos++; if(pos!=expr.length())` with `int[] p=new int[]{0}; ... int pos=p[0]; while(pos<expr.length()&&expr.charAt(pos)==' ') pos++; if(pos!=expr.length())`. Pass `p` into parseSum and reuse it for the end-of-input check."
140
+ },
141
+ "source": {
142
+ "files": {
143
+ "src/main/java/demo/App.java": "package demo;\n\nimport com.sun.net.httpserver.HttpServer;\nimport com.sun.net.httpserver.HttpExchange;\nimport java.io.*;\nimport java.math.*;\nimport java.net.InetSocketAddress;\nimport java.nio.ByteBuffer;\nimport java.nio.CharBuffer;\nimport java.nio.charset.*;\nimport java.util.Base64;\n\npublic class App {\n static int ops, depth;\n public static void main(String[] args) throws Exception {\n HttpServer s = HttpServer.create(new InetSocketAddress(8080), 0);\n s.createContext(\"/\", App::handle);\n s.setExecutor(null);\n s.start();\n }\n static void handle(HttpExchange x) throws IOException {\n try { doHandle(x); } finally { x.close(); }\n }\n static void doHandle(HttpExchange x) throws IOException {\n String p = x.getRequestURI().getPath();\n if (p.equals(\"/health\")) {\n if (!x.getRequestMethod().equals(\"GET\")) { send(x,405,\"{\\\"error\\\":\\\"METHOD_NOT_ALLOWED\\\"}\"); return; }\n send(x,200,\"{\\\"status\\\":\\\"ok\\\"}\"); return;\n }\n if (p.equals(\"/api/calculate\")) {\n if (!x.getRequestMethod().equals(\"GET\")) { send(x,405,\"{\\\"error\\\":\\\"METHOD_NOT_ALLOWED\\\"}\"); return; }\n String a = x.getRequestHeaders().getFirst(\"Authorization\");\n if (a==null||!a.equals(\"Bearer demo-calculator\")) { send(x,401,\"{\\\"error\\\":\\\"UNAUTHORIZED\\\"}\"); return; }\n calc(x); return;\n }\n send(x,404,\"{\\\"error\\\":\\\"NOT_FOUND\\\"}\");\n }\n static void calc(HttpExchange x) throws IOException {\n String q = x.getRequestURI().getRawQuery();\n if (q==null||q.isEmpty()) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n String[] ps = q.split(\"&\");\n if (ps.length!=1) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n int eq = ps[0].indexOf('=');\n if (eq<0||!ps[0].substring(0,eq).equals(\"expression64\")) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n String v = ps[0].substring(eq+1);\n if (v.isEmpty()||v.length()>256) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n for (int i=0;i<v.length();i++) { char c=v.charAt(i); if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||c=='-'||c=='_')) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; } }\n byte[] b; try { b=Base64.getUrlDecoder().decode(v); } catch(Exception e) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n CharsetDecoder d=StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);\n CharBuffer cb; try { cb=d.decode(ByteBuffer.wrap(b)); } catch(Exception e) { send(x,400,\"{\\\"error\\\":\\\"INVALID_INPUT\\\"}\"); return; }\n String expr=cb.toString();\n if (expr.length()>128) { send(x,422,\"{\\\"error\\\":\\\"LIMIT_EXCEEDED\\\"}\"); return; }\n ops=0; depth=0;\n int[] p=new int[]{0};\n BigDecimal r; try { r=parseSum(expr,p); } catch(RE e) { send(x,e.c,e.m); return; }\n int pos=p[0]; while(pos<expr.length()&&expr.charAt(pos)==' ') pos++;\n if (pos!=expr.length()) { send(x,400,\"{\\\"error\\\":\\\"INVALID_EXPRESSION\\\"}\"); return; }\n r=r.setScale(12,RoundingMode.HALF_UP).stripTrailingZeros();\n String rs=r.compareTo(BigDecimal.ZERO)==0?\"0\":r.toPlainString();\n String j=\"{\\\"expression\\\":\\\"\"+expr.replace(\"\\\\\",\"\\\\\\\\\").replace(\"\\\"\",\"\\\\\\\"\")+\"\\\",\\\"result\\\":\\\"\"+rs+\"\\\"}\";\n send(x,200,j);\n }\n static void send(HttpExchange x,int c,String b) throws IOException {\n byte[] by=b.getBytes(StandardCharsets.UTF_8);\n x.getResponseHeaders().set(\"Content-Type\",\"application/json;charset=utf-8\");\n x.sendResponseHeaders(c,by.length);\n try(OutputStream o=x.getResponseBody()){o.write(by);}\n }\n static class RE extends RuntimeException { String m; int c; RE(int c,String m){this.c=c;this.m=\"{\\\"error\\\":\\\"\"+m+\"\\\"}\";} }\n static void chk(BigDecimal v) { if(v.abs().compareTo(new BigDecimal(\"1E+24\"))>0) throw new RE(422,\"LIMIT_EXCEEDED\"); }\n static BigDecimal parseSum(String e,int[] p) {\n BigDecimal l=parseProduct(e,p);\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n while(p[0]<e.length()&&(e.charAt(p[0])=='+'||e.charAt(p[0])=='-')) {\n char op=e.charAt(p[0]); p[0]++; if(++ops>64) throw new RE(422,\"LIMIT_EXCEEDED\");\n BigDecimal r=parseProduct(e,p);\n l=op=='+'?l.add(r,MathContext.DECIMAL128):l.subtract(r,MathContext.DECIMAL128); chk(l);\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n }\n return l;\n }\n static BigDecimal parseProduct(String e,int[] p) {\n BigDecimal l=parseUnary(e,p);\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n while(p[0]<e.length()&&(e.charAt(p[0])=='*'||e.charAt(p[0])=='/')) {\n char op=e.charAt(p[0]); p[0]++; if(++ops>64) throw new RE(422,\"LIMIT_EXCEEDED\");\n BigDecimal r=parseUnary(e,p);\n if(op=='*'){l=l.multiply(r,MathContext.DECIMAL128);}else{if(r.signum()==0)throw new RE(400,\"DIVISION_BY_ZERO\");l=l.divide(r,30,RoundingMode.HALF_UP);}\n chk(l); while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n }\n return l;\n }\n static BigDecimal parseUnary(String e,int[] p) {\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n if(p[0]>=e.length()) throw new RE(400,\"INVALID_EXPRESSION\");\n if(e.charAt(p[0])=='+'||e.charAt(p[0])=='-') {\n int s=1;\n while(p[0]<e.length()&&(e.charAt(p[0])=='+'||e.charAt(p[0])=='-')) {\n if(e.charAt(p[0])=='-') s=-s; p[0]++; if(++ops>64) throw new RE(422,\"LIMIT_EXCEEDED\");\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n }\n BigDecimal v=parseAtom(e,p); return s==-1?v.negate():v;\n }\n return parseAtom(e,p);\n }\n static BigDecimal parseAtom(String e,int[] p) {\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n if(p[0]>=e.length()) throw new RE(400,\"INVALID_EXPRESSION\");\n if(e.charAt(p[0])=='(') {\n p[0]++; if(++depth>16) throw new RE(422,\"LIMIT_EXCEEDED\");\n BigDecimal v=parseSum(e,p);\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n if(p[0]>=e.length()||e.charAt(p[0])!=')') throw new RE(400,\"INVALID_EXPRESSION\");\n p[0]++; depth--; return v;\n }\n return parseNum(e,p);\n }\n static BigDecimal parseNum(String e,int[] p) {\n while(p[0]<e.length()&&e.charAt(p[0])==' ') p[0]++;\n int s=p[0]; boolean dot=false; boolean hasDigit=false;\n while(p[0]<e.length()&&(e.charAt(p[0])>='0'&&e.charAt(p[0])<='9'||e.charAt(p[0])=='.')) {\n if(e.charAt(p[0])=='.') { if(dot) break; dot=true; } else { hasDigit=true; } p[0]++;\n }\n if(!hasDigit) throw new RE(400,\"INVALID_EXPRESSION\");\n if(dot&&p[0]>s+1&&e.charAt(p[0]-1)=='.') throw new RE(400,\"INVALID_EXPRESSION\");\n String t=e.substring(s,p[0]);\n int dc=0; for(int i=0;i<t.length();i++) if(t.charAt(i)>='0'&&t.charAt(i)<='9') dc++;\n if(dc>24) throw new RE(422,\"LIMIT_EXCEEDED\");\n BigDecimal v=new BigDecimal(t); chk(v); return v;\n }\n}"
144
+ },
145
+ "source_digest": "235d2b5bc9d1583691fece244daafbb9994a730cd26305e88402cc65973008e2"
146
+ },
147
+ "candidate": {
148
+ "source_digest": "235d2b5bc9d1583691fece244daafbb9994a730cd26305e88402cc65973008e2",
149
+ "classes_digest": "6ad41c4e8745087648e92d02c503575abcf07e69a7455b34f1b8606a1bcbc4f2",
150
+ "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
151
+ "suite_digest": "05e353f239f8919946d419e91e63fedccbf62b02386fa12f39ad8795b6a4de4d",
152
+ "config_digest": "ec1c941302d1f0bf34512b9b524f7c8dc5bfd523f22fe50093f8cd757cdfc848",
153
+ "execution_mode": "qemu",
154
+ "container": "zk-run-33c6f3ed0a6d4be7bbf5c79af3ca4e55",
155
+ "stage": "build",
156
+ "passed": true,
157
+ "receipt_ref": "run-33c6f3ed0a6d4be7bbf5c79af3ca4e55-b5314964b0c842cb90f1dafbf3ab4914",
158
+ "receipt_digest": "985604d60097aa1f7d4d0d690187a4c58e4162c3ecef4849e568fac6e1feaae7",
159
+ "isolation": {
160
+ "network": "none",
161
+ "host_mounts": [],
162
+ "memory_mb": 1024,
163
+ "vcpu": 1,
164
+ "disposable": true
165
+ }
166
+ },
167
+ "test": {
168
+ "source_digest": "235d2b5bc9d1583691fece244daafbb9994a730cd26305e88402cc65973008e2",
169
+ "classes_digest": "6ad41c4e8745087648e92d02c503575abcf07e69a7455b34f1b8606a1bcbc4f2",
170
+ "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
171
+ "suite_digest": "05e353f239f8919946d419e91e63fedccbf62b02386fa12f39ad8795b6a4de4d",
172
+ "config_digest": "ec1c941302d1f0bf34512b9b524f7c8dc5bfd523f22fe50093f8cd757cdfc848",
173
+ "execution_mode": "qemu",
174
+ "container": "zk-run-33c6f3ed0a6d4be7bbf5c79af3ca4e55",
175
+ "stage": "test",
176
+ "passed": true,
177
+ "receipt_ref": "run-33c6f3ed0a6d4be7bbf5c79af3ca4e55-b5314964b0c842cb90f1dafbf3ab4914",
178
+ "receipt_digest": "985604d60097aa1f7d4d0d690187a4c58e4162c3ecef4849e568fac6e1feaae7",
179
+ "isolation": {
180
+ "network": "none",
181
+ "host_mounts": [],
182
+ "memory_mb": 1024,
183
+ "vcpu": 1,
184
+ "disposable": true
185
+ },
186
+ "cases": 39,
187
+ "passed_cases": 39,
188
+ "preview_scope": "disposable-vm-loopback-http"
189
+ },
190
+ "preview": {
191
+ "source_digest": "235d2b5bc9d1583691fece244daafbb9994a730cd26305e88402cc65973008e2",
192
+ "classes_digest": "6ad41c4e8745087648e92d02c503575abcf07e69a7455b34f1b8606a1bcbc4f2",
193
+ "image": "zkcoding-qemu@sha256:123b955068e212a3cb1cf6db348cc8efab24c44ca2b4fb67835100845a9e7ddf",
194
+ "suite_digest": "05e353f239f8919946d419e91e63fedccbf62b02386fa12f39ad8795b6a4de4d",
195
+ "config_digest": "ec1c941302d1f0bf34512b9b524f7c8dc5bfd523f22fe50093f8cd757cdfc848",
196
+ "execution_mode": "qemu",
197
+ "container": "zk-run-33c6f3ed0a6d4be7bbf5c79af3ca4e55",
198
+ "stage": "preview",
199
+ "passed": true,
200
+ "receipt_ref": "run-33c6f3ed0a6d4be7bbf5c79af3ca4e55-b5314964b0c842cb90f1dafbf3ab4914",
201
+ "receipt_digest": "985604d60097aa1f7d4d0d690187a4c58e4162c3ecef4849e568fac6e1feaae7",
202
+ "isolation": {
203
+ "network": "none",
204
+ "host_mounts": [],
205
+ "memory_mb": 1024,
206
+ "vcpu": 1,
207
+ "disposable": true
208
+ },
209
+ "cases": 1,
210
+ "passed_cases": 1,
211
+ "preview_scope": "disposable-vm-loopback-http"
212
+ },
213
+ "model_calls": [
214
+ {
215
+ "id": 1,
216
+ "run_id": "run-fa45e3ec4b2e48e599c6e799a6f51547",
217
+ "reservation": 16112,
218
+ "charged": 4079,
219
+ "state": "settled",
220
+ "provider": "bailian-qwen3.8-max",
221
+ "prompt_digest": "d4861366ccadd8ce9b7ee61715bfb71bc7b7e8aa005bf265e5dab91c7ed6013c",
222
+ "metadata": {
223
+ "finish_reason": "stop",
224
+ "model": "qwen3.8-max",
225
+ "policy_version": "bailian-task-routing-v3",
226
+ "request_id": "chatcmpl-068b22cc-4ca0-9c07-a8ed-6ac997e17d4c",
227
+ "requested_output_tokens": 2048,
228
+ "retry_of": null,
229
+ "route_reason": "failure-localization",
230
+ "stage": "diagnose"
231
+ }
232
+ },
233
+ {
234
+ "id": 2,
235
+ "run_id": "run-fa45e3ec4b2e48e599c6e799a6f51547",
236
+ "reservation": 26946,
237
+ "charged": 6471,
238
+ "state": "settled",
239
+ "provider": "bailian-qwen3.8-max",
240
+ "prompt_digest": "b04e80b6b1f079ca22822a75d3eeac321d40ae52791333ff7ac7efce3b068fc7",
241
+ "metadata": {
242
+ "finish_reason": "stop",
243
+ "model": "qwen3.8-max",
244
+ "policy_version": "bailian-task-routing-v3",
245
+ "request_id": "chatcmpl-4bb498cc-8895-9874-a106-a2ec2f9e04a3",
246
+ "requested_output_tokens": 12288,
247
+ "retry_of": null,
248
+ "route_reason": "diagnostic-repair",
249
+ "stage": "repair"
250
+ }
251
+ }
252
+ ],
253
+ "human_acceptance": false,
254
+ "method": "independent routed diagnosis then model repair; no human source edits"
255
+ },
256
+ "dependency_transfer": {
257
+ "status": "verified",
258
+ "artifact": "org.apache.pdfbox:pdfbox-app:3.0.8",
259
+ "bytes": 13602031,
260
+ "lock": {
261
+ "schema": "java-dependency-lock-v1",
262
+ "roots": [
263
+ "org.apache.pdfbox:pdfbox-app:3.0.8"
264
+ ],
265
+ "artifacts": [
266
+ {
267
+ "coordinate": "org.apache.pdfbox:pdfbox-app:3.0.8",
268
+ "sha512": "768847238f683568507bf73570a2b6fedcbe58b25c7b4f97fba536ba110b290fe96ba065aed58629d41fb94857d76bc1978c2f31d294b553c69f287f71ee9600",
269
+ "license": "Apache-2.0; bundled notices preserved",
270
+ "max_bytes": 20000000
271
+ }
272
+ ],
273
+ "digest": "9eddd7f39e33b6c48e070ffb8bb9c2371a6d5e9aebd19551cd2f693b98583265"
274
+ },
275
+ "bundle_sha256": "e74cbde30958dfcfe4685bf4caa0775167a636f221e95da44e6c9bcf1d6d9975",
276
+ "network_calls": 0,
277
+ "empty_destination_cache": true,
278
+ "tampered_cache_rejected": true,
279
+ "java_executed_on_host": false,
280
+ "scope": "approved PDFBox closure portability; not a complete Maven project build"
281
+ },
282
+ "failed_local_diagnosis": {
283
+ "analysis": {
284
+ "summary": "The handler returns INVALID_EXPRESSION because the base64url decoder rejects unpadded input. Java's Base64.getUrlDecoder() mandates padding, but the contract requires canonical UNPADDED strings. Decoding fails for all test cases (e.g., 'Misz' -> 3 bytes, needs no padding). Fix: Before decoding, manually append '=' characters to make the encoded string length a multiple of 4. Alternatively, implement a custom decoder that processes 4-character blocks without requiring trailing '='. The current code catches the IllegalArgumentException from decode() and maps it to INVALID_INPUT or INVALID_EXPRESSION depending on flow, but here it likely hits the generic catch or validation logic incorrectly. Specifically, ensure `v` is padded to `(v.length()+3)/4*4` before passing to `Base64.getUrlDecoder().decode()`."
285
+ },
286
+ "source_digest": "fb192b3efb20cf844e15673c838091153d04fb628c731c5d6c77bd504969885e",
287
+ "test": {
288
+ "cases": 39,
289
+ "classes_digest": "0f8683d2bf16e5c6d103cdda53a1ada3d35e10e83e17148e77a9611f0c37f8b4",
290
+ "failures": [
291
+ {
292
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
293
+ "actual_status": 400,
294
+ "case_index": 1,
295
+ "expected_status": 200,
296
+ "path": "/api/calculate?expression64=Misz",
297
+ "reason": "response_did_not_match_public_contract"
298
+ },
299
+ {
300
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
301
+ "actual_status": 400,
302
+ "case_index": 2,
303
+ "expected_status": 200,
304
+ "path": "/api/calculate?expression64=MTAtMTM",
305
+ "reason": "response_did_not_match_public_contract"
306
+ },
307
+ {
308
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
309
+ "actual_status": 400,
310
+ "case_index": 3,
311
+ "expected_status": 200,
312
+ "path": "/api/calculate?expression64=Nio3",
313
+ "reason": "response_did_not_match_public_contract"
314
+ },
315
+ {
316
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
317
+ "actual_status": 400,
318
+ "case_index": 4,
319
+ "expected_status": 200,
320
+ "path": "/api/calculate?expression64=OC8y",
321
+ "reason": "response_did_not_match_public_contract"
322
+ },
323
+ {
324
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
325
+ "actual_status": 400,
326
+ "case_index": 5,
327
+ "expected_status": 200,
328
+ "path": "/api/calculate?expression64=MiszKjQ",
329
+ "reason": "response_did_not_match_public_contract"
330
+ },
331
+ {
332
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
333
+ "actual_status": 400,
334
+ "case_index": 6,
335
+ "expected_status": 200,
336
+ "path": "/api/calculate?expression64=KDIrMykqNA",
337
+ "reason": "response_did_not_match_public_contract"
338
+ },
339
+ {
340
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
341
+ "actual_status": 400,
342
+ "case_index": 7,
343
+ "expected_status": 200,
344
+ "path": "/api/calculate?expression64=MC4xKzAuMg",
345
+ "reason": "response_did_not_match_public_contract"
346
+ },
347
+ {
348
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
349
+ "actual_status": 400,
350
+ "case_index": 8,
351
+ "expected_status": 200,
352
+ "path": "/api/calculate?expression64=LSgyKzMpKi0y",
353
+ "reason": "response_did_not_match_public_contract"
354
+ },
355
+ {
356
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
357
+ "actual_status": 400,
358
+ "case_index": 9,
359
+ "expected_status": 200,
360
+ "path": "/api/calculate?expression64=MTAvMiozLTE",
361
+ "reason": "response_did_not_match_public_contract"
362
+ },
363
+ {
364
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
365
+ "actual_status": 400,
366
+ "case_index": 10,
367
+ "expected_status": 200,
368
+ "path": "/api/calculate?expression64=MS82",
369
+ "reason": "response_did_not_match_public_contract"
370
+ },
371
+ {
372
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
373
+ "actual_status": 400,
374
+ "case_index": 11,
375
+ "expected_status": 200,
376
+ "path": "/api/calculate?expression64=LTA",
377
+ "reason": "response_did_not_match_public_contract"
378
+ },
379
+ {
380
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
381
+ "actual_status": 400,
382
+ "case_index": 12,
383
+ "expected_status": 200,
384
+ "path": "/api/calculate?expression64=LjUrLjI1",
385
+ "reason": "response_did_not_match_public_contract"
386
+ },
387
+ {
388
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
389
+ "actual_status": 400,
390
+ "case_index": 13,
391
+ "expected_status": 200,
392
+ "path": "/api/calculate?expression64=IDEyICsgKCAzICogMiApIA",
393
+ "reason": "response_did_not_match_public_contract"
394
+ },
395
+ {
396
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
397
+ "actual_status": 400,
398
+ "case_index": 14,
399
+ "expected_status": 200,
400
+ "path": "/api/calculate?expression64=KCgoKCgoKCgoKCgoKCgoKDEpKSkpKSkpKSkpKSkpKSkp",
401
+ "reason": "response_did_not_match_public_contract"
402
+ },
403
+ {
404
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
405
+ "actual_status": 400,
406
+ "case_index": 15,
407
+ "expected_status": 200,
408
+ "path": "/api/calculate?expression64=MTAwMDAwMDAwMDAwMCoxMDAwMDAwMDAwMDAw",
409
+ "reason": "response_did_not_match_public_contract"
410
+ }
411
+ ],
412
+ "passed": false,
413
+ "passed_cases": 24
414
+ },
415
+ "model_calls": [
416
+ {
417
+ "id": 1,
418
+ "run_id": "run-b7ee1e2ce7d64070a5fa66f72c4287d5",
419
+ "reservation": 15719,
420
+ "charged": 3954,
421
+ "state": "settled",
422
+ "provider": "bailian-qwen3.8-flash",
423
+ "prompt_digest": "f92b0718e8b386af50d5150c0b0a25ea03ff716cf1313baf9a57d740f88901a4",
424
+ "metadata": {
425
+ "finish_reason": "stop",
426
+ "model": "qwen3.8-flash",
427
+ "policy_version": "bailian-task-routing-v3",
428
+ "request_id": "chatcmpl-7bad8a9f-a292-955f-9581-ad51f6927caf",
429
+ "requested_output_tokens": 2048,
430
+ "retry_of": null,
431
+ "route_reason": "failure-localization",
432
+ "stage": "diagnose"
433
+ }
434
+ },
435
+ {
436
+ "id": 2,
437
+ "run_id": "run-b7ee1e2ce7d64070a5fa66f72c4287d5",
438
+ "reservation": 26933,
439
+ "charged": 6438,
440
+ "state": "settled",
441
+ "provider": "bailian-qwen3.8-max",
442
+ "prompt_digest": "30dea087a30d23346b6133d87a064da38ee65788b538018008681224d711e876",
443
+ "metadata": {
444
+ "finish_reason": "stop",
445
+ "model": "qwen3.8-max",
446
+ "policy_version": "bailian-task-routing-v3",
447
+ "request_id": "chatcmpl-b0f68dde-cce7-99eb-9a41-3e139a973f42",
448
+ "requested_output_tokens": 12288,
449
+ "retry_of": null,
450
+ "route_reason": "diagnostic-repair",
451
+ "stage": "repair"
452
+ }
453
+ }
454
+ ],
455
+ "runner_error": "EVIDENCE_BINDING_MISMATCH; test outcome retained in the independently bound VM receipt"
456
+ },
457
+ "cloud_candidate_verified": false,
458
+ "human_acceptance": false,
459
+ "tested_at_utc": "2026-10-24T05:53:47.662113+00:00"
460
+ }
examples/hf-cloud-fourth-candidate.json ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "space_commit": "253a5d441bdd1e9c7fd3647d93b0e8c0e17f6844",
3
+ "cloud_end_to_end_verified": false,
4
+ "failure": "AssertionError: {'scenario': 'calculator', 'state': 'failed', 'error': 'JAVA_TEST_FAILED'}",
5
+ "child": {
6
+ "id": "run-5f29adca2f124701a0833fefb0ea2ff1",
7
+ "status": "failed",
8
+ "error": "JAVA_TEST_FAILED",
9
+ "repairs": 2,
10
+ "model_calls": [
11
+ {
12
+ "id": 5,
13
+ "run_id": "run-5f29adca2f124701a0833fefb0ea2ff1",
14
+ "reservation": 19034,
15
+ "charged": 5198,
16
+ "state": "settled",
17
+ "provider": "bailian-qwen3.8-flash",
18
+ "prompt_digest": "5cd8f148f17ef09b28c62541a64ef9f9d952cc24db599344f47a0c8f66ce1e10",
19
+ "metadata": {
20
+ "finish_reason": "stop",
21
+ "model": "qwen3.8-flash",
22
+ "policy_version": "bailian-task-routing-v2",
23
+ "request_id": "chatcmpl-b1871ec0-1774-96b7-b192-3da466a4aec1",
24
+ "requested_output_tokens": 2048,
25
+ "retry_of": null,
26
+ "route_reason": "technical-design",
27
+ "stage": "design"
28
+ }
29
+ },
30
+ {
31
+ "id": 6,
32
+ "run_id": "run-5f29adca2f124701a0833fefb0ea2ff1",
33
+ "reservation": 32000,
34
+ "charged": 8709,
35
+ "state": "settled",
36
+ "provider": "bailian-qwen3.8-max",
37
+ "prompt_digest": "cc56405a1913d988325ffc4f19310c3cc2d1cb071eec1c10d0a39a6c9016df01",
38
+ "metadata": {
39
+ "finish_reason": "stop",
40
+ "model": "qwen3.8-max",
41
+ "policy_version": "bailian-task-routing-v2",
42
+ "request_id": "chatcmpl-6ef2ed00-5e3a-9bf7-bee5-74e5c8a515ab",
43
+ "requested_output_tokens": 8889,
44
+ "retry_of": null,
45
+ "route_reason": "diagnostic-repair",
46
+ "stage": "code"
47
+ }
48
+ },
49
+ {
50
+ "id": 7,
51
+ "run_id": "run-5f29adca2f124701a0833fefb0ea2ff1",
52
+ "reservation": 30107,
53
+ "charged": 7362,
54
+ "state": "settled",
55
+ "provider": "bailian-qwen3.8-max",
56
+ "prompt_digest": "cba1c461fea599dee01427e6a44e0f6e80b51871a16ad5c87e34450c8186830c",
57
+ "metadata": {
58
+ "finish_reason": "stop",
59
+ "model": "qwen3.8-max",
60
+ "policy_version": "bailian-task-routing-v2",
61
+ "request_id": "chatcmpl-adf5bb30-07a6-9136-95d2-b0e26e807802",
62
+ "requested_output_tokens": 12288,
63
+ "retry_of": null,
64
+ "route_reason": "diagnostic-repair",
65
+ "stage": "repair"
66
+ }
67
+ },
68
+ {
69
+ "id": 8,
70
+ "run_id": "run-5f29adca2f124701a0833fefb0ea2ff1",
71
+ "reservation": 30108,
72
+ "charged": 7396,
73
+ "state": "settled",
74
+ "provider": "bailian-qwen3.8-max",
75
+ "prompt_digest": "aa1410eaae121c0a51ddd87394fac1cfe56ca1fb8fda906e88fc80104df072dd",
76
+ "metadata": {
77
+ "finish_reason": "stop",
78
+ "model": "qwen3.8-max",
79
+ "policy_version": "bailian-task-routing-v2",
80
+ "request_id": "chatcmpl-e5a28658-dae6-920b-abfd-0334b5e907eb",
81
+ "requested_output_tokens": 12288,
82
+ "retry_of": null,
83
+ "route_reason": "diagnostic-repair",
84
+ "stage": "repair"
85
+ }
86
+ }
87
+ ],
88
+ "diagnostics": {
89
+ "failures": [
90
+ {
91
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
92
+ "actual_status": 400,
93
+ "case_index": 1,
94
+ "expected_status": 200,
95
+ "path": "/api/calculate?expression64=Misz",
96
+ "reason": "response_did_not_match_public_contract"
97
+ },
98
+ {
99
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
100
+ "actual_status": 400,
101
+ "case_index": 2,
102
+ "expected_status": 200,
103
+ "path": "/api/calculate?expression64=MTAtMTM",
104
+ "reason": "response_did_not_match_public_contract"
105
+ },
106
+ {
107
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
108
+ "actual_status": 400,
109
+ "case_index": 3,
110
+ "expected_status": 200,
111
+ "path": "/api/calculate?expression64=Nio3",
112
+ "reason": "response_did_not_match_public_contract"
113
+ },
114
+ {
115
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
116
+ "actual_status": 400,
117
+ "case_index": 4,
118
+ "expected_status": 200,
119
+ "path": "/api/calculate?expression64=OC8y",
120
+ "reason": "response_did_not_match_public_contract"
121
+ },
122
+ {
123
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
124
+ "actual_status": 400,
125
+ "case_index": 5,
126
+ "expected_status": 200,
127
+ "path": "/api/calculate?expression64=MiszKjQ",
128
+ "reason": "response_did_not_match_public_contract"
129
+ },
130
+ {
131
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
132
+ "actual_status": 400,
133
+ "case_index": 6,
134
+ "expected_status": 200,
135
+ "path": "/api/calculate?expression64=KDIrMykqNA",
136
+ "reason": "response_did_not_match_public_contract"
137
+ },
138
+ {
139
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
140
+ "actual_status": 400,
141
+ "case_index": 7,
142
+ "expected_status": 200,
143
+ "path": "/api/calculate?expression64=MC4xKzAuMg",
144
+ "reason": "response_did_not_match_public_contract"
145
+ },
146
+ {
147
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
148
+ "actual_status": 400,
149
+ "case_index": 8,
150
+ "expected_status": 200,
151
+ "path": "/api/calculate?expression64=LSgyKzMpKi0y",
152
+ "reason": "response_did_not_match_public_contract"
153
+ },
154
+ {
155
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
156
+ "actual_status": 400,
157
+ "case_index": 9,
158
+ "expected_status": 200,
159
+ "path": "/api/calculate?expression64=MTAvMiozLTE",
160
+ "reason": "response_did_not_match_public_contract"
161
+ },
162
+ {
163
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
164
+ "actual_status": 400,
165
+ "case_index": 10,
166
+ "expected_status": 200,
167
+ "path": "/api/calculate?expression64=MS82",
168
+ "reason": "response_did_not_match_public_contract"
169
+ },
170
+ {
171
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
172
+ "actual_status": 400,
173
+ "case_index": 11,
174
+ "expected_status": 200,
175
+ "path": "/api/calculate?expression64=LTA",
176
+ "reason": "response_did_not_match_public_contract"
177
+ },
178
+ {
179
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
180
+ "actual_status": 400,
181
+ "case_index": 12,
182
+ "expected_status": 200,
183
+ "path": "/api/calculate?expression64=LjUrLjI1",
184
+ "reason": "response_did_not_match_public_contract"
185
+ },
186
+ {
187
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
188
+ "actual_status": 400,
189
+ "case_index": 13,
190
+ "expected_status": 200,
191
+ "path": "/api/calculate?expression64=IDEyICsgKCAzICogMiApIA",
192
+ "reason": "response_did_not_match_public_contract"
193
+ },
194
+ {
195
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
196
+ "actual_status": 400,
197
+ "case_index": 14,
198
+ "expected_status": 200,
199
+ "path": "/api/calculate?expression64=KCgoKCgoKCgoKCgoKCgoKDEpKSkpKSkpKSkpKSkpKSkp",
200
+ "reason": "response_did_not_match_public_contract"
201
+ },
202
+ {
203
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
204
+ "actual_status": 400,
205
+ "case_index": 15,
206
+ "expected_status": 200,
207
+ "path": "/api/calculate?expression64=MTAwMDAwMDAwMDAwMCoxMDAwMDAwMDAwMDAw",
208
+ "reason": "response_did_not_match_public_contract"
209
+ }
210
+ ]
211
+ }
212
+ },
213
+ "note": "Root and one automatic continuation both failed; independent local diagnosis/repair proof does not change these failures.",
214
+ "root": {
215
+ "id": "run-c3fb61ee182e4fc394f9ae6fb841b770",
216
+ "status": "failed",
217
+ "error": "JAVA_TEST_FAILED",
218
+ "model_calls": [
219
+ {
220
+ "id": 1,
221
+ "run_id": "run-c3fb61ee182e4fc394f9ae6fb841b770",
222
+ "reservation": 18848,
223
+ "charged": 5141,
224
+ "state": "settled",
225
+ "provider": "bailian-qwen3.8-flash",
226
+ "prompt_digest": "94c9e52243d0debca330c2f106079280652a07cdc55f55143214d3d3cee96279",
227
+ "metadata": {
228
+ "finish_reason": "stop",
229
+ "model": "qwen3.8-flash",
230
+ "policy_version": "bailian-task-routing-v2",
231
+ "request_id": "chatcmpl-d086d89d-34e9-9b6e-8249-02c9ca13bacf",
232
+ "requested_output_tokens": 2048,
233
+ "retry_of": null,
234
+ "route_reason": "technical-design",
235
+ "stage": "design"
236
+ }
237
+ },
238
+ {
239
+ "id": 2,
240
+ "run_id": "run-c3fb61ee182e4fc394f9ae6fb841b770",
241
+ "reservation": 18544,
242
+ "charged": 4809,
243
+ "state": "settled",
244
+ "provider": "bailian-qwen3.8-max",
245
+ "prompt_digest": "c39cc5a41c1ae850bb36fef6f00772cac0ddc977500c7f05ca6950af4d1ab2d4",
246
+ "metadata": {
247
+ "finish_reason": "stop",
248
+ "model": "qwen3.8-max",
249
+ "policy_version": "bailian-task-routing-v2",
250
+ "request_id": "chatcmpl-6c9941ec-d218-9a50-811d-72ce676ba355",
251
+ "requested_output_tokens": 8192,
252
+ "retry_of": null,
253
+ "route_reason": "java-code",
254
+ "stage": "code"
255
+ }
256
+ },
257
+ {
258
+ "id": 3,
259
+ "run_id": "run-c3fb61ee182e4fc394f9ae6fb841b770",
260
+ "reservation": 30087,
261
+ "charged": 7279,
262
+ "state": "settled",
263
+ "provider": "bailian-qwen3.8-max",
264
+ "prompt_digest": "a8aac4b30ba3afc49cd967291c3f8204742e8f846effd2869d6765e00f0f0557",
265
+ "metadata": {
266
+ "finish_reason": "stop",
267
+ "model": "qwen3.8-max",
268
+ "policy_version": "bailian-task-routing-v2",
269
+ "request_id": "chatcmpl-d837911f-718e-9e13-822e-78c05dca4120",
270
+ "requested_output_tokens": 12288,
271
+ "retry_of": null,
272
+ "route_reason": "diagnostic-repair",
273
+ "stage": "repair"
274
+ }
275
+ },
276
+ {
277
+ "id": 4,
278
+ "run_id": "run-c3fb61ee182e4fc394f9ae6fb841b770",
279
+ "reservation": 30004,
280
+ "charged": 7256,
281
+ "state": "settled",
282
+ "provider": "bailian-qwen3.8-max",
283
+ "prompt_digest": "7c64d3c51e25a036f10b054c9522491d135d34583d98a0620a961959bf4f19d0",
284
+ "metadata": {
285
+ "finish_reason": "stop",
286
+ "model": "qwen3.8-max",
287
+ "policy_version": "bailian-task-routing-v2",
288
+ "request_id": "chatcmpl-29ff0f8a-8603-9a57-990c-e918a9a0201c",
289
+ "requested_output_tokens": 12288,
290
+ "retry_of": null,
291
+ "route_reason": "diagnostic-repair",
292
+ "stage": "repair"
293
+ }
294
+ }
295
+ ],
296
+ "diagnostics": {
297
+ "failures": [
298
+ {
299
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
300
+ "actual_status": 400,
301
+ "case_index": 1,
302
+ "expected_status": 200,
303
+ "path": "/api/calculate?expression64=Misz",
304
+ "reason": "response_did_not_match_public_contract"
305
+ },
306
+ {
307
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
308
+ "actual_status": 400,
309
+ "case_index": 2,
310
+ "expected_status": 200,
311
+ "path": "/api/calculate?expression64=MTAtMTM",
312
+ "reason": "response_did_not_match_public_contract"
313
+ },
314
+ {
315
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
316
+ "actual_status": 400,
317
+ "case_index": 3,
318
+ "expected_status": 200,
319
+ "path": "/api/calculate?expression64=Nio3",
320
+ "reason": "response_did_not_match_public_contract"
321
+ },
322
+ {
323
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
324
+ "actual_status": 400,
325
+ "case_index": 4,
326
+ "expected_status": 200,
327
+ "path": "/api/calculate?expression64=OC8y",
328
+ "reason": "response_did_not_match_public_contract"
329
+ },
330
+ {
331
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
332
+ "actual_status": 400,
333
+ "case_index": 5,
334
+ "expected_status": 200,
335
+ "path": "/api/calculate?expression64=MiszKjQ",
336
+ "reason": "response_did_not_match_public_contract"
337
+ },
338
+ {
339
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
340
+ "actual_status": 400,
341
+ "case_index": 6,
342
+ "expected_status": 200,
343
+ "path": "/api/calculate?expression64=KDIrMykqNA",
344
+ "reason": "response_did_not_match_public_contract"
345
+ },
346
+ {
347
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
348
+ "actual_status": 400,
349
+ "case_index": 7,
350
+ "expected_status": 200,
351
+ "path": "/api/calculate?expression64=MC4xKzAuMg",
352
+ "reason": "response_did_not_match_public_contract"
353
+ },
354
+ {
355
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
356
+ "actual_status": 400,
357
+ "case_index": 8,
358
+ "expected_status": 200,
359
+ "path": "/api/calculate?expression64=LSgyKzMpKi0y",
360
+ "reason": "response_did_not_match_public_contract"
361
+ },
362
+ {
363
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
364
+ "actual_status": 400,
365
+ "case_index": 9,
366
+ "expected_status": 200,
367
+ "path": "/api/calculate?expression64=MTAvMiozLTE",
368
+ "reason": "response_did_not_match_public_contract"
369
+ },
370
+ {
371
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
372
+ "actual_status": 400,
373
+ "case_index": 10,
374
+ "expected_status": 200,
375
+ "path": "/api/calculate?expression64=MS82",
376
+ "reason": "response_did_not_match_public_contract"
377
+ },
378
+ {
379
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
380
+ "actual_status": 400,
381
+ "case_index": 11,
382
+ "expected_status": 200,
383
+ "path": "/api/calculate?expression64=LTA",
384
+ "reason": "response_did_not_match_public_contract"
385
+ },
386
+ {
387
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
388
+ "actual_status": 400,
389
+ "case_index": 12,
390
+ "expected_status": 200,
391
+ "path": "/api/calculate?expression64=LjUrLjI1",
392
+ "reason": "response_did_not_match_public_contract"
393
+ },
394
+ {
395
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
396
+ "actual_status": 400,
397
+ "case_index": 13,
398
+ "expected_status": 200,
399
+ "path": "/api/calculate?expression64=IDEyICsgKCAzICogMiApIA",
400
+ "reason": "response_did_not_match_public_contract"
401
+ },
402
+ {
403
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
404
+ "actual_status": 400,
405
+ "case_index": 14,
406
+ "expected_status": 200,
407
+ "path": "/api/calculate?expression64=KCgoKCgoKCgoKCgoKCgoKDEpKSkpKSkpKSkpKSkpKSkp",
408
+ "reason": "response_did_not_match_public_contract"
409
+ },
410
+ {
411
+ "actual_body": "{\"error\":\"INVALID_EXPRESSION\"}",
412
+ "actual_status": 400,
413
+ "case_index": 15,
414
+ "expected_status": 200,
415
+ "path": "/api/calculate?expression64=MTAwMDAwMDAwMDAwMCoxMDAwMDAwMDAwMDAw",
416
+ "reason": "response_did_not_match_public_contract"
417
+ }
418
+ ]
419
+ }
420
+ }
421
+ }
examples/hf-ingress-validation.json CHANGED
@@ -8,7 +8,7 @@
8
  "popup receives the exact parent identity; an independent programmer remains denied"
9
  ],
10
  "errors": [],
11
- "platform_code_digest": "cc0bd4d6541c7fd2c321bc1de034f9ef635384bfb24b8d0bebfc0b741573f5b2",
12
  "cloud_runtime_files": {
13
  "deploy/hf/adapter.py": "0088b19648ab9661bb6eb6bdf4fa34de368f5fe5d6c347a58504c60331f42e95",
14
  "deploy/hf/app.py": "0e8a5729b5e99aae88c277d718e0afa6de21350515f92452996d10deac7612f3",
@@ -31,14 +31,14 @@
31
  "host_mounts": []
32
  },
33
  "passed": 6,
34
- "tested_at_utc": "2026-10-24T05:09:19.413583+00:00",
35
  "unit_tests": {
36
  "passed": 27,
37
  "skipped": 0
38
  },
39
  "core_tests": {
40
- "total": 241,
41
- "passed": 239,
42
  "skipped": 2
43
  }
44
  }
 
8
  "popup receives the exact parent identity; an independent programmer remains denied"
9
  ],
10
  "errors": [],
11
+ "platform_code_digest": "93df1f49cf2297ffdb8edeff3a27e300025e5d62eb18e0aaf6d2a584950f070e",
12
  "cloud_runtime_files": {
13
  "deploy/hf/adapter.py": "0088b19648ab9661bb6eb6bdf4fa34de368f5fe5d6c347a58504c60331f42e95",
14
  "deploy/hf/app.py": "0e8a5729b5e99aae88c277d718e0afa6de21350515f92452996d10deac7612f3",
 
31
  "host_mounts": []
32
  },
33
  "passed": 6,
34
+ "tested_at_utc": "2026-10-24T05:48:36.861647+00:00",
35
  "unit_tests": {
36
  "passed": 27,
37
  "skipped": 0
38
  },
39
  "core_tests": {
40
+ "total": 255,
41
+ "passed": 253,
42
  "skipped": 2
43
  }
44
  }
sites/zkcoding-workbench/dist/runtime.js CHANGED
@@ -148,7 +148,8 @@ export function renderJobMessage(job,index,error='') {
148
  ${job.evidence?.manifest?.repair_origin?`<p class="development-meta">本制品由 Codex 接管修复后独立验证。原模型任务 ${esc(job.evidence.manifest.repair_origin.generation_run)} 保留原结果。</p>`:''}
149
  ${job.evidence?.manifest?.continuation_origin?`<p class="development-meta">平台修复后的模型续作;原任务 ${esc(job.evidence.manifest.continuation_origin.generation_run)} 保留原结果。</p>`:''}
150
  ${job.recovery_of?`<p class="development-meta">依据任务 ${esc(job.recovery_of)} 继续修复;原源码、错误与用量记录保留。</p>`:''}
151
- ${job.design_summary?`<details class="development-diagnostics execution-plan" data-detail="plan"><summary>实施方案 · 模型已生成</summary><p>${esc(job.design_summary)}</p></details>`:''}
 
152
  ${timeline.length?`<details class="development-diagnostics" data-detail="events"><summary>执行记录 · 已保存 ${esc(timeline.length)} 条 · 最新:${esc(timeline.at(-1).title)}</summary><ol class="development-timeline">${timeline.map(event=>`<li data-stage="${esc(event.stage)}" data-status="${esc(event.status)}"><div class="development-event-heading"><strong>${esc(event.title||event.stage)}</strong><span>${esc(event.status==='active'?'执行器心跳':statusText(event.status))}</span></div><time>${esc(eventTime(event.at))}</time>${event.detail?`<p>${esc(typeof event.detail==='string'?event.detail:diagnosticText(event.detail))}</p>`:''}</li>`).join('')}</ol></details>`:'<p class="development-meta">等待服务端执行事件。</p>'}
153
  ${progressCard(job,error)}
154
  ${job.error?`<p class="development-error" role="status">${['queued','working'].includes(job.status)?'最近一轮验证发现问题,正在修复与复测:':'本次结果:'}${esc(job.error)}</p>`:''}
 
148
  ${job.evidence?.manifest?.repair_origin?`<p class="development-meta">本制品由 Codex 接管修复后独立验证。原模型任务 ${esc(job.evidence.manifest.repair_origin.generation_run)} 保留原结果。</p>`:''}
149
  ${job.evidence?.manifest?.continuation_origin?`<p class="development-meta">平台修复后的模型续作;原任务 ${esc(job.evidence.manifest.continuation_origin.generation_run)} 保留原结果。</p>`:''}
150
  ${job.recovery_of?`<p class="development-meta">依据任务 ${esc(job.recovery_of)} 继续修复;原源码、错误与用量记录保留。</p>`:''}
151
+ ${job.design_summary?`<details class="development-diagnostics execution-plan" data-detail="plan"><summary>实施方案 · 模型已生成</summary><p>${esc(job.design_summary)}</p></details>`:''}
152
+ ${job.failure_analysis?`<details class="development-diagnostics" data-detail="analysis"><summary>故障定位建议 · 以独立复测为准</summary><p>${esc(job.failure_analysis.summary)}</p></details>`:''}
153
  ${timeline.length?`<details class="development-diagnostics" data-detail="events"><summary>执行记录 · 已保存 ${esc(timeline.length)} 条 · 最新:${esc(timeline.at(-1).title)}</summary><ol class="development-timeline">${timeline.map(event=>`<li data-stage="${esc(event.stage)}" data-status="${esc(event.status)}"><div class="development-event-heading"><strong>${esc(event.title||event.stage)}</strong><span>${esc(event.status==='active'?'执行器心跳':statusText(event.status))}</span></div><time>${esc(eventTime(event.at))}</time>${event.detail?`<p>${esc(typeof event.detail==='string'?event.detail:diagnosticText(event.detail))}</p>`:''}</li>`).join('')}</ol></details>`:'<p class="development-meta">等待服务端执行事件。</p>'}
154
  ${progressCard(job,error)}
155
  ${job.error?`<p class="development-error" role="status">${['queued','working'].includes(job.status)?'最近一轮验证发现问题,正在修复与复测:':'本次结果:'}${esc(job.error)}</p>`:''}
src/apps/workbench/development.py CHANGED
@@ -10,6 +10,7 @@ TITLES={'start':'接收开发需求','requirements':'整理需求与验收目标
10
  'review':'独立续作与修复来源','repair':'模型依据失败诊断修复','execution':'执行状态',
11
  'routing':'按任务选择模型','model_recovery':'恢复已知输出问题'}
12
  TITLES['recovery']='自动恢复任务'
 
13
 
14
 
15
  def progress(run, state, events, now):
 
10
  'review':'独立续作与修复来源','repair':'模型依据失败诊断修复','execution':'执行状态',
11
  'routing':'按任务选择模型','model_recovery':'恢复已知输出问题'}
12
  TITLES['recovery']='自动恢复任务'
13
+ TITLES['diagnosis']='定位失败代码与最小复现'
14
 
15
 
16
  def progress(run, state, events, now):
src/apps/workbench/engine.py CHANGED
@@ -274,6 +274,7 @@ class LocalWorkbench:
274
  diagnostics=run.get('diagnostics'),evidence=self.checked_json(row['evidence']) if row['evidence'] else None,
275
  timeline=timeline(self.store,run,events),progress=progress(run,row['state'],events,time.time()),
276
  design_summary=design,project=project_info(self,actor,run_id),
 
277
  artifacts_available=bool(source),human_acceptance=False,
278
  recovery_of=run['request'].get('recovery_of'),followups=followups,auto_recovery=recovery)
279
 
 
274
  diagnostics=run.get('diagnostics'),evidence=self.checked_json(row['evidence']) if row['evidence'] else None,
275
  timeline=timeline(self.store,run,events),progress=progress(run,row['state'],events,time.time()),
276
  design_summary=design,project=project_info(self,actor,run_id),
277
+ failure_analysis=run.get('failure_analysis'),
278
  artifacts_available=bool(source),human_acceptance=False,
279
  recovery_of=run['request'].get('recovery_of'),followups=followups,auto_recovery=recovery)
280
 
src/modules/artifact_catalog/java_dependencies.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Server-approved Java dependency closure, verified cache and portable offline pack.
2
+
3
+ Catalog metadata is server policy. This is not an implementation of Maven's POM/BOM
4
+ resolver: a Maven Resolver adapter must approve its complete closure into the catalog.
5
+ The same lock is independent of the cloud/internal repository URL and layout.
6
+ """
7
+ import hashlib
8
+ import io
9
+ import json
10
+ import re
11
+ import uuid
12
+ import zipfile
13
+ from dataclasses import dataclass
14
+ from pathlib import Path
15
+ from urllib.parse import urlsplit
16
+ from src.modules.skill.domain.models import SkillError,canonical,digest
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class JavaArtifact:
21
+ coordinate:str
22
+ sha512:str
23
+ license:str
24
+ max_bytes:int=20_000_000
25
+ dependencies:tuple[str,...]=()
26
+ distribution_path:str|None=None
27
+
28
+ def parts(self):
29
+ values=self.coordinate.split(':')
30
+ if (len(values)!=3 or any(not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.-]{0,120}',v) or '..' in v for v in values)
31
+ or values[2].upper() in {'LATEST','RELEASE'} or 'SNAPSHOT' in values[2].upper()
32
+ or not re.fullmatch(r'[a-f0-9]{128}',self.sha512) or not self.license or not 0<self.max_bytes<=50_000_000):
33
+ raise SkillError('DEPENDENCY_DESCRIPTOR_INVALID','依赖必须有固定坐标、摘要、许可证和大小边界。')
34
+ return values
35
+
36
+
37
+ class JavaDependencyGateway:
38
+ def __init__(self,cache,catalog,repository='https://repo.maven.apache.org/maven2',*,layout='maven',offline=False,fetch=None):
39
+ parsed=urlsplit(repository)
40
+ if parsed.scheme!='https' or not parsed.hostname or parsed.username or parsed.password or parsed.query or parsed.fragment:
41
+ raise SkillError('DEPENDENCY_REPOSITORY_DENIED','仓库必须是服务端配置的HTTPS地址,凭据不得放在URL。')
42
+ if layout not in {'maven','distribution'}:raise ValueError('Unknown repository layout')
43
+ self.cache=Path(cache).resolve();self.cache.mkdir(parents=True,exist_ok=True)
44
+ self.catalog=dict(catalog);self.repository=repository.rstrip('/');self.layout=layout;self.offline=offline
45
+ self.fetch=fetch or self._fetch
46
+
47
+ def resolve(self,coordinates):
48
+ if not isinstance(coordinates,(list,tuple)):
49
+ raise SkillError('DEPENDENCY_REQUEST_INVALID','依赖坐标必须是列表。')
50
+ roots=list(coordinates)
51
+ if not roots or len(roots)>32 or any(not isinstance(c,str) for c in roots):
52
+ raise SkillError('DEPENDENCY_REQUEST_INVALID','需要有界的明确依赖坐标。')
53
+ ordered=[];seen=set();visiting=set();versions={}
54
+ def visit(coordinate):
55
+ if coordinate in visiting:raise SkillError('DEPENDENCY_CYCLE','依赖图存在循环。')
56
+ if coordinate in seen:return
57
+ item=self.catalog.get(coordinate)
58
+ if not item or item.coordinate!=coordinate:raise SkillError('DEPENDENCY_NOT_APPROVED','依赖尚未进入服务端批准目录。',409)
59
+ group,artifact,version=item.parts();key=(group,artifact)
60
+ if key in versions and versions[key]!=version:raise SkillError('DEPENDENCY_VERSION_CONFLICT','依赖版本冲突,不能默默选择版本。',409)
61
+ versions[key]=version;visiting.add(coordinate)
62
+ if len(versions)>64:raise SkillError('DEPENDENCY_GRAPH_LIMIT','依赖闭包超过限制。')
63
+ for child in item.dependencies:visit(child)
64
+ visiting.remove(coordinate);seen.add(coordinate)
65
+ ordered.append({'coordinate':coordinate,'sha512':item.sha512,'license':item.license,'max_bytes':item.max_bytes})
66
+ for coordinate in roots:visit(coordinate)
67
+ body={'schema':'java-dependency-lock-v1','roots':roots,'artifacts':ordered}
68
+ return {**body,'digest':digest(body)}
69
+
70
+ def _checked(self,lock):
71
+ if not isinstance(lock,dict) or not isinstance(lock.get('roots'),list) or self.resolve(lock['roots'])!=lock:
72
+ raise SkillError('DEPENDENCY_LOCK_INVALID','依赖锁定清单与批准目录不一致。',409)
73
+ return lock['artifacts']
74
+
75
+ def _path(self,item):
76
+ group,artifact,version=item.parts()
77
+ if self.layout=='maven':return f'{group.replace(".","/")}/{artifact}/{version}/{artifact}-{version}.jar'
78
+ path=item.distribution_path
79
+ if not path or path.startswith('/') or any(p in {'','..','.'} for p in path.split('/')) or not re.fullmatch(r'[A-Za-z0-9_./-]+',path):
80
+ raise SkillError('DEPENDENCY_SOURCE_NOT_CONFIGURED','此依赖未配置当前仓库来源。',409)
81
+ return path
82
+
83
+ @staticmethod
84
+ def _verify(data,item):
85
+ if len(data)>item.max_bytes or hashlib.sha512(data).hexdigest()!=item.sha512:
86
+ raise SkillError('DEPENDENCY_INTEGRITY_FAILED','依赖大小或摘要不符合锁定清单。',409)
87
+
88
+ def seed(self,coordinate,data):
89
+ item=self.catalog.get(coordinate)
90
+ if not item:raise SkillError('DEPENDENCY_NOT_APPROVED','依赖未批准。',409)
91
+ item.parts();self._verify(data,item)
92
+ target=self._cache_path(item)
93
+ if target.is_symlink():raise SkillError('DEPENDENCY_CACHE_PATH_DENIED','缓存路径不可为符号链接。')
94
+ temporary=self.cache/(uuid.uuid4().hex+'.partial')
95
+ try:temporary.write_bytes(data);temporary.replace(target)
96
+ finally:temporary.unlink(missing_ok=True)
97
+ return target
98
+
99
+ def _cache_path(self,item):
100
+ # Keep Windows cache paths short; the full SHA-512 is still verified on every read.
101
+ return self.cache/(hashlib.sha256(bytes.fromhex(item.sha512)).hexdigest()+'.jar')
102
+
103
+ def materialize(self,lock):
104
+ files={}
105
+ for entry in self._checked(lock):
106
+ item=self.catalog[entry['coordinate']];target=self._cache_path(item)
107
+ if target.is_symlink():raise SkillError('DEPENDENCY_CACHE_PATH_DENIED','缓存路径不可为符号链接。')
108
+ if target.exists():self._verify(target.read_bytes(),item)
109
+ else:
110
+ if self.offline:raise SkillError('DEPENDENCY_NOT_CACHED','离线镜像尚未预存完整依赖闭包。',503)
111
+ target=self.seed(item.coordinate,self.fetch(self.repository+'/'+self._path(item),item.max_bytes))
112
+ files[item.coordinate]=target
113
+ return files
114
+
115
+ @staticmethod
116
+ def _fetch(url,limit):
117
+ import httpx
118
+ try:
119
+ with httpx.Client(trust_env=False,follow_redirects=False,timeout=45) as client:
120
+ with client.stream('GET',url) as response:
121
+ if response.status_code!=200:raise SkillError('DEPENDENCY_DOWNLOAD_FAILED','固定来源未返回依赖文件。',503)
122
+ data=bytearray()
123
+ for chunk in response.iter_bytes():
124
+ data.extend(chunk)
125
+ if len(data)>limit:raise SkillError('DEPENDENCY_SIZE_LIMIT','依赖下载超过大小限制。')
126
+ return bytes(data)
127
+ except httpx.HTTPError:
128
+ raise SkillError('DEPENDENCY_DOWNLOAD_FAILED','依赖仓库连接失败;未向其他来源重试。',503) from None
129
+
130
+ def export_bundle(self,lock):
131
+ files=self.materialize(lock);output=io.BytesIO()
132
+ with zipfile.ZipFile(output,'w',zipfile.ZIP_STORED) as archive:
133
+ archive.writestr('dependency-lock.json',canonical(lock))
134
+ written=set()
135
+ for entry in lock['artifacts']:
136
+ if entry['sha512'] not in written:
137
+ archive.writestr('artifacts/'+entry['sha512']+'.jar',files[entry['coordinate']].read_bytes())
138
+ written.add(entry['sha512'])
139
+ return output.getvalue()
140
+
141
+ def import_bundle(self,data):
142
+ if len(data)>200_000_000:raise SkillError('DEPENDENCY_BUNDLE_LIMIT','依赖包超过上限。')
143
+ try:return self._import_bundle(data)
144
+ except (zipfile.BadZipFile,KeyError,ValueError,UnicodeError,RuntimeError):
145
+ raise SkillError('DEPENDENCY_BUNDLE_INVALID','离线依赖包不可解析或条目不合法。') from None
146
+
147
+ def _import_bundle(self,data):
148
+ with zipfile.ZipFile(io.BytesIO(data)) as archive:
149
+ names=archive.namelist()
150
+ if (len(names)!=len(set(names)) or len(names)>65
151
+ or sum(e.file_size for e in archive.infolist())>200_000_000
152
+ or archive.getinfo('dependency-lock.json').file_size>65536):
153
+ raise SkillError('DEPENDENCY_BUNDLE_INVALID','离线包条目不合法。')
154
+ lock=json.loads(archive.read('dependency-lock.json'));entries=self._checked(lock)
155
+ if set(names)!={'dependency-lock.json',*('artifacts/'+e['sha512']+'.jar' for e in entries)}:
156
+ raise SkillError('DEPENDENCY_BUNDLE_INVALID','离线包包含未批准文件。')
157
+ checked=[]
158
+ for entry in entries:
159
+ item=self.catalog[entry['coordinate']];name='artifacts/'+item.sha512+'.jar'
160
+ if archive.getinfo(name).file_size>item.max_bytes:raise SkillError('DEPENDENCY_SIZE_LIMIT','离线文件超过限制。')
161
+ payload=archive.read(name);self._verify(payload,item);checked.append((item.coordinate,payload))
162
+ for coordinate,payload in checked:self.seed(coordinate,payload)
163
+ return lock
src/modules/llm_gateway/routing.py CHANGED
@@ -1,10 +1,10 @@
1
  """Server-owned Bailian capabilities and deterministic routing; never prompt-selected endpoints."""
2
- VERSION = 'bailian-task-routing-v2'
3
  PROFILES = {
4
- 'qwen3.8-flash': {'roles':['chat','design','code','repair'], 'json_mode':True, 'thinking':False},
5
  'qwen3-coder-flash': {'roles':['code','repair'], 'json_mode':False, 'thinking':None},
6
- 'qwen3.7-plus': {'roles':['design','code','repair'], 'json_mode':True, 'thinking':False},
7
- 'qwen3.8-max': {'roles':['design','code','repair'], 'json_mode':True, 'thinking':False},
8
  }
9
 
10
 
@@ -14,7 +14,7 @@ def plan(providers, kind, run):
14
  # Dependency complexity comes from the frozen server framework, not the user's wording.
15
  complex_code=bool(run.get('snapshot',{}).get('framework',{}).get('dependencies'))
16
  business=run.get('project_id') in {'erp-demo','wms-demo','equipment-demo'}
17
- reason=('dependency-code' if complex_code else 'business-code' if business else 'java-code') if kind=='code' else {'design':'technical-design','repair':'diagnostic-repair','chat':'ordinary-chat'}[kind]
18
  if kind=='code' and run.get('request',{}).get('recovery_diagnostics'):reason='diagnostic-repair'
19
  preferred=(['qwen3.8-flash'] if kind=='chat' else ['qwen3.8-flash','qwen3.8-max','qwen3.7-plus'] if kind=='design'
20
  else ['qwen3.8-max','qwen3.8-flash','qwen3-coder-flash','qwen3.7-plus'])
@@ -25,7 +25,7 @@ def plan(providers, kind, run):
25
  def catalog(providers):
26
  effective={}
27
  for label,kind,dependencies in [('chat','chat',{}),('design','design',{}),('java-code','code',{}),
28
- ('business-code','code',{}),('dependency-code','code',{'approved':'fixed'}),('repair','repair',{})]:
29
  candidates,_=plan(providers,kind,{'project_id':'erp-demo' if label=='business-code' else 'calculator-demo','snapshot':{'framework':{'dependencies':dependencies}}})
30
  effective[label]=getattr(candidates[0],'model',candidates[0].name) if candidates else None
31
  return {'policy_version':VERSION,'automatic':True,'effective_policy':effective,'models':[
@@ -33,6 +33,6 @@ def catalog(providers):
33
  'json_mode':getattr(p,'json_mode',True),'health':getattr(p,'health',{'status':'not_probed'})}
34
  for p in providers],
35
  'preferred_policy':{'chat':'qwen3.8-flash','design':'qwen3.8-flash','java-code':'qwen3.8-max',
36
- 'business-code':'qwen3.8-max','dependency-code':'qwen3.8-max','repair':'qwen3.8-max'},
37
- 'output_limits':{'design':2048,'code':8192,'dependency-code':12288,'repair':12288,'known_output_retry_max':24576},
38
  'unknown_outcome_replay':False}
 
1
  """Server-owned Bailian capabilities and deterministic routing; never prompt-selected endpoints."""
2
+ VERSION = 'bailian-task-routing-v3'
3
  PROFILES = {
4
+ 'qwen3.8-flash': {'roles':['chat','design','diagnose','code','repair'], 'json_mode':True, 'thinking':False},
5
  'qwen3-coder-flash': {'roles':['code','repair'], 'json_mode':False, 'thinking':None},
6
+ 'qwen3.7-plus': {'roles':['design','diagnose','code','repair'], 'json_mode':True, 'thinking':False},
7
+ 'qwen3.8-max': {'roles':['design','diagnose','code','repair'], 'json_mode':True, 'thinking':False},
8
  }
9
 
10
 
 
14
  # Dependency complexity comes from the frozen server framework, not the user's wording.
15
  complex_code=bool(run.get('snapshot',{}).get('framework',{}).get('dependencies'))
16
  business=run.get('project_id') in {'erp-demo','wms-demo','equipment-demo'}
17
+ reason=('dependency-code' if complex_code else 'business-code' if business else 'java-code') if kind=='code' else {'design':'technical-design','diagnose':'failure-localization','repair':'diagnostic-repair','chat':'ordinary-chat'}[kind]
18
  if kind=='code' and run.get('request',{}).get('recovery_diagnostics'):reason='diagnostic-repair'
19
  preferred=(['qwen3.8-flash'] if kind=='chat' else ['qwen3.8-flash','qwen3.8-max','qwen3.7-plus'] if kind=='design'
20
  else ['qwen3.8-max','qwen3.8-flash','qwen3-coder-flash','qwen3.7-plus'])
 
25
  def catalog(providers):
26
  effective={}
27
  for label,kind,dependencies in [('chat','chat',{}),('design','design',{}),('java-code','code',{}),
28
+ ('business-code','code',{}),('dependency-code','code',{'approved':'fixed'}),('diagnose','diagnose',{}),('repair','repair',{})]:
29
  candidates,_=plan(providers,kind,{'project_id':'erp-demo' if label=='business-code' else 'calculator-demo','snapshot':{'framework':{'dependencies':dependencies}}})
30
  effective[label]=getattr(candidates[0],'model',candidates[0].name) if candidates else None
31
  return {'policy_version':VERSION,'automatic':True,'effective_policy':effective,'models':[
 
33
  'json_mode':getattr(p,'json_mode',True),'health':getattr(p,'health',{'status':'not_probed'})}
34
  for p in providers],
35
  'preferred_policy':{'chat':'qwen3.8-flash','design':'qwen3.8-flash','java-code':'qwen3.8-max',
36
+ 'business-code':'qwen3.8-max','dependency-code':'qwen3.8-max','diagnose':'qwen3.8-max','repair':'qwen3.8-max'},
37
+ 'output_limits':{'design':2048,'diagnose':2048,'code':8192,'dependency-code':12288,'repair':12288,'known_output_retry_max':24576},
38
  'unknown_outcome_replay':False}
src/modules/llm_gateway/service.py CHANGED
@@ -49,7 +49,7 @@ class LLMGateway:
49
  from src.modules.llm_gateway.routing import plan
50
  if not self.providers:
51
  raise SkillError('MODEL_NOT_CONFIGURED', '未配置本项目模型。', 503)
52
- schema = Design if kind == 'design' else Candidate
53
  run=self.store.get(run_id)
54
  providers,reason=plan(self.providers,kind,run)
55
  if not providers:
@@ -60,7 +60,16 @@ class LLMGateway:
60
  'For design return a concise technical summary within 800 characters, never source code. '
61
  'For code or repair return only src/main/java/demo/App.java; do not generate docs already supplied by the platform. '
62
  +canonical(schema.model_json_schema()))
63
- if kind!='design':
 
 
 
 
 
 
 
 
 
64
  system+=(' Keep Java string literals valid Java, never JavaScript single-quoted strings. '
65
  'For HTTP query validation reject duplicates before inserting into a Map. '
66
  'Decode request text using a UTF-8 CharsetDecoder with CodingErrorAction.REPORT. '
@@ -73,7 +82,7 @@ class LLMGateway:
73
  'before PDF parsing. Unknown HTTP routes must return the JSON NOT_FOUND contract, not HttpServer HTML.')
74
  messages=[{'role':'system','content':system},
75
  {'role':'user','content':canonical({'task':kind,'data':payload})}]
76
- target=2048 if kind=='design' else 12288 if kind=='repair' or reason in {'dependency-code','diagnostic-repair'} else 8192
77
  index,recoveries,retry_of=0,0,None
78
  while index<len(providers):
79
  provider=providers[index]
@@ -127,7 +136,7 @@ class LLMGateway:
127
  if cancelled():raise SkillError('RUN_CANCELLED','任务已取消,模型输出未应用。',409)
128
  if not known_error:return body
129
  if cancelled():raise SkillError('RUN_CANCELLED','任务已取消,停止恢复。',409)
130
- if known_error in {'MODEL_OUTPUT_TRUNCATED','MODEL_OUTPUT_INVALID'} and recoveries<1:
131
  recoveries+=1;retry_of=call_id;target=min(target*2,24576)
132
  reason='known-output-recovery'
133
  messages[0]['content']=system+' Previous completed response was unusable. Regenerate a COMPLETE compact JSON object. Do not continue or concatenate partial JSON.'
 
49
  from src.modules.llm_gateway.routing import plan
50
  if not self.providers:
51
  raise SkillError('MODEL_NOT_CONFIGURED', '未配置本项目模型。', 503)
52
+ schema = Design if kind in {'design','diagnose'} else Candidate
53
  run=self.store.get(run_id)
54
  providers,reason=plan(self.providers,kind,run)
55
  if not providers:
 
60
  'For design return a concise technical summary within 800 characters, never source code. '
61
  'For code or repair return only src/main/java/demo/App.java; do not generate docs already supplied by the platform. '
62
  +canonical(schema.model_json_schema()))
63
+ if kind=='diagnose':
64
+ system+=(' Return only a summary of the concrete root cause and minimal code correction, within 800 characters. '
65
+ 'Use the smallest disclosed failing request to check the handler, parser state, guards and return path against expected and actual values. '
66
+ 'Name the actual variables/conditions to change. Do not provide private deliberation, rewrite source, or claim verification. '
67
+ 'Only explain branches that can return the EXACT observed status AND error body. '
68
+ 'A branch returning INVALID_INPUT cannot explain an observed INVALID_EXPRESSION. '
69
+ 'Check state ownership and propagation: a mutable cursor passed into a parser must be reused by the final end-of-input check. '
70
+ 'Quote the faulty expression and the replacement expression. Do not guess undocumented library restrictions. '
71
+ 'The existing implementation failed; its design is not authoritative.')
72
+ if kind in {'code','repair'}:
73
  system+=(' Keep Java string literals valid Java, never JavaScript single-quoted strings. '
74
  'For HTTP query validation reject duplicates before inserting into a Map. '
75
  'Decode request text using a UTF-8 CharsetDecoder with CodingErrorAction.REPORT. '
 
82
  'before PDF parsing. Unknown HTTP routes must return the JSON NOT_FOUND contract, not HttpServer HTML.')
83
  messages=[{'role':'system','content':system},
84
  {'role':'user','content':canonical({'task':kind,'data':payload})}]
85
+ target=2048 if kind in {'design','diagnose'} else 12288 if kind=='repair' or reason in {'dependency-code','diagnostic-repair'} else 8192
86
  index,recoveries,retry_of=0,0,None
87
  while index<len(providers):
88
  provider=providers[index]
 
136
  if cancelled():raise SkillError('RUN_CANCELLED','任务已取消,模型输出未应用。',409)
137
  if not known_error:return body
138
  if cancelled():raise SkillError('RUN_CANCELLED','任务已取消,停止恢复。',409)
139
+ if kind!='diagnose' and known_error in {'MODEL_OUTPUT_TRUNCATED','MODEL_OUTPUT_INVALID'} and recoveries<1:
140
  recoveries+=1;retry_of=call_id;target=min(target*2,24576)
141
  reason='known-output-recovery'
142
  messages[0]['content']=system+' Previous completed response was unusable. Regenerate a COMPLETE compact JSON object. Do not continue or concatenate partial JSON.'
src/modules/orchestrator/service.py CHANGED
@@ -165,10 +165,33 @@ class AgentRuntime:
165
  self.store.stage_event(run_id,'repair','started','根据实际编译或测试诊断请求模型修复')
166
  design=self._operation_output(run, 'AO04')['design']
167
  new_context=any(op['operation_id']=='AO05' and op['version']=='0.2.0' for op in run['release']['operations'].values())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  with self.activity(run_id, claim, 'repair'):
169
  patch = self.llm.generate(run_id, 'repair', {'design':{'digest':digest(design)},
170
  'previous': self._operation_output(run, 'AO06')['source']['files'], 'failure_code': run['error'],
171
  'diagnostics': self.repair_diagnostics(run),
 
172
  'runtime_contract': self.sandbox.runtime_contract}, cancelled,
173
  32000 if new_context else 26000 if run['snapshot']['framework']['profile_id']=='java17-pdfbox-web' else 20000,
174
  dispatch_guard=lambda:self._recheck(actor,self.store.get(run_id)))
@@ -332,6 +355,7 @@ class AgentRuntime:
332
  'deployment': 'not_performed', 'human_acceptance': False, 'sandbox_cleaned': True}
333
  if run.get('repair_origin'):body['repair_origin']=run['repair_origin']
334
  if run.get('continuation_origin'):body['continuation_origin']=run['continuation_origin']
 
335
  if run['request'].get('recovery_of'):body['recovery_of']=run['request']['recovery_of']
336
  if run['request'].get('baseline_origin'):
337
  body['source_baseline']={'origin':run['request']['baseline_origin'],
 
165
  self.store.stage_event(run_id,'repair','started','根据实际编译或测试诊断请求模型修复')
166
  design=self._operation_output(run, 'AO04')['design']
167
  new_context=any(op['operation_id']=='AO05' and op['version']=='0.2.0' for op in run['release']['operations'].values())
168
+ analysis=None
169
+ if (new_context and run['repairs']>=2 and run['budget']['max_model_calls']-len(self.store.calls(run_id))>=2
170
+ and any('diagnose' in getattr(p,'task_roles',[]) for p in self.llm.providers)):
171
+ failure=self.repair_diagnostics(run)
172
+ observed=failure['observed']
173
+ if isinstance(observed,dict) and 'failures' in observed:
174
+ failure={**failure,'observed':{**observed,'failures':observed['failures'][:3]},
175
+ 'public_contract_expectations':failure['public_contract_expectations'][:3]}
176
+ self.store.stage_event(run_id,'diagnosis','started','修复后仍未通过,先定位最小失败请求的具体代码原因')
177
+ try:
178
+ with self.activity(run_id,claim,'diagnosis'):
179
+ hypothesis=self.llm.generate(run_id,'diagnose',{'source':self._operation_output(run,'AO06')['source']['files'],
180
+ 'failure':failure,'runtime_contract':self.sandbox.runtime_contract},cancelled,26000,
181
+ dispatch_guard=lambda:self._recheck(actor,self.store.get(run_id)))
182
+ analysis={**hypothesis,'source_digest':self._operation_output(run,'AO06')['source']['source_digest'],
183
+ 'trust':'model_hypothesis_requires_independent_tests'}
184
+ run=self._write(run_id,claim,{'failure_analysis':analysis})
185
+ self.store.stage_event(run_id,'diagnosis','completed',hypothesis['summary'])
186
+ except SkillError as exc:
187
+ if exc.code not in {'CONTEXT_BUDGET_EXCEEDED','MODEL_ROUTE_UNAVAILABLE','MODEL_OUTPUT_INVALID','MODEL_OUTPUT_TRUNCATED'}:raise
188
+ self.store.stage_event(run_id,'diagnosis','skipped','诊断建议不可用:'+exc.code+';调用记录保留,按原预算修复')
189
+ if analysis:self.store.stage_event(run_id,'repair','started','按定位建议修复源码;仍须独立编译和系统测试')
190
  with self.activity(run_id, claim, 'repair'):
191
  patch = self.llm.generate(run_id, 'repair', {'design':{'digest':digest(design)},
192
  'previous': self._operation_output(run, 'AO06')['source']['files'], 'failure_code': run['error'],
193
  'diagnostics': self.repair_diagnostics(run),
194
+ **({'failure_analysis':analysis} if analysis else {}),
195
  'runtime_contract': self.sandbox.runtime_contract}, cancelled,
196
  32000 if new_context else 26000 if run['snapshot']['framework']['profile_id']=='java17-pdfbox-web' else 20000,
197
  dispatch_guard=lambda:self._recheck(actor,self.store.get(run_id)))
 
355
  'deployment': 'not_performed', 'human_acceptance': False, 'sandbox_cleaned': True}
356
  if run.get('repair_origin'):body['repair_origin']=run['repair_origin']
357
  if run.get('continuation_origin'):body['continuation_origin']=run['continuation_origin']
358
+ if run.get('failure_analysis'):body['failure_analysis']=run['failure_analysis']
359
  if run['request'].get('recovery_of'):body['recovery_of']=run['request']['recovery_of']
360
  if run['request'].get('baseline_origin'):
361
  body['source_baseline']={'origin':run['request']['baseline_origin'],
src/tests/runtime/test_failure_localization.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Explicit synthetic diagnosis contracts; live source/VM tests are separate."""
2
+ import json
3
+ import unittest
4
+ from src.tests.runtime.fixtures import setup,workspace,USER,AUTHOR,SOURCE
5
+ from src.modules.skill.atomic_registry.catalog import routing_operations
6
+ from src.modules.skill.domain.models import Draft,Budget
7
+ from src.modules.llm_gateway.service import ModelReply,ProviderFailure
8
+ from src.modules.governance.local_validation import LocalValidation
9
+
10
+
11
+ class FailureLocalizationTests(unittest.TestCase):
12
+ def execute(self, mode='valid'):
13
+ runtime,request,model,sandbox=setup(self.enterContext(workspace()))
14
+ for op in routing_operations():runtime.skills.add_operation(AUTHOR,op)
15
+ doc=runtime.skills.read_draft(AUTHOR,'erp-java-development')
16
+ body={k:v for k,v in doc['body'].items() if k not in {'owner_id','last_editor_id'}}
17
+ body['project_id']='fixture-project'
18
+ body['budget']=Budget(max_model_calls=6,max_tokens=120000,max_repairs=2).model_dump()
19
+ for node in body['graph']['nodes']:
20
+ if node.get('operation_ref')=='AO05@0.1.0':node['operation_ref']='AO05@0.2.0'
21
+ runtime.skills.save_draft(AUTHOR,Draft.model_validate(body),doc['revision'])
22
+ release=runtime.skills.stage_local_validation(AUTHOR,'erp-java-development','unit-localization',validation_owner=USER.user_id)
23
+ request['release_ref']=release['key']
24
+ model.task_roles=['diagnose'];captured=[];original=model.complete
25
+ sandbox.fail='build'
26
+ def complete(messages,*args):
27
+ data=json.loads(messages[-1]['content']);captured.append(data)
28
+ if data['task']=='diagnose':
29
+ model.count+=1
30
+ if mode=='unknown':raise ProviderFailure('MODEL_RESULT_UNKNOWN')
31
+ if mode=='invalid':return ModelReply({'files':SOURCE},80,80,model.name)
32
+ return ModelReply({'summary':'Concrete synthetic compiler cause and minimal correction.'},80,80,model.name)
33
+ if data['task']=='repair' and data['data'].get('failure_analysis'):sandbox.fail=None
34
+ return original(messages,*args)
35
+ model.complete=complete
36
+ run=runtime.create(USER,request,'failure-localization-unit')
37
+ validator=LocalValidation(runtime,USER,'unit-localization')
38
+ for _ in range(30):
39
+ run=runtime.get(USER,run['id'])
40
+ if run['status'] in {'unknown','failed'} or (run.get('pending_approval') or {}).get('scope')=='acceptance':break
41
+ if mode=='one-call-left' and run['repairs']==2:
42
+ runtime.store.mutate(run['id'],lambda r:r['budget'].update(max_model_calls=4))
43
+ validator.step(run['id'])
44
+ return runtime,runtime.get(USER,run['id']),captured
45
+
46
+ def test_repeat_failure_is_localized_then_repaired_and_independently_retested(self):
47
+ runtime,run,messages=self.execute()
48
+ self.assertEqual(run['status'],'waiting_approval')
49
+ self.assertEqual(run['pending_approval']['scope'],'acceptance')
50
+ self.assertEqual([m['task'] for m in messages],['design','code','repair','diagnose','repair'])
51
+ self.assertEqual(run['failure_analysis']['trust'],'model_hypothesis_requires_independent_tests')
52
+ self.assertEqual(runtime.validation_evidence(USER,run['id'])['manifest']['failure_analysis'],run['failure_analysis'])
53
+ self.assertEqual(len(runtime.store.calls(run['id'])),5)
54
+
55
+ def test_unknown_diagnosis_stops_without_applying_or_replaying(self):
56
+ runtime,run,messages=self.execute('unknown')
57
+ self.assertEqual(run['status'],'unknown')
58
+ self.assertEqual(messages[-1]['task'],'diagnose')
59
+ self.assertEqual(runtime.store.calls(run['id'])[-1]['state'],'unknown')
60
+
61
+ def test_invalid_optional_diagnosis_is_settled_once_and_does_not_consume_a_retry(self):
62
+ runtime,run,messages=self.execute('invalid')
63
+ self.assertEqual(run['status'],'failed')
64
+ self.assertEqual(sum(m['task']=='diagnose' for m in messages),1)
65
+ self.assertEqual(len(runtime.store.calls(run['id'])),5)
66
+ self.assertTrue(all(c['state']=='settled' for c in runtime.store.calls(run['id'])))
67
+
68
+ def test_diagnosis_does_not_steal_the_last_repair_call_or_expand_budget(self):
69
+ runtime,run,messages=self.execute('one-call-left')
70
+ self.assertEqual(run['status'],'failed')
71
+ self.assertFalse(any(m['task']=='diagnose' for m in messages))
72
+ self.assertEqual(len(runtime.store.calls(run['id'])),4)
src/tests/runtime/test_java_dependencies.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hashlib
2
+ import io
3
+ import json
4
+ import unittest
5
+ import zipfile
6
+ from pathlib import Path
7
+ from dataclasses import replace
8
+ from src.modules.artifact_catalog.java_dependencies import JavaArtifact,JavaDependencyGateway
9
+ from src.modules.skill.domain.models import SkillError
10
+ from src.tests.runtime.fixtures import workspace
11
+ from contextlib import contextmanager
12
+
13
+
14
+ class JavaDependencyTests(unittest.TestCase):
15
+ def setUp(self):
16
+ self.folder=Path(self.enterContext(workspace()))
17
+ self.payload=b'approved binary fixture; never executed'
18
+ self.item=JavaArtifact('demo:library:1.0',hashlib.sha512(self.payload).hexdigest(),'Apache-2.0',100)
19
+ self.catalog={self.item.coordinate:self.item}
20
+
21
+ def gateway(self,name='cache',**kw):
22
+ return JavaDependencyGateway(self.folder/name,self.catalog,**kw)
23
+
24
+ @contextmanager
25
+ def assertRaisesCode(self,code):
26
+ with self.assertRaises(SkillError) as raised:yield
27
+ self.assertEqual(raised.exception.code,code)
28
+
29
+ def test_online_materialize_downloads_fixed_coordinate_once_then_checks_cache(self):
30
+ calls=[]
31
+ gateway=self.gateway(fetch=lambda url,limit:(calls.append((url,limit)) or self.payload))
32
+ lock=gateway.resolve([self.item.coordinate])
33
+ gateway.materialize(lock);gateway.materialize(lock)
34
+ self.assertEqual(calls,[('https://repo.maven.apache.org/maven2/demo/library/1.0/library-1.0.jar',100)])
35
+ self.assertEqual(next(iter(gateway.materialize(lock).values())).read_bytes(),self.payload)
36
+
37
+ def test_same_lock_moves_to_internal_offline_cache_without_network(self):
38
+ online=self.gateway(fetch=lambda *_:self.payload)
39
+ lock=online.resolve([self.item.coordinate]);bundle=online.export_bundle(lock)
40
+ offline=self.gateway('intranet',repository='https://maven.internal.example/repository/approved',offline=True,
41
+ fetch=lambda *_:self.fail('Offline import attempted network'))
42
+ self.assertEqual(offline.import_bundle(bundle),lock)
43
+ self.assertEqual(offline.resolve([self.item.coordinate]),lock)
44
+ self.assertEqual(next(iter(offline.materialize(lock).values())).read_bytes(),self.payload)
45
+
46
+ def test_tampered_download_and_cached_binary_are_rejected(self):
47
+ gateway=self.gateway(fetch=lambda *_:b'tampered')
48
+ lock=gateway.resolve([self.item.coordinate])
49
+ with self.assertRaisesCode('DEPENDENCY_INTEGRITY_FAILED'):gateway.materialize(lock)
50
+ path=gateway.seed(self.item.coordinate,self.payload);path.write_bytes(b'tampered')
51
+ with self.assertRaisesCode('DEPENDENCY_INTEGRITY_FAILED'):gateway.materialize(lock)
52
+
53
+ def test_offline_miss_never_falls_back_to_public_repository(self):
54
+ gateway=self.gateway(offline=True,fetch=lambda *_:self.fail('Network fallback'))
55
+ with self.assertRaisesCode('DEPENDENCY_NOT_CACHED'):gateway.materialize(gateway.resolve([self.item.coordinate]))
56
+
57
+ def test_unknown_floating_and_path_coordinates_are_rejected(self):
58
+ gateway=self.gateway()
59
+ with self.assertRaisesCode('DEPENDENCY_NOT_APPROVED'):gateway.resolve(['other:library:1.0'])
60
+ for coordinate in ['demo:library:LATEST','demo:library:1-SNAPSHOT','../demo:library:1.0']:
61
+ with self.subTest(coordinate=coordinate),self.assertRaisesCode('DEPENDENCY_DESCRIPTOR_INVALID'):
62
+ replace(self.item,coordinate=coordinate).parts()
63
+ for roots in [None,'demo:library:1.0',[],[None]]:
64
+ with self.subTest(roots=roots),self.assertRaisesCode('DEPENDENCY_REQUEST_INVALID'):gateway.resolve(roots)
65
+
66
+ def test_complete_closure_detects_version_conflicts_and_cycles(self):
67
+ parent=replace(self.item,coordinate='demo:parent:1.0',dependencies=('demo:library:1.0','demo:library:2.0'))
68
+ self.catalog.update({parent.coordinate:parent,'demo:library:2.0':replace(self.item,coordinate='demo:library:2.0')})
69
+ with self.assertRaisesCode('DEPENDENCY_VERSION_CONFLICT'):self.gateway().resolve([parent.coordinate])
70
+ self.catalog={parent.coordinate:replace(parent,dependencies=(parent.coordinate,))}
71
+ with self.assertRaisesCode('DEPENDENCY_CYCLE'):self.gateway().resolve([parent.coordinate])
72
+
73
+ def test_lock_cannot_add_arbitrary_files_or_change_checksums(self):
74
+ gateway=self.gateway();lock=gateway.resolve([self.item.coordinate]);lock['artifacts'][0]['sha512']='0'*128
75
+ with self.assertRaisesCode('DEPENDENCY_LOCK_INVALID'):gateway.materialize(lock)
76
+
77
+ def test_malformed_extra_and_corrupted_bundle_are_rejected_before_cache_write(self):
78
+ gateway=self.gateway()
79
+ for payload in [b'not zip',self.bundle({'dependency-lock.json':b'{}'}),self.bundle({'../escape.jar':b'bad'})]:
80
+ with self.subTest(payload=payload[:12]),self.assertRaises(SkillError):gateway.import_bundle(payload)
81
+ lock=gateway.resolve([self.item.coordinate])
82
+ for entries in [
83
+ {'dependency-lock.json':json.dumps(lock).encode(),'artifacts/'+self.item.sha512+'.jar':b'tampered'},
84
+ {'dependency-lock.json':json.dumps(lock).encode(),'artifacts/'+self.item.sha512+'.jar':self.payload,'extra':b'bad'}]:
85
+ with self.assertRaises(SkillError):gateway.import_bundle(self.bundle(entries))
86
+ self.assertEqual(list(gateway.cache.iterdir()),[])
87
+
88
+ @staticmethod
89
+ def bundle(entries):
90
+ output=io.BytesIO()
91
+ with zipfile.ZipFile(output,'w') as archive:
92
+ for path,payload in entries.items():archive.writestr(path,payload)
93
+ return output.getvalue()
94
+
95
+ def test_repositories_and_distribution_paths_are_server_policy(self):
96
+ for url in ['http://repo.example','https://user:secret@repo.example','https://repo.example/?token=x']:
97
+ with self.assertRaisesCode('DEPENDENCY_REPOSITORY_DENIED'):self.gateway(repository=url)
98
+ for path in ['../escape.jar','/absolute.jar','https://elsewhere/x.jar']:
99
+ self.catalog={self.item.coordinate:replace(self.item,distribution_path=path)}
100
+ gateway=self.gateway(layout='distribution',fetch=lambda *_:self.fail('Unapproved path downloaded'))
101
+ with self.assertRaisesCode('DEPENDENCY_SOURCE_NOT_CONFIGURED'):gateway.materialize(gateway.resolve([self.item.coordinate]))
102
+
103
+ def test_identical_binary_in_two_coordinates_is_exported_once(self):
104
+ alias=replace(self.item,coordinate='demo:alias:1.0');self.catalog[alias.coordinate]=alias
105
+ gateway=self.gateway(fetch=lambda *_:self.payload);lock=gateway.resolve(list(self.catalog))
106
+ bundle=gateway.export_bundle(lock)
107
+ with zipfile.ZipFile(io.BytesIO(bundle)) as archive:self.assertEqual(len(archive.namelist()),2)
108
+ self.assertEqual(self.gateway('target',offline=True).import_bundle(bundle),lock)
109
+
110
+
111
+ if __name__=='__main__':unittest.main()