Skip to content

feat(openclaw): retain replay sources and record phase timing - #3338

Closed
vincentkoc wants to merge 40 commits into
harbor-framework:mainfrom
vincentkoc:feat/openclaw-replay-retention-timing
Closed

vincentkoc wants to merge 40 commits into
harbor-framework:mainfrom
vincentkoc:feat/openclaw-replay-retention-timing

Conversation

@vincentkoc

Copy link
Copy Markdown

Summary

Separate follow-up to #3336 and #2327. Neither predecessor branch is modified. Keep this draft until those changes land, then rebase and drop the predecessor commits.

Live recheck: #2327 independently advanced to 8649c58f3c110f806723bec9545361f639ab2a89 with capture-metadata support after this stack was based. Its metadata overlaps #3336; reconcile that overlap during restacking. This draft does not claim to include that newer predecessor head.

Incremental review: vincentkoc/harbor@be142ea...f6cef25

  • Opt in with retain_source_bundles=true to request the exporter's existing --keep-source-bundles flag and retain public bundles before private trial cleanup.
  • Accept only the expected exporter staging path inside the per-trial directory; reject linked sources and occupied/linked destinations. Do not copy private state/configuration. Extend owner-only hardening and run-reuse cleanup to the retained directory.
  • Report retention separately from trajectory capture; an unavailable source archive does not erase a valid capture.
  • Record setup/configuration, command, export/retention, and cleanup with one controller monotonic clock, including failed operations. Preserve Harbor's outer duration and the original execution/cleanup errors.

These are controller-observed remote-operation durations, not exact container command time or provider latency. There is no resource collector, generic Harbor schema change, or campaign policy in this PR.

The pinned exporter 0.1.2 already retains bundles. Automatic graph replay requires the separate exporter follow-up and a later maintainer-owned release/pin; this PR does not bump or publish it.

Validation

  • Exact follow-up head: 132 OpenClaw adapter tests passed, including real shell publication tests with a synthetic CLI, source path/symlink rejection, private-state exclusion, owner-only permissions, operation failure, and run reuse.
  • Repository Ruff lint/format and configured type checks passed.
  • No live model, Docker/cgroup qualification, scored campaign, release, merge, or deployment is claimed.

Design and authorship

Keep execution, capture, retention, accounting, and resource proof separate. Reuse the existing exporter and adapter cleanup/hardening boundaries. Do not change Onur's integration branch or the accounting draft. Implementation, tests, and draft description were prepared with OpenClaw/Codex assistance; maintainer review is still required.

osolmaz and others added 30 commits August 19, 2026 18:36
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)
osolmaz and others added 10 commits September 18, 2026 14:02
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)
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)
@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown

@vincentkoc is attempting to deploy a commit to the Harbor Framework Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Enjoy a better diff viewing experience by clicking one of these URLs:

@vincentkoc

Copy link
Copy Markdown
Author

Consolidated into #2327 at aaa2fcb, including the published ATIF 0.1.3 pin. Closing this redundant follow-up; its branch and recovery evidence are retained. The canonical PR remains open and unmerged.

@vincentkoc vincentkoc closed this Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants