Repository navigation
fix(openclaw): preserve usage and capture metadata (follow-up to #2327) - #3336
Closed
vincentkoc wants to merge 39 commits into
Closed
vincentkoc wants to merge 39 commits into
vincentkoc wants to merge 39 commits into
Conversation
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Co-Authored-By: GPT-5.6 Sol <[email protected]> Generated-By: pi 0.84.2 (https://pi.dev)
Merge main into the trajectory capture work and adopt the current Harbor agent contracts. Conflict resolution in openclaw.py keeps main's newer code and adds the trajectory attributes the capture path needs: - keep the capability declaration import and add the validation import - keep the options-based super() call and read the export flag from self.options.session_to_trajectory - drop main's session JSONL branch, which the public export replaces Changes on top of the merge: - implement convert_trajectory() for preview conversion without changing run results, sharing the export loader with populate_context_post_run - emit ATIF v1.8 - describe session_to_trajectory as the rich export request - cover the conversion hook and the agreement between the rolled-up totals and compute_model_usage() Co-Authored-By: DeepSeek V4.1 Flash · Auto · Novita <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Address two review findings on the trajectory converter. Cost: a message that reports tokens without a cost total no longer counts as free. `_metrics` returns whether pricing was present, the session omits `total_cost_usd` when any token-bearing message is unpriced, and every ancestor inherits that unknown status through the capture graph. A partial numeric total can no longer ship. Media: content mapping keeps image and audio parts that name a media type and a location, such as a file path or URL, as ATIF content parts. Inline base64 media cannot be represented in ATIF, so it becomes a truthful placeholder and the capture is marked partial with the `media-content-not-preserved` warning code. This covers user messages, assistant messages, and tool results. Co-Authored-By: DeepSeek V4.1 Flash · Auto · Novita <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
The first pass only recognised `image` and `audio` parts, so any other part type still disappeared without a trace while the capture reported `complete`. Content mapping now tracks the part types that have their own converters, either a tool call or reasoning, and records every other non-empty part as omitted. It also accepts the `image_url` and `input_image` shapes that carry a declared media type and location. Covered by `test_unknown_content_part_marks_capture_partial` and `test_provider_image_url_shape_is_preserved`. Co-Authored-By: DeepSeek V4.1 Flash · Auto · Novita <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Address three more review findings on the converter. Local media: a path inside the agent environment is deleted with that environment, so it no longer counts as preserved. The converter copies such a file next to the trajectory under `media/`, references it with a relative path that resolves against the trajectory directory, and keeps the copy private. A file that is missing, a symlink, or larger than the 32 MiB cap becomes a placeholder with the `media-content-not-preserved` warning instead. Zero cost: an explicit `cost.total: 0` establishes that pricing is known. Step metrics now carry a zero cost, and the session reports `total_cost_usd: 0.0` when every token-bearing message is priced, so a free run no longer reports an unknown cost. Identity: `trajectory_id` now derives from the exported `session_id` together with the session key. Isolated trials reuse the key `agent:main:main`, so the key alone gave unrelated runs the same identifier. Co-Authored-By: DeepSeek V4.1 Flash · Auto · Novita <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Address two more review findings. Repeated media: the file limit now counts retained files, not references to them. A payload is content-addressed before the limit is applied, so a file that is already retained stays referenceable after the limit is reached instead of turning into a placeholder. Exposure: local media is copied only when the resolved path stays inside the session's own export bundle. A crafted part that names a credential, configuration, or unrelated task file is dropped with the `media-content-not-preserved` warning instead, so it cannot reach the synchronized logs. Co-Authored-By: DeepSeek V4.1 Flash · Auto · Novita <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
A media location can be absolute, a URL, or relative to the export bundle that contains the event. Resolving a relative location from the process directory made the containment check reject a valid bundle-local file, so the part became an omission placeholder. A relative location now resolves from the bundle root before the containment, symlink, size, and regular-file checks run. Co-Authored-By: DeepSeek V4.1 Flash · Auto · Novita <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Run public session discovery, export, and conversion in one remote helper. Keep all private state and exports under one trial directory with bounded cleanup, and fail the run when cleanup fails after a capture fallback. Preserve partial trees at capture limits and add standalone helper, cancellation, and combined-failure coverage. Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Download backends recreate remote files with `mkdir` and `Path.write_bytes`, so an export written as 0600 files inside a 0700 directory arrives on the host as 0644 files inside a 0755 directory under umask 022. `_load_export` narrowed only `trajectory.json` and `receipt.json`, which left the package's image and audio files readable by other host users. Harden every package-owned artifact after the transfer: the two JSON files and the whole `media/` tree. Directories become 0700 and files 0600, which are the modes `openclaw-atif` writes. Hardening reuses `validate_output_path`, so a path that resolves outside the logs directory, or any link, is left untouched; the shared log directory keeps its mode. Hardening runs before receipt validation and also when a failed capture leaves a media bundle behind, so private media is never left readable. Co-Authored-By: DeepSeek V4.1 Flash · Auto · Novita <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
Co-Authored-By: GPT-6 Astra <[email protected]> Generated-By: pi 0.85.1 (https://pi.dev)
The converter package moved to the @openclaw npm scope. Install @openclaw/[email protected] instead of [email protected]. The scoped release is not on npm yet. The unit tests use a fake environment, so they pass. A live run needs the published release. Co-Authored-By: DeepSeek V4.1 Flash · Novita <[email protected]> Generated-By: pi 0.86.1 (https://pi.dev)
|
@vincentkoc is attempting to deploy a commit to the Harbor Framework Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Enjoy a better diff viewing experience by clicking one of these URLs: |
This was referenced Sep 21, 2026
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dependency
Depends on #2327 (Onur's OpenClaw ATIF integration), pinned at
9468613145492509d92c360eb6d93d27c3dd9392. This is a separate, non-blocking follow-up; it does not change Onur's branch.Review only the follow-up: one commit / two files.
The upstream diff currently includes the predecessor commits. Keep this draft until #2327 merges, then rebase onto
mainand drop those commits. This does not need to hold up #2327 or the exporter release.Changes
Noneand explicitly reported zero totals as0in the OpenClaw adapter.AgentContext.metadata["openclaw_capture"].Capture completeness is not a claim about usage coverage or successful execution. Diagnostic messages remain in the receipt; only codes are copied into trial metadata.
The change is limited to the adapter and regression tests. No shared Harbor schema, generic per-model aggregation, source retention, resource collection or execution-timing changes.
Validation
At follow-up commit
be142ea691fd80792d181e0383fb44a19c19971b:ruff check --fix .: passed.ruff format .: 1,424 files unchanged.ty check: passed.git diff --check: passed; working tree clean.Commands ran with
uv run --no-syncagainst the existing task environment. No full unit suite, live-provider benchmark or Windows execution was performed locally. Hosted CI and maintainer review are separate checks.AI assistance
OpenClaw/Codex implemented this follow-up, wrote the regression tests and drafted this description under the author's direction. Human review is pending; this remains a draft.
Dependency recheck (2026-09-21)
PR #2327 independently advanced to
8649c58f3c110f806723bec9545361f639ab2a89with capture-metadata support after this draft was based. Its metadata overlaps this draft; reconcile that overlap when restacking after the predecessor lands. This draft remains atbe142ea691fd80792d181e0383fb44a19c19971b; neither branch was rewritten in this continuation. The nullable/zero and cache-write accounting fixes remain a separate contribution.The opt-in source retention and controller phase timing follow-up is isolated in #3338.