Skip to content

fix(openclaw): preserve complete remote trajectories - #2327

Open
osolmaz wants to merge 48 commits into
harbor-framework:mainfrom
osolmaz:fix/openclaw-remote-config
Open

osolmaz wants to merge 48 commits into
harbor-framework:mainfrom
osolmaz:fix/openclaw-remote-config

Conversation

@osolmaz

@osolmaz osolmaz commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Updated on behalf of Onur Solmaz (osolmaz).

Summary

Harbor must preserve OpenClaw run details after a remote environment is removed.
The old approach depended on one parent JSONL path, so it could not handle OpenClaw's SQLite storage or complete subagent runs.
Harbor now calls the standalone @openclaw/openclaw-atif npm package to export the current run, then preserves its trajectory, receipt, and media before removing private trial state.

The source repository is openclaw/openclaw-atif. This is the official package for OpenClaw-to-ATIF conversion.
The package will be published under the @openclaw npm scope as @openclaw/openclaw-atif.
Harbor pins @openclaw/[email protected]. The scoped release is not on npm yet, and its converter code matches the tested [email protected].

What changed

OpenClaw owns access to session storage, and the package owns conversion.
Harbor keeps agent setup, private configuration, current-run selection, artifact transfer, validation, and the existing labeled summary fallback.

  • Keep the adapter in one file, openclaw.py, including private receipt models and the loader. Keep conversion tests in the package and adapter tests in Harbor.
  • Install npm release @openclaw/[email protected]. Its converter code is source revision 08da23b403544864ac3c2f2859ef5b686b17a263, which includes the cost fix and provider-prompt event support. The scoped release changes package metadata only.
  • Install under the agent user's home with --save-exact --omit=dev --ignore-scripts. The release includes compiled output, so the converter needs neither Git nor a TypeScript compiler.
  • Export the exact root session ID with the trial's OPENCLAW_STATE_DIR. Keep temporary files inside Harbor's private trial directory.
  • Accept exit 0 (complete) and exit 2 (partial). Preserve trajectory.json, receipt.json, and optional media/; move the trajectory last. Hard failures retain the labeled command-summary fallback.
  • Keep the package's files and directories owner-only after the transfer: 0600 files inside 0700 directories, matching the modes openclaw-atif writes. The permission reset is limited to real paths inside the log directory and skips links. This corrects file modes when a provider recreates downloads under a permissive umask.
  • Read Harbor context totals from the receipt's family aggregate. Each trajectory retains its own per-session metrics, so child usage is not counted twice.
  • Reject malformed metrics or a receipt whose SHA256 does not match the trajectory. Missing cost remains unknown; explicit zero remains zero.
  • Clear only adapter-owned output from local and remote logs before each run. This lets a reused agent replace its media, removes old media when the next export has none, and prevents an early failure from importing earlier results. Leave the shared log directory and unrelated files unchanged.
  • Keep the existing cancellation, private configuration, cleanup, and provider behavior.

The package preserves exact child relationships, stable-capture checks, observed content, cache-write accounting, and deterministic IDs. It retains safe bundle-local media with a limit of 64 files and 32 MiB per file. It does not fetch remote media or read private session storage.

Testing

The published [email protected] package passed the previously failing live Luna case on Harbor commit 73239f5c. The later permission and run-reuse fixes are verified locally on 72a064b7: 106 focused tests and 2,805 broader unit tests passed, with 2 skipped. Ruff and type checks also passed.

The 12 initial reuse cases failed before the fix. The completed lifecycle test file now passes 15 cases. It covers shared and downloaded logs, two successive media exports, a later export without media, startup failures, linked output, and a bounded reset timeout. The publication and cleanup shells are real; OpenClaw and package output are stand-ins. The permission tests also check provider downloads that recreate files with a permissive umask.

uv run ruff check --fix .
uv run ruff format .
uv run ty check
uv run pytest tests/unit/agents/installed/test_openclaw*.py -q --tb=short
uv run pytest tests/unit/agents tests/unit/trial tests/unit/utils tests/unit/environments/test_e2b.py -q --tb=short
git diff --check

The isolated Docker trial used npm OpenClaw 2026.9.3 (1391f7c), Node 24.18.0, and requested and observed openai/gpt-5.6-luna. Harbor installed [email protected] from npm with lifecycle scripts disabled; no installed code was patched. The container had 2 CPUs and 6 GiB RAM, verified before model execution.

harbor trial start --config trial.json ran with a private local config selecting those versions, a 180-second agent timeout, and automatic environment deletion. It completed in about 89 seconds:

  • Reward 1. Two tool calls wrote and read 837, then returned the required final marker.
  • Complete ATIF 1.8 export with 12 steps and zero diagnostics. All three provider.prompt.observed events remain in extra.openclaw.runtime.events.
  • Harbor schema validation and the receipt SHA256 check passed. No summary fallback was used.
  • Harbor context matches the receipt: 94,246 prompt tokens, 62,184 cached tokens, 149 output tokens. Runtime-reported cost: $0.0470269, not a confirmed charge.
  • Both output files have mode 0600. The verifier confirmed private staging removal; Harbor then removed the container. A secret scan found no matches in 17 output and evidence files.

The same task previously failed with 0.1.0: reward 0, partial receipt, and three unsupported provider-prompt events. That result remains preserved. All original verifier checks remain unchanged; the new trial also checks the installed package version and retained observations.

Package [email protected] passed 196 tests, mutation checks, Slophammer, pinned Harbor conformance, installed-CLI media/metadata checks, and packaging. The earlier full Harbor unit run passed 8,246 tests with 23 skipped; that count predates the new metadata test.

Review and limits

The capture-state finding was fixed in 378b88a5. The media-reuse finding and early-failure stale results are fixed in 72a064b7, with before/after regression evidence. The permission and lifecycle changes were reviewed directly. The package fix was reviewed with no findings.

The [email protected] release is available with the expected source revision. Its publish action succeeded, but the following registry-verification step timed out. A later registry read and the clean live install both confirmed 0.1.1; the publish workflow was not rerun.

The live trial contains no media or subagents. Those paths have fixture and adapter coverage, not new live coverage from this trial. Earlier local-shell evidence used a different OpenClaw build and is not the basis for this result. This Harbor PR remains open and unmerged. The latest Harbor change moves the pin to @openclaw/[email protected]. That scoped release is not on npm yet, so a live run needs the publication first. The unit tests use a fake environment and do not reach npm. Current-head Linux and Windows tests, Ruff, type checks, and Devin Review passed. No unresolved review threads remain. Devin's temporary unpublished-package concern was answered with registry and live-install evidence, then resolved.

Follow-ups

Publish @openclaw/[email protected] on npm. A live re-run then confirms the scoped install end to end.

Agent usage

The earlier commits were written with the pi coding agent, using GPT-5.6 Sol for the initial changes and DeepSeek V4.1 Flash for the merge with main and follow-up changes. The package integration, tests, and review also used coding-agent assistance. Onur's final code and description review remains required.

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

@osolmaz 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:

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@osolmaz
osolmaz marked this pull request as draft July 14, 2026 05:36
@osolmaz
osolmaz marked this pull request as ready for review July 14, 2026 05:39
devin-ai-integration[bot]

This comment was marked as resolved.

@osolmaz osolmaz changed the title fix(openclaw): upload config to remote environments fix(openclaw): preserve remote config and sessions Jul 14, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@osolmaz
osolmaz force-pushed the fix/openclaw-remote-config branch from af9a7f0 to 9e8fa7c Compare August 19, 2026 10:36
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@osolmaz

osolmaz commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Published [email protected] and pinned it in 73239f5c. The release comes from 08da23b403544864ac3c2f2859ef5b686b17a263.

The previously failing live case now passes. A fresh Docker trial used npm OpenClaw 2026.9.3 (1391f7c), Node 24.18.0, and requested and observed openai/gpt-5.6-luna. Harbor installed the published converter without patching it. The strict verifier returned reward 1: complete ATIF 1.8, 12 steps, two tool calls, zero diagnostics, and all three provider.prompt.observed events retained. Harbor schema, receipt hash, family totals, owner-only files, and private-staging cleanup checks passed. The container was removed. The original failed trial and every original verifier check are preserved.

All 127 focused tests passed. Commands:

uv run ruff check --fix .
uv run ruff format .
uv run ty check
uv run pytest tests/unit/agents/installed/test_openclaw.py tests/unit/agents/installed/test_openclaw_capture.py tests/unit/agents/installed/test_openclaw_trajectory.py tests/unit/agents/test_factory.py tests/unit/agents/installed/test_system_dependencies.py -q
git diff --check

The live command was harbor trial start --config trial.json, with a private local configuration for the versions above, Docker, a 180-second agent timeout, and automatic cleanup. Current-head Linux and Windows CI, Ruff, type checks, and Devin Review passed. The pin and metadata regression test were reviewed directly. Devin's unpublished-package comment is resolved with registry and live-install evidence.

The npm publish action succeeded; only its final registry check timed out. Later registry and install checks confirmed the release, so no second publish was attempted. This live trial had no media or subagents; those paths retain fixture and adapter coverage. The PR remains open and unmerged.

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)
@osolmaz

osolmaz commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Downloaded media permissions

Root cause. The E2B transfer path recreates remote entries with mkdir and Path.write_bytes, so the modes openclaw-atif writes (0700 directories, 0600 files) arrive on the host as 0755/0644 under umask 022. _load_export narrowed only trajectory.json and receipt.json, so package-owned image and audio files and the media/ directory stayed readable by other host users. This is a Harbor artifact-handling gap, not an E2B request.

