Skip to content

fix(update): hard-link owner-private dependencies during runtime retention - #197529

Closed
obviyus wants to merge 4 commits into
mainfrom
fix/update-retained-runtime-cost
Closed

obviyus wants to merge 4 commits into
mainfrom
fix/update-retained-runtime-cost

Conversation

@obviyus

@obviyus obviyus commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

What

Runtime retention no longer copies every dependency file when the umask is private.

#187549 made retention copy owner-private files so it could never raise the link count of package recovery state. Under umask 077 every installed file is owner-private, so a dev checkout copied its whole node_modules.

Dependency package files hold no recovery state, so they are now hard-linked whatever their mode. That covers anything inside node_modules/<pkg> or node_modules/@scope/<pkg>, including pnpm's .pnpm/*/node_modules/<pkg>.

These keep the copy rule:

  • the package's own files
  • a global install's own dist under node_modules
  • dot-named package-manager entries (.pnpm metadata, .openclaw.package-activation-*)

Retention also logs linked / copied counts. They were measured but never reported.

Reclaiming abandoned retained runtimes while other OpenClaw processes run is split into a follow-up. That change needs SQLite-owned creator custody and upgrade proof.

Evidence

Retention benchmark (prepareRetainedRuntimeFiles) on a copy of one dev checkout: 248,554 entries, 5.6 GB, all files mode 0600, same host:

linked copied inventory materialize total
base 0 217,727 156.8 s 880.7 s 17.3 min
this PR 191,901 25,826 51.2 s 240.2 s 4.9 min
reference: same tree, mode 0644 212,317 5,410 60.1 s 71.8 s 2.2 min

