# Harness integration: official SDK, durable recovery and OTLP

## English

This lab closes a specific integration gap: it actually runs the official OpenAI Python SDK through HTTP, the OpenTelemetry SDK and OTLP/HTTP protobuf exporter, two separate worker processes, file-backed SQLite recovery, and bounded child processes. **All Responses are authored localhost fixtures. No generative model or remote merchant is contacted, no model credential is read, and no billed request is made.** The fixed SDK credential is an explicit fake string. A working SDK call demonstrates transport and response handling, not provider quality or account access.

Validated on Python **3.12.14**, macOS arm64, with **openai 3.41.0**, **httpx2 2.16.0**, **opentelemetry-sdk / opentelemetry-exporter-otlp-proto-http 1.45.2** and **protobuf 7.36.2**. `requirements.txt` pins the actual full dependency set. Linux is an intended POSIX route but was not executed in this release; Windows is unsupported because the resource/process controls use POSIX APIs. Dependency installation requires network access; lab execution uses only `127.0.0.1`.

### Setup and execute

Download [the source ZIP](https://ai.lwkjob.com/downloads/harness-production-integration-v1.zip), extract it, and enter `harness-production-integration-v1/`. Use a fresh empty work directory for each run. Run:

```sh
python3.12 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python -B -m unittest -v
.venv/bin/python -B lab.py demo --work work/ok
.venv/bin/python -B lab.py demo --work work/rejected --reject-export
```

Six test methods must pass. They include a named fictional parent-secret/key sentinel check; they do not inspect an actual credential. The normal demo exits 0 and prints exactly the following stable fields (object-key order is not significant):

```json
{"after_recovery":"completed","before_recovery":"outcome_unknown","call_output_correlated":true,"effect_count":1,"otlp_export_observed":true,"propagated_parent_observed":true,"raw_sensitive_payload_absent":true,"recovery_link_observed":true,"sdk_model_requests":3,"wrong_call_id_rejected":true}
```

The rejected-export run deliberately logs HTTP 400 exporter errors to stderr, exits 0 and retains `completed` and one effect; its `otlp_export_observed`, `propagated_parent_observed` and `recovery_link_observed` are false, and `raw_sensitive_payload_absent` is null because no exported bytes were observed. Exit 0 means the bounded scenario ran, not that telemetry delivery succeeded. Worker exits are `[75,0]`: 75 is the intentionally lost-response boundary, caught by the parent runner; the replacement worker exits 0.

### Follow the actual boundaries

1. `client_for` accepts an explicit numeric-port `http://127.0.0.1` origin only, sets `max_retries=0`, disables proxies and redirect following, and supplies a fake key directly. The real SDK sends one Responses request; the fixture returns a fixed `create_ticket` function call. The worker validates its arguments and commits intent, exact call output, trace identity and the original business key to Agent SQLite before dispatching the business action.
2. An independent HTTP handler commits one fictional ticket and receipt to merchant SQLite, then shuts down the socket without a response. The SDK raises a transport error. The worker commits `outcome_unknown`, exports its spans and exits 75. This is a controlled process exit after state persistence, not a proof of correctness under arbitrary power loss.
3. A different worker PID reopens the Agent database, links its new trace to the persisted original span, and queries the original receipt key. It validates the payload digest before supplying matching `function_call_output` through a second real SDK Responses request. A missing receipt leaves the effect unknown and does not authorize resending. The demo also repeats the same key/binding, rejects a changed binding with HTTP 409, and sends one bad call ID that the fixture rejects with HTTP 400. Three `/responses` requests means two valid fixture rounds plus one negative control, **zero model generations**. Call-ID correctness is an application/fixture contract, not a promise that the SDK enforces business meaning.
4. Explicit client spans inject W3C `traceparent`; the HTTP handler extracts it to create a server span. A recovery span has an actual OTel `Link` to the persisted earlier trace/span. The official protobuf exporter sends spans to the miniature local OTLP test receiver in `fixture.py`. It is not the OpenTelemetry Collector distribution and has no persistent queue/backend. Spans use an attribute allowlist; raw prompt/tool payloads and the fictional sensitive marker are absent from the observed protobuf bytes. Other payloads and instrumentations require their own redaction tests.
5. `launch` builds an environment from fixed safe values, invokes an absolute Python executable without a shell, and applies CPU 2s, file-size 64KiB and open-file 64 limits in an exec bootstrap. It avoids `preexec_fn` in the threaded parent. A wall-clock timeout kills the process group and waits for the direct child. Output reads are bounded. Tests observe sentinel omission and a reaped timed-out child. **These controls do not deny filesystem/network access or constitute a hostile-code sandbox.** No memory limit, namespace, syscall filter or credential proxy is implemented.

### Inspect evidence, not only a green flag

`work/ok/` contains `report.json`, `workers.json`, `http-audit.json`, `merchant-ledger.json`, `otlp-spans.json`, base64 `otlp-batches.json`, and separate Agent/merchant SQLite files. Source hashes and actual versions are in the report. The normal recorded run exported 13 spans; count is descriptive for this implementation, not a service capacity target. Audit HTTP records retain method/path/status/digest and a dropped-response flag rather than raw request text. The database data is fictional.

Inspect the original intent/unknown/completed audit rows, the single merchant receipt, both worker PIDs, request correlation, propagated parent IDs and recovery link. `first_usage=null` stays unknown; the second fixture's `10/2/12` usage is **authored fixture data**, not provider tokens or monetary cost. Malformed/empty/inconsistent/bool usage is rejected as unknown. `force_flush_returned=true` can coexist with every exporter result failing: telemetry is best-effort diagnostic delivery, not the durable business audit. SDK retries are disabled here; read-only receipt reconciliation is a separate application operation. Do not turn off all retries in a production system without classifying each operation's semantics.

[Recorded evidence](https://ai.lwkjob.com/research-evidence/harness-production/README.md) includes the initial red log, passing regression, normal/rejected runs and file hashes. `MANIFEST.json` hashes the allowlisted source package. Hashes establish byte identity, not third-party attestation, authorship or production readiness. Rebuild with:

```sh
.venv/bin/python -B package.py --out harness-production-integration-v1.zip
```

### Deployment recipes — not executed

`Dockerfile.example` is supplied only as an unexecuted starting recipe. Build-time package download and runtime egress are separate decisions. A possible disposable local exercise is:

```sh
docker build -f Dockerfile.example -t harness-local-lab .
docker run --rm --network none --read-only --cap-drop ALL --security-opt no-new-privileges --pids-limit 32 --memory 256m --cpus 1 --tmpfs /tmp:rw,noexec,nosuid,nodev,size=64m --tmpfs /work:rw,nosuid,nodev,uid=65532,gid=65532,size=64m harness-local-lab
```

The tmpfs evidence disappears when this disposable container stops. A persistent production audit needs a separately designed store and retention policy. No container, microVM, hosted collector, production identity, real payment system, multi-host failover, autoscaling, quality benchmark or SLA was validated here. For a microVM design exercise, specify a read-only guest image, explicit artifact mount, guest egress policy, external deadline enforcement, scoped credential proxy and host-controlled teardown; document its threat model and test escape/credential-leak cases in a dedicated environment. This package does not provide a tested microVM launcher.

## 中文

本实验补的是具体集成缺口：实际运行官方 OpenAI Python SDK 的HTTP请求、OpenTelemetry SDK与OTLP/HTTP protobuf导出器、两个不同worker进程、文件SQLite恢复和受控子进程。**Responses全部来自作者编写的localhost夹具；不联系生成模型或远端商家，不读取模型密钥，不产生计费请求。** SDK凭据是直接传入的固定假字符串；SDK发包成功仅证明本机传输与响应处理，不能证明提供方质量或账号接入。

已验证Python **3.12.14**、macOS arm64，以及上方固定版本；完整实际依赖锁在`requirements.txt`。Linux是预期POSIX路线但本轮未执行；资源及进程控制依赖POSIX，未支持Windows。仅安装依赖需要网络，实验执行只使用`127.0.0.1`。解压后进入`harness-production-integration-v1/`，执行上方完全相同的五条setup/run命令，每次使用新的空work目录。

六项测试应全部通过，包含虚构父进程secret/key哨兵检查；不检查真实密钥。正常demo退出0并打印上方相同JSON。拒收实验故意向stderr输出HTTP400导出错误，仍保留`completed`及一条效果；三个导出/父子关联字段为false，没有观察到导出字节时`raw_sensitive_payload_absent=null`。退出0表示有界场景执行完，不表示遥测送达。worker退出为`[75,0]`，75是父运行器预期捕获的丢返回边界。

### 沿真实边界阅读

1. `client_for`只接收明确数值端口的`http://127.0.0.1`源，设置`max_retries=0`，禁用环境代理和重定向，直接传入假key。真实SDK第一轮收到固定`create_ticket`函数调用；worker校验参数后，先将意图、完整调用条目、trace身份和原业务键提交Agent SQLite，再派发动作。
2. 独立HTTP handler向商家SQLite提交一条虚构工单及回执，随后关闭socket而不返回响应。SDK抛传输错误，worker持久化`outcome_unknown`、导出span并退出75。这是持久化后的受控退出，不等于任意断电可靠性证明。
3. 不同PID的新worker重新打开Agent库，以持久化的原trace/span建立恢复Link，按原键只读查询回执，核对payload摘要后，通过第二轮真实SDK请求发送匹配`function_call_output`。查询为空仍保持未知，不允许重发。相同键/绑定重放返回同回执，改变绑定收到409，错误call ID收到400。三次`/responses`请求是两轮有效夹具与一次反例，**模型生成数为零**；调用关联由应用/夹具合同验收，不是SDK自动理解业务。
4. 客户端span注入W3C `traceparent`，HTTP handler提取后创建同trace的server span；恢复span实际携带指向旧trace/span的OTel Link。官方protobuf导出器向`fixture.py`的微型本机OTLP测试接收器发包。它不是OpenTelemetry Collector发行版，无持久队列/后端。span属性采用白名单，实测protobuf不含原始prompt、工具payload或虚构敏感标记；新增payload/自动埋点仍须另测脱敏。
5. `launch`用固定值构造环境，使用绝对Python路径且不启shell，在exec引导进程中施加CPU2秒、文件64KiB、打开文件64项限制，避免在多线程父进程里使用`preexec_fn`。墙钟超时会杀进程组并等待直属子进程，输出读取有界。测试观察哨兵未继承及超时子进程已回收。**这些控制没有禁止文件/网络能力，不构成恶意代码安全沙箱**；没有实现内存隔离、namespace、系统调用过滤或凭据代理。

### 读证据与独立账本

`work/ok/`含上方列出的JSON、原始protobuf的base64批次，以及相互分离的Agent/商家SQLite。报告绑定实际源码摘要和版本；正常记录导出13个span仅描述本实现，不能变成生产容量门槛。HTTP审计保存方法/路径/状态/摘要与丢返回标志，不保存原始请求正文；数据库内容为虚构。

核对原意图/未知/完成审计行、商家唯一回执、两个worker PID、调用关联、跨HTTP父ID与恢复Link。首轮`first_usage=null`保持未知，第二轮`10/2/12`是**作者夹具数值**，不是提供方token或金额。空白、格式错误、不一致、bool用量均视为未知。`force_flush_returned=true`可与所有导出失败并存；遥测是尽力诊断传送，不是持久业务审计。本实验关闭SDK重试，原键只读对账是另一项应用动作；生产重试政策仍须按动作语义分类。

上方证据链接含红基线、通过回归、正常/拒收运行和文件摘要。`MANIFEST.json`绑定白名单源码，按上方打包命令可重建；摘要只标识字节，不认证第三方、作者或生产就绪。

### 部署配方未执行

`Dockerfile.example`及上方Docker命令仅为未执行起点；构建下载依赖与运行时出网应分别控制。一次性tmpfs证据在容器结束后消失，生产审计仍需另行设计持久存储与保留政策。本轮未验证容器、microVM、托管采集器、生产身份、真实支付、多机故障转移、自动扩缩容、质量基准或SLA。microVM设计练习应明确只读镜像、产物挂载、guest出网策略、外部截止执行、有限凭据代理及宿主清理，在专用环境测试逃逸与凭据泄漏；本包没有已验证microVM launcher。

## Official references / 官方依据

Reviewed 2026-10-30. Version applicability comes from the installed lockfile, not an assumption that a future SDK is identical.

- [Official OpenAI Python SDK](https://github.com/openai/openai-python): custom base URL/client, typed Responses and configurable retries/timeouts.
- [OpenTelemetry Python exporters](https://opentelemetry.io/docs/languages/python/exporters/): official OTLP exporter and span processors.
- [OpenTelemetry context propagation](https://opentelemetry.io/docs/languages/python/propagation/): injection/extraction across service boundaries.
- [OpenTelemetry trace API](https://opentelemetry-python.readthedocs.io/en/latest/api/trace.html): span contexts and links.