Fix (4b5d51a4). Harden every package-owned artifact after the transfer: the two JSON files and the whole media/ tree, to 0600 files inside 0700 directories, which are the modes openclaw-atif itself writes. Hardening reuses harbor.utils.path_safety.validate_output_path for containment, so a path that resolves outside the logs directory, or any link, is left untouched. The shared log directory keeps its mode, so openclaw.txt and instruction.txt stay 0644. Hardening runs before receipt validation, and also on the failed-capture path that can leave a media bundle behind.

Repro (no network, no cloud). Real E2BEnvironment.download_dir/download_file with a mocked sandbox.files.list/read over the openclaw-atif golden media fixture, then the real _load_export, under umask 022.

Before (73239f5c):

media/          0755
media/*.png     0644
media/*.wav     0644
trajectory.json 0600
receipt.json    0600

After (4b5d51a4):

media/          0700
media/*.png     0600
media/*.wav     0600
trajectory.json 0600
receipt.json    0600
openclaw.txt    0644  (shared log, unchanged)

Regression tests. Eight new tests; seven of them fail on 73239f5c.

  • test_downloaded_media_is_owner_only_after_load — normal downloaded modes (0755/0644) become 0700/0600, and the shared log and log directory keep their modes.
  • test_invalid_receipt_still_hardens_downloaded_media — a receipt hash mismatch still hardens the bundle before it raises.
  • test_failed_capture_still_hardens_downloaded_media — populate_context_post_run hardens a bundle left by a failed capture, with no trajectory present.
  • test_convert_trajectory_hardens_downloaded_media — the preview path hardens too.
  • test_hardening_leaves_linked_files_untouched — a linked file and a linked directory inside media/ keep their targets' modes.
  • test_linked_export_file_is_not_followed — a linked trajectory.json leaves its target at 0644; the old Path.chmod call followed the link and changed it to 0600.
  • test_hardening_does_not_walk_into_linked_directories — a link back to the shared log directory does not narrow Harbor's own logs.
  • test_linked_media_directory_is_left_alone — a linked media/ root is left alone (passes before the fix; it guards a naive recursive walk).

The four link tests fail if the containment gate is bypassed, so they constrain the fix rather than only record the new modes.

Checks (all on 4b5d51a4, clean worktree):

uv run ruff check --fix .   # All checks passed
uv run ruff format .        # 1420 files left unchanged
uv run ty check             # All checks passed
uv run pytest tests/unit/agents/installed/test_openclaw.py \
  tests/unit/agents/installed/test_openclaw_capture.py \
  tests/unit/agents/installed/test_openclaw_trajectory.py \
  tests/unit/agents/test_factory.py \
  tests/unit/agents/installed/test_system_dependencies.py -q   # 135 passed
uv run pytest tests/unit/agents tests/unit/trial tests/unit/utils \
  tests/unit/environments/test_e2b.py -q                       # 2790 passed, 2 skipped
git diff --check            # clean

Limits. The earlier live Docker trial contained no media, so it does not cover this path; the evidence here is the mocked-sandbox repro plus unit tests, with no live E2B run. The change is scoped to OpenClaw's package output, so other providers keep their release behavior, and the separate stale-results finding is untouched. [email protected] stays pinned.

This change was written and reviewed with the pi coding agent. Onur's own review remains required.

devin-ai-integration[bot]

This comment was marked as resolved.

@osolmaz

osolmaz commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

CI on 4b5d51a4 is green: Linux and Windows tests, Ruff, type check, labeler, and Devin Review all pass (tests, lint, and type check).

Devin's new finding about a reused agent instance and a leftover media/ directory is answered in the thread: the mechanics are correct, the behavior is present at 73239f5c, and a fix changes the publication contract rather than transfer permissions, so it stays with the separate reused-agent artifact work.

@osolmaz

osolmaz commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Updated on behalf of Onur Solmaz (osolmaz).

The media-permission fix and the remaining run-reuse issue are fixed at 72a064b786dced510d5ab238199b9c5240b2b5bc.

Downloaded package media now gets owner-only permissions. Each run also removes only the adapter-owned files from local and remote logs before startup. This lets the next export replace old media and prevents an early failed run from using an earlier trajectory or token count. The shared log directory and unrelated files remain unchanged, and link targets are left untouched.

I reviewed both changes directly. The 12 initial reuse cases failed before the fix. All 15 completed lifecycle tests now pass. They use real publication and cleanup shells with stand-in OpenClaw/package output. The permission fix has a separate mocked E2B download reproduction. No live E2B or live-media run was performed.

The following local commands passed:

uv run ruff check --fix .
uv run ruff format .
uv run ty check
uv run pytest tests/unit/agents/installed/test_openclaw*.py -q --tb=short
uv run pytest tests/unit/agents tests/unit/trial tests/unit/utils tests/unit/environments/test_e2b.py -q --tb=short
git diff --check

The focused run passed 106 tests. The broader run passed 2,805 tests with 2 skipped under a memory guard. The two skips and dependency deprecation warnings did not fail the run.

[email protected] is still the correct npm pin. A registry read confirms source revision 08da23b403544864ac3c2f2859ef5b686b17a263. These fixes change Harbor only, so no new npm release was made. The earlier live gpt-5.6-luna result remains evidence for 73239f5c. It was not repeated on this commit.

Linux and Windows CI, Ruff, type checks, and Devin Review passed on this commit. The Claude job was skipped. The media-reuse thread is resolved, and no unresolved review threads remain.

The PR remains open and unmerged. This update was prepared with coding-agent assistance. Onur's final review remains required.

osolmaz and others added 4 commits September 19, 2026 01:30
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)
The pinned openclaw-atif release already states whether a session family was captured completely, and why a capture was partial. Harbor read the receipt, used its family totals, and dropped the rest, so a partial export reached the trial result looking identical to a complete one.

Publish the status and the usable diagnostics through AgentContext.metadata under an openclaw_capture key. The labeled summary fallback reports through the same key with the same shape. The receipt diagnostics are advisory, so an unusable entry is dropped instead of discarding a hash-verified trajectory, and unknown diagnostic keys are not republished.

The package owns trajectory.json and the receipt binds its bytes, so the export path does not rewrite the trajectory file.

Co-Authored-By: DeepSeek V4.1 Flash · Novita <[email protected]>
Generated-By: pi 0.86.1 (https://pi.dev)
@vincentkoc

vincentkoc commented Sep 22, 2026 •

Copy link
Copy Markdown

Consolidated the accounting and retention/timing follow-ups from #3336 and #3338 here, on top of Onur's capture-status commit, without rewriting the existing branch history.

Current head: 27f8291. The adapter now pins the published @openclaw/[email protected] (release). Registry integrity/provenance and a fresh installed-CLI smoke are verified.

The combined adapter preserves Onur's permissive diagnostic filtering and capture source labels, keeps missing usage distinct from zero, includes observed cache-write tokens, and adds opt-in public source retention plus controller phase timing. Retained 0.1.3 bundles include a checksum-verified replay graph. No generic Harbor aggregation or resource sampler was added.

Validation at this head: 147 focused adapter tests, repository Ruff lint/format, full configured type check, and diff checks passed locally. Hosted lint/type checks and Devin Review pass; Linux/Windows integration checks are still running. The follow-up commit fixes noisy nvm stdout, validates locally transferred retained sources, and handles diagnostics surrounding a confined staging path.

The older version/publication paragraphs in the PR description are superseded by this update; this account can push the fork branch but cannot edit that description. Changes and consolidation were made with coding-agent assistance at Vincent's request. Onur's review remains required. The redundant follow-ups are closed, with their branches retained.

Live functional smoke at this exact head: OpenClaw 2026.9.5 with the installed registry exporter 0.1.3 completed Harbor's Hello World task on isolated Ubuntu ARM64/Docker/cgroup-v2; verifier reward was 1.0. The trial container had 1 CPU/4 GiB and was non-privileged. Retention and all four controller timing phases completed. After container cleanup, a fresh registry exporter installation replayed the retained sources to byte-identical trajectory and receipt.

Evidence boundary: the export is partial, with unsupported-runtime-event diagnostics for runtime tool.call and tool.result events. The transcript tool call and observation are present (one each); runtime events are retained without pretending their semantics are fully understood. This is one functional smoke, not full family/resource qualification or a scored performance campaign. Temporary proxy and VM are stopped.

devin-ai-integration[bot]

This comment was marked as resolved.

vincentkoc and others added 2 commits September 22, 2026 01:18
The section was added to the branch outside the scope of this change. It documents retain_source_bundles, openclaw_source_retention, and openclaw_phase_timing. The file now matches its state on the pull request base.

Co-Authored-By: DeepSeek V4.1 Flash · Novita <[email protected]>
Generated-By: pi 0.86.1 (https://pi.dev)
vincentkoc and others added 3 commits September 22, 2026 13:35
Harbor already times the trial phases on the result, so the adapter kept a second set of timings with its own clock and its own shape. Remove _record_phase, the openclaw_phase_timing metadata key, the reset on run reuse, and the two tests that pinned them. The class docstring now records that Harbor owns phase timing.

The cleanup guarantee stays: a failed command must not hide removal of the private trial directory, so that test now checks the remote command instead of the removed phase record.

Co-Authored-By: DeepSeek V4.1 Flash · Novita <[email protected]>
Generated-By: pi 0.86.1 (https://pi.dev)

This branch has not been deployed

No deployments
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