Skip to content

fix(paths): preserve identity across realpath failures - #130516

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/existing-ancestor-path-resolution
Aug 27, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/existing-ancestor-path-resolution

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where agent-directory ownership and Gateway state locks could treat one aliased path as separate identities when native realpath failed below an existing canonical ancestor.

Why This Change Was Made

The two identity owners now share resolveIdentityPathViaExistingAncestorSync, which preserves their historical contract: use native realpath, continue climbing after any failure, rebuild the missing suffix after a canonical ancestor resolves, and fall back lexically only after the filesystem root fails. The ordinary fs-safe existing-ancestor helper remains unchanged for all other callers.

User Impact

Agent cleanup fencing and Gateway or maintenance locking continue to converge on one identity through symlink or junction aliases, including missing descendants and intermediate realpath failures.

Evidence

  • Repaired source head: 2f47db1fb1e09c116cd0cb2794344d7ba3f2d192
  • Pre-fix regression: the new boundary contract returned the lexical alias and made zero native realpath calls (2 failed, 5 passed).
  • Focused native review: 14/14 across src/infra/boundary-path.test.ts, src/agents/agent-dir-registry.test.ts, and src/infra/gateway-lock.state-dir.test.ts.
  • Changed-file format, typecheck, lint, architecture, and repository guards passed.
  • Fresh structured autoreview reported no findings.
  • Production LOC: +26/-41 (net -15); tests: +114/-3.
  • Current main has zero touched-file drift; merge tree is clean, so no rebase is warranted.

Linux Testbox

  • Blacksmith lease: tbx_01m10ypqw4xkfw0xfnwbpqzj97
  • Actions: https://github.com/openclaw/openclaw/actions/runs/33046223365
  • SHA proof: expected/local/live/fetched/remote all 2f47db1fb1e09c116cd0cb2794344d7ba3f2d192; remote-fetch sync confirmed.
  • Command: node scripts/run-vitest.mjs src/infra/boundary-path.test.ts src/agents/agent-dir-registry.test.ts src/infra/gateway-lock.state-dir.test.ts
  • Result: 3 files, 14 tests, exitCode: 0, runStatus: succeeded.
  • Receipt: {"provider":"blacksmith-testbox","leaseId":"tbx_01m10ypqw4xkfw0xfnwbpqzj97","exitCode":0,"runStatus":"succeeded","label":"pr-130516-linux-exact"}

The delegated command succeeded before Blacksmith stopped the one-shot lease. The backing Actions step may show cancellation during provider-owned teardown; the preserved Crabbox timing receipt is successful.

Native Windows Crabbox

  • Provider: Azure native Windows, lease cbx_216932440bdc
  • Run: https://crabbox.openclaw.ai/portal/runs/run_0a81329f1411
  • SHA proof: expected/local/live/fetched/remote all 2f47db1fb1e09c116cd0cb2794344d7ba3f2d192; remote-fetch sync confirmed.
  • Setup: official Node v24.20.0 archive verified against Node's published SHA-256; repository-pinned pnpm 11.22.0.
  • Command: node scripts/run-vitest.mjs src/infra/boundary-path.test.ts src/agents/agent-dir-registry.test.ts src/infra/gateway-lock.state-dir.test.ts
  • Result: 3 files, 14 tests, exitCode: 0, runStatus: succeeded.
  • Receipt: {"provider":"azure","leaseId":"cbx_216932440bdc","runId":"run_0a81329f1411","machineType":"Standard_D4ads_v6","exitCode":0,"runStatus":"succeeded","leaseStopped":true}

Final Review

  • Hosted CI at the repaired head: 153 successful, 53 skipped, 1 neutral, zero failed or pending checks.
  • ClawSweeper exact-head review: fix(paths): preserve identity across realpath failures #130516 (comment)
  • Finding disposition: the compatibility-sensitive Windows junction and symlinked-state proof gap is resolved by the Linux and native-Windows receipts above.
  • Rank-up disposition: published redacted exact-head output for both platforms, including the existing agent junction and Gateway missing-leaf-under-symlink scenarios.
  • Owner decision: accept the focused, behavior-preserving identity helper after direct @openclaw/fs-safe 0.5.6 inspection and cross-platform proof.

