Preventing Contract Drift in a Desktop Agent
A report describes a desktop agent whose requests pass through TypeScript, Rust, Node.js, Python, and Java layers. Duplicated field definitions can drift silently, allowing isolated tests to pass while a request fails during integration. The proposed approach defines contracts with Pydantic for runtime validation, then generates domain-specific JSON Schema and TypeScript artifacts. A --check mode compares regenerated output with committed files so drift can be exposed before merging. The report notes that the checks are not yet connected to every continuous-integration pipeline and that command names, runtime envelopes, and the Java cloud service still require manual alignment. These architecture details and benefits are not independently verified.
Centralizing field definitions and checking generated artifacts provides a concrete way to expose cross-language contract drift before merge, while strict validation can prevent unknown fields from being silently accepted.
「前端已经加上这个字段了。」 「宿主这边还没看到。」 「运行时忽略了它,云端却当成必填。」
有一次,前端给「创建工单」加了可选字段 priority。宿主那一侧的结构还是旧的,多出来的字段被悄悄丢掉。运行时按自己的类型放行了,云端却把这个字段当成必填,请求到最后一跳才失败。三端没有一个人报错,直到联调才对上。同一个字段如果在 TypeScript、Rust、Node、Python 和 Java 里各写一遍,三个月后谁也说不清哪一遍才算数。漂移是静默的:宽松解析会把多出来或少掉的字段吞下去,单测各自通过,问题要到联调甚至用户那里才出现。
同一份定义,既用来校验,也用来导出各端契约
一个桌面智能体的典型请求会穿过很多层。界面用 TypeScript 发出命令,Rust 宿主收到后分发,对话引擎用 Node 处理,工作流引擎用 Python 处理,部分结果还要写回 Java 云端。方向很明确:一个字段只在一个地方定义,其余各端要么是它的生成物,要么和它比对。
#Pydantic#TypeScript#Rust#Node.js#Python#Java#JSON Schema#Serde