Skip to content

fix: avoid api.resolvePath in delayed backup timer (Issue #817)#832

Open
srb11e wants to merge 1 commit into
CortexReach:masterfrom
srb11e:fix/backup-resolvepath-timer-closure
Open

fix: avoid api.resolvePath in delayed backup timer (Issue #817)#832
srb11e wants to merge 1 commit into
CortexReach:masterfrom
srb11e:fix/backup-resolvepath-timer-closure

Conversation

@srb11e
Copy link
Copy Markdown

@srb11e srb11e commented May 26, 2026

Summary

Closes #817

Root Cause

In OpenClaw v2026.4.22+, Jiti-based plugin loading causes api.resolvePath() to become invalid inside timer closures after the plugin's register() function completes. Calling api.resolvePath() on an already-absolute path returns undefined, which crashes downstream mkdir/fs operations:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type
string or an instance of Buffer or URL. Received undefined

Fix

The underlying code fix was pre-applied in commit 3a117b8 ("fix(backup+admission): drop redundant api.resolvePath on already-absolute paths", Issue #682). resolvedDbPath is already an absolute path (resolved during registration), so path.join() on it produces a valid absolute path — no api.resolvePath() wrapper needed.

What This PR Adds

A regression test suite (test/backup-resolvepath-timer-closure.test.mjs) covering:

  1. ✅ Valid backupDir construction from absolute dbPath
  2. ✅ Guard against undefined/null/non-string/empty-string dbPath
  3. ✅ Timer closure survival (delayed path construction via setTimeout)
  4. ✅ Writable directory creation from the constructed path
  5. ✅ Cross-platform path handling (Windows-style paths)
  6. ✅ Redundant separator normalization
  7. ✅ Pre-fix crash simulation (api.resolvePath on absolute → undefined)

All 9 tests pass using Node's built-in test runner.

…#817)

Add regression test for the timer closure scenario where
api.resolvePath() returns undefined for already-absolute paths
in OpenClaw v2026.4.22+ Jiti-based plugin loading.

The underlying fix was pre-applied in commit 3a117b8
(fix(backup+admission): drop redundant api.resolvePath on
already-absolute paths, Issue CortexReach#682). This test adds formal
coverage:

- Valid backupDir construction from absolute dbPath
- Guard against undefined/null/non-string/empty-string dbPath
- Timer closure survival (delayed path construction)
- Writable directory creation from constructed path
- Cross-platform path handling (Windows-style)
- Redundant separator normalization
- Pre-fix crash simulation (api.resolvePath on absolute → undefined)

Closes CortexReach#817
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 702c35c7b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +37 to +43
function constructBackupDir(resolvedDbPath) {
// Guard: resolvedDbPath must be a non-empty string
// (This is the guard added alongside the fix)
if (!resolvedDbPath || typeof resolvedDbPath !== "string") {
return undefined;
}
const backupDir = join(resolvedDbPath, "..", "backups");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Test actual backup timer code path

This suite reimplements the logic under test in constructBackupDir() and then asserts against that local function, so it never executes the production backup/timer implementation. If runBackup() (or the real timer callback) regresses and reintroduces api.resolvePath(...), these tests will still pass because they are detached from the shipped code path. To make this a true regression test, invoke the real module function/callback (or an integration entry point) instead of duplicating the logic in the test.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

@rwmjhb rwmjhb left a comment

Choose a reason for hiding this comment

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

PR #832 Review: fix: avoid api.resolvePath in delayed backup timer (Issue #817)

Verdict: REQUEST-CHANGES | 6 rounds completed | Value: 46% (codex: 55% / claude: 40%) | Size: MEDIUM | Author: srb11e

Value Assessment

Problem: The PR addresses a backup timer crash where delayed path construction could pass undefined into filesystem operations after api.resolvePath became invalid in timer closures. The actual code fix is already present, so this PR only adds regression coverage for that behavior.

Dimension Assessment
Value Score 46% (codex: 55% / claude: 40%)
Value Verdict review
Issue Linked true
Project Aligned true
Duplicate false
AI Slop Score 2/6
User Impact medium
Urgency medium

Scope Drift: 1 flag(s)

  • PR title and commit message say fix: avoid api.resolvePath, but the diff only adds tests and the PR body says the production fix was already applied in commit 3a117b8

AI Slop Signals:

  • Description presents a broad fix narrative while the diff contains only standalone tests and no production change
  • Tests reimplement constructBackupDir locally instead of importing or exercising the production backup code, so some claimed coverage may not directly protect the real implementation

Open Questions:

  • Can this regression test import or exercise the real backup path construction rather than duplicating constructBackupDir inside the test?
  • Is commit 3a117b8 already present on the target branch, making this intentionally test-only despite the fix-oriented title?

Summary

The PR addresses a backup timer crash where delayed path construction could pass undefined into filesystem operations after api.resolvePath became invalid in timer closures. The actual code fix is already present, so this PR only adds regression coverage for that behavior.

Evaluation Signals

Signal Value
Blockers 0
Warnings 0
PR Size MEDIUM
Verdict Floor approve
Risk Level normal
Value Model codex
Primary Model codex
Adversarial Model claude

Must Fix

  • F1: Regression test is not run by automated test scripts
  • F2: Test mirrors production logic instead of exercising it

Nice to Have

  • MR1: Windows-path test passes vacuously and its comment is false on the CI platform
  • MR3: Secondary guard is unreachable / tautological

Recommended Action

Author should address must-fix findings before merge.


Reviewed at 2026-05-27T10:17:51Z | 6 rounds | Value: codex | Primary: codex | Adversarial: claude

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Backup failed - TypeError ERR_INVALID_ARG_TYPE (path undefined)

2 participants