@vincentkoc vincentkoc self-assigned this Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 27, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 27, 2026 00:09
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 3:22 AM ET / 07:22 UTC.

ClawSweeper review

What this changes

The branch extracts native-realpath ancestor walking into a shared helper used by agent-directory ownership and Gateway state locking, with tests for failed descendants and symlink or junction aliases.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for human maintainer review. Current main already preserves the stated alias-convergence behavior in two duplicated implementations, so this exact head is a behavior-preserving deduplication and regression-test strengthening rather than a needed production bug fix; the member-authored, maintainer-labeled PR must not be auto-closed.

Priority: P3
Reviewed head: 2f47db1fb1e09c116cd0cb2794344d7ba3f2d192
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The implementation is a focused, net-negative refactor with meaningful regression coverage; cross-platform exact-head results would improve merge confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored internal refactor is outside the external-contributor proof gate; the PR body reports focused test results, but no live artifact was required for this classification.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored internal refactor is outside the external-contributor proof gate; the PR body reports focused test results, but no live artifact was required for this classification.
Evidence reviewed 6 items Current-main agent behavior: Current main already walks from a missing path toward the root, retries native realpath at each ancestor, and rebuilds the suffix after success.
Current-main Gateway behavior: Current main's Gateway state-directory canonicalizer has the same climb-and-rebuild behavior, including continuing after intermediate realpath failures.
Shared refactor on PR head: The PR moves that identity-specific algorithm into one helper and both consumers delegate to it.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/infra/boundary-path.test.ts src/agents/agent-dir-registry.test.ts src/infra/gateway-lock.state-dir.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.boundary.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130516-F25mwW/target

 ✓  boundary  src/infra/boundary-path.test.ts (7 tests) 47ms

 Test Files  1 passed (1)
      Tests  7 passed (7)
   Start at  07:23:06
   Duration  508ms (transform 229ms, setup 59ms, import 58ms, tests 47ms, environment 0ms)

[test] starting test/vitest/vitest.infra.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130516-F25mwW/target

 ✓  infra  src/infra/gateway-lock.state-dir.test.ts (3 tests) 128ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  07:23:07
   Duration  1.55s (transform 1.16s, setup 1.15s, import 163ms, tests 128ms, environment 0ms)

[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130516-F25mwW/target

Assertions:

  • PASS expect_output: Test Files

How this fits together

Configured agent and state-directory paths become canonical filesystem identities before ownership checks and Gateway lock paths are calculated. Both consumers must resolve an existing canonical ancestor and then rebuild any missing descendant path.

flowchart LR
  A[Configured directory path] --> B[Expand and make absolute]
  B --> C[Walk toward existing ancestor]
  C --> D[Canonical identity path]
  D --> E[Agent ownership registry]
  D --> F[Gateway state locks]
Loading

Decision needed

Question Recommendation
Should this behavior-preserving deduplication and its focused regression coverage be merged when current main already delivers the reported filesystem behavior? Merge the canonical refactor: Keep the shared helper because it removes duplicated identity logic and makes future behavioral drift less likely.

Why: The correctness need is already satisfied on main; choosing whether the reduced duplication is worth an additional internal helper is a maintainer scope decision.

Before merge

  • Resolve merge risk (P1) - Path identity remains compatibility-sensitive across Windows junctions and symlinked state directories; the PR body says exact-head Windows proof will be recorded, but no reviewer-visible artifact was available in this context.
Agent review details

Security

None.

PR surface

Source -15, Tests +111. Total +96 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 26 41 -15
Tests 3 114 3 +111
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 140 44 +96

Review metrics

Metric Value Why it matters
Production versus test LOC production +26/-41 (net -15); tests +114/-3 The patch removes two duplicated implementations while adding focused boundary and consumer coverage.

Merge-risk options

Maintainer options:

  1. Record cross-platform identity proof (recommended)
    Before merge, publish redacted exact-head focused results including the Windows junction scenario because state-lock identity affects existing installations.
  2. Close the optional refactor
    Close this PR if maintainers do not want a behavior-preserving shared helper now that current main already has the required semantics.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Run the focused path-identity checks on the exact head, including a Windows junction scenario, and publish redacted results.

Technical review

Best possible solution:

Merge only if maintainers want the canonical shared helper and its regression coverage; otherwise close this behavior-preserving refactor while retaining the already-correct current-main implementations.

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

No current-main bug reproduction is supported: both current-main consumers already continue native-realpath attempts through ancestors and rebuild the missing suffix. The PR's new test guards against a transient branch regression rather than a current-main failure.

Is this the best way to solve the issue?

No as a production bug fix, because current main already implements the claimed behavior. As a cleanup, the shared helper is a clean way to prevent the two copies from drifting if maintainers choose to retain the refactor.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5f3324587e40.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P3: This is optional internal cleanup around behavior that current main already provides, with no demonstrated active outage.
  • merge-risk: 🚨 compatibility: Changing canonical state and agent-directory identities can affect existing symlink or junction lock and ownership behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored internal refactor is outside the external-contributor proof gate; the PR body reports focused test results, but no live artifact was required for this classification.

Evidence

What I checked:

  • Current-main agent behavior: Current main already walks from a missing path toward the root, retries native realpath at each ancestor, and rebuilds the suffix after success. (src/agents/agent-dir-registry.ts:16, 5f3324587e40)
  • Current-main Gateway behavior: Current main's Gateway state-directory canonicalizer has the same climb-and-rebuild behavior, including continuing after intermediate realpath failures. (src/infra/gateway-lock.ts:297, 5f3324587e40)
  • Shared refactor on PR head: The PR moves that identity-specific algorithm into one helper and both consumers delegate to it. (src/infra/boundary-path.ts:13, 2f47db1fb1e0)
  • Boundary coverage: The PR adds an injected intermediate-realpath-failure contract test and real symlink or junction coverage through the Gateway lock owner; existing registry coverage exercises a removed agent directory below a symlinked parent. (src/infra/boundary-path.test.ts:20, 2f47db1fb1e0)
  • Current behavior provenance: Blame attributes both current-main duplicated identity routines to the same agent-path change, establishing the shared-owner refactor target. (src/agents/agent-dir-registry.ts:16, 4a2b910ec064)
  • Release check: The open PR head is not contained by any locally available release tag, so it has not been shipped and cannot be treated as an implemented-on-main closure. (2f47db1fb1e0)

Likely related people:

  • SunnyShu: Current-main blame attributes both duplicated identity implementations to this change. (role: introduced current behavior; confidence: high; commits: 4a2b910ec064; files: src/agents/agent-dir-registry.ts, src/infra/gateway-lock.ts)
  • Peter Steinberger: Available history shows recent Gateway lock-path and filesystem-realpath refactors adjacent to the shared helper boundary. (role: recent adjacent infrastructure contributor; confidence: medium; commits: 70abd88e03e0, eecbfcc96076; files: src/infra/gateway-lock.ts, src/infra/boundary-path.ts)

Rank-up moves

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

  • Publish redacted exact-head Linux and Windows focused-test output, including the junction case.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-27T00:16:18.963Z sha 0ea9967 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T06:39:18.106Z sha 2f47db1 :: needs maintainer review before merge. :: none

@vincentkoc vincentkoc changed the title refactor(paths): reuse existing ancestor resolution fix(paths): preserve identity across realpath failures Aug 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Exact repaired head: 2f47db1fb1e09c116cd0cb2794344d7ba3f2d192.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 27, 2026
@vincentkoc
vincentkoc merged commit 82167b0 into main Aug 27, 2026
213 checks passed
@vincentkoc
vincentkoc deleted the refactor/existing-ancestor-path-resolution branch August 27, 2026 07:59
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
* refactor(paths): reuse existing ancestor resolution

* fix(paths): preserve identity canonicalization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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