The remaining copies are workspace packages inside the checkout (extensions/*, packages/*), which keep the conservative rule. The fix run was taken under concurrent load, so its times are approximate.

The updater-runtime-retention step of a real managed update on that host (1,069 commits, base code) took 261.6 s of about 26 min.

End-to-end update (correction to the benchmark above). Full openclaw update --yes on isolated git checkouts under umask 077 (APFS, same host, load average ~10–18), one commit ahead, run back to back:

updater-runtime-retention linked / copied update total result
base 43fc744 248.5 s 0 / all 630 s ok, head on target, config hash and data unchanged
this PR b1c59a9 271.5 s 113,998 / 47,350 654 s ok, head on target, config hash and data unchanged

On APFS the end-to-end retention time does not improve: clone: "auto" copies are already copy-on-write clones, so hard-linking saves little there. The standalone benchmark's 17.3 → 4.9 min gap did not reproduce in a real update and should not be read as an update speedup. What this PR does change is that 114k dependency files are no longer duplicated on filesystems without clone support (ext4, NTFS); that disk and time effect is not measured here.

Tests

Accepted edge case

Workspace packages inside a checkout (extensions/*, packages/*) are still copied when owner-private. They are the package's own files, and the copy rule exists to protect those.

…times

Runtime retention copied every owner-private file so it could never raise
the link count of package recovery state (#187549). Under a private umask
(077) every dependency file is owner-private, so a dev checkout copied all
~218k files (17.3 min in a benchmark of a 5.6 GB tree). Dependency package
files hold no recovery state, so they are now hard-linked whatever their
mode; the package's own files and dot-named package-manager entries keep
the copy rule.

Retained runtimes were also never reclaimed on hosts running other OpenClaw
processes: any unscoped OpenClaw process counted as a holder. The creating
updater now records its pid and start time, and cleanup releases processes
that cannot be that creator (another identity, or started after the
directory existed). Processes that reference the directory stay holders.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR hard-links owner-private dependency files during updater runtime retention and logs linked/copied counts.

Example: An installation created under umask 077 contains node_modules/dep/index.js with mode 0600.

  • Before: Runtime retention copies the dependency's bytes.
  • After: Runtime retention hard-links the dependency while continuing to copy OpenClaw's private files and package-manager controls.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, focused patch with no actionable findings and meaningful filesystem evidence; complete-update coverage is not established.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; its supplied benchmark exercises prepareRetainedRuntimeFiles on a real dependency tree, while the complete-update path remains unshown.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Updates spend substantial time copying dependency trees installed with private permissions.
Reason: The collaborator-authored direction has a concrete measured workload, preserves the existing recovery contract, and keeps reclamation as separate work.

Regression provenance

Regression provenance — suspected predecessor, not a causality claim: source commit 6323eee0ba44 by Peter Steinberger; no PR verified.

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a current retention bottleneck with a focused change and no actionable correctness findings. Removing creator custody resolves the previous review blockers.

Priority: P2
Reviewed head: b1c59a958b7f898388d7d4eb8435ca19293bf26f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not demonstrate a complete update executed by the patched updater under umask 077 or a latest-stable upgrade with settings and data preserved.
Agent review details

How this fits together

Before replacing an installation, the updater inventories its running package and dependencies, materializes a private runtime, and binds imports and workers to that retained generation.

flowchart LR
  A[Running updater] --> B[Dependency inventory]
  B --> C[Retention materializer]
  C --> D[Linked dependency files]
  C --> E[Independent protected copies]
  D --> F[Retained runtime]
  E --> F
  F --> G[Updater imports and workers]
Loading

Technical review

Best possible solution:

Keep dependency eligibility in the existing retention materializer while preserving recovery, plugin-inspection, relocation, and copy-fallback safeguards.

Do we have a high-confidence way to reproduce the issue?

Current main's mode-only copy condition establishes the path for mode-0600 dependencies, supported by the author's benchmark and reported base-failing filesystem cases; this review did not execute the reproduction.

Is this the best way to solve the issue?

The narrowed patch removes unnecessary byte copying at its existing owner, preserves the original safety exceptions, and adds distinct layout regressions without new storage or cleanup machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 193053576b0a.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit a7a8c39 adds src/infra/update-retained-runtime-tree.ts:106 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a7a8c397dda7; files: src/infra/update-retained-runtime-tree.ts)
  • Vincent Koc: Raw commit 731d1c1 adds src/infra/update-retained-runtime-files.ts:66 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 731d1c178209; files: src/infra/update-retained-runtime-files.ts)
  • Jason (Json): Raw commit 5fa9dba adds src/infra/update-retained-runtime-files.ts:89 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5fa9dba02606; files: src/infra/update-retained-runtime-files.ts)

PR surface

Source +38, Tests +51, Other +2. Total +91 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 40 2 +38
Tests 1 51 0 +51
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 5 93 2 +91

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Private-umask installations perform unnecessary dependency byte copies during updates; the change has a bounded retention-performance scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • An isolated update executed by the patched updater under umask 077 would extend confidence beyond the retention benchmark.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-12T05:02:56.421Z sha 6299da5 :: blocked before merge. :: [P2] Use stable process identity instead of reconstructed epoch times | [P2] Preserve processes whose runtime custody is unknown | [P2] Store persisted creator custody through the SQLite owner
  • reviewed 2026-11-12T05:38:34.090Z sha 4784935 :: blocked before merge. :: [P2] Persist creator custody through the approved SQLite owner

Reviewed November 12, 2026, 2:00 AM ET / 07:00 UTC (Revision 3).

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in 4784935:

  • Uninspected custody is kept. The creator exemption now applies only when a process is positively classified as an unscoped holder (custody.kind === "holder" with no paths). Processes with unknown custody stay holders even when a recorded creator is elsewhere. The existing incomplete-Darwin-observation regression now also runs with a recorded creator, and it fails if the old condition is restored.
  • Recorded creators are compared clock-independently. creator.json also stores proc-safe's startTimeSinceBootMicros where the platform provides it, and reuse detection compares that field using only its resolution. A new test steps the wall clock by two minutes and keeps the live creator. If either side lacks the field, the comparison falls back to the epoch start with the existing margin.

Not changed, with reasons:

  • Legacy directories (no creator.json) still compare process start against directory birth time with a 60 s margin. A larger wall-clock step while their creating updater is still alive could release one early. That needs an NTP step of more than 60 s during an update, which is rare, and the result is visible and recoverable: that update fails and can be retried. It only applies to runtimes created before this change, and the accepted edge case is noted next to the margin constant.
  • creator.json is not a new state store. It sits inside the disposable runtime directory it describes, is written once at creation, and is removed together with that directory. Moving it into SQLite would split one fact across two owners with independent lifetimes, so cleanup would also have to reconcile orphaned rows. Keeping the fact inside the directory keeps a single owner.
  • Upgrade compatibility: no stored format changes. A directory without creator.json (every runtime created by v2026.11.3 and earlier) follows the legacy path above, and a malformed or symlinked record is ignored the same way. On a host with runtimes left by the base updater, maintenance from the previous head recognized all 18 legacy runtimes and reclaimed 5. Base code had retained every one. That run predates the stricter unknown-custody rule, which now also keeps a runtime when any process with unreadable references is alive.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
Keep this change to owner-private dependency linking and retention metrics.
Creator-based reclaim needs SQLite-owned custody and upgrade proof.

Co-authored-by: obviyus <[email protected]>
@obviyus obviyus changed the title fix(update): link private-umask dependencies and reclaim retained runtimes fix(update): hard-link owner-private dependencies during runtime retention Nov 12, 2026
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Split per review: creator-based reclaim custody (and its creator.json) is removed from this PR and will return as a follow-up with SQLite-owned custody and upgrade proof. This PR now only hard-links owner-private dependency package files during retention and logs linked/copied counts; no persisted state or cleanup behavior changes.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: a full end-to-end update on APFS under umask 077 showed no retention-time improvement (248 s base vs 271 s with this change, both under load). Clone-backed copies are already cheap there; the cost is per-entry work across ~183k entries, not bytes. Following up on that per-entry cost instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant