clawsweeper icon indicating copy to clipboard operation
clawsweeper copied to clipboard

apply: default report path fails action-ledger validation, aborting every ledger-enabled apply-decisions run before results are published

Open yetval opened this issue 4 months ago • 1 comments

Summary

apply-decisions defaults --report-path to the repository-root apply-report.json. When the action ledger is enabled, finishApply records that path as subject.recordPath, the ledger path contract rejects any path outside its allowed namespaces, and the command throws after the apply pass has already run. The three sweep.yml invocations that mutate GitHub do not pass --report-path, so every ledger-enabled apply run aborts before its report is copied, merged, cursor-advanced or published.

Environment

  • Commit: 6284161cdcd27e447ec5478c98327c5325460e43 (origin/main at time of filing)
  • Surface: apply-decisions command, action ledger, sweep.yml apply lanes

Steps to reproduce

  1. Check out origin/main at the commit above and build.
  2. Run apply-decisions with the action ledger enabled and no --report-path: node dist/clawsweeper.js apply-decisions -- --target-repo openclaw/clawhub --skip-dashboard --limit 1 --dry-run
  3. Run the identical command again with a namespaced report path: ... --report-path artifacts/apply/apply-report.json

Expected

Both runs complete and emit the apply summary. The report path should not decide whether the command can finish.

Actual

Run 2 exits 0 and prints the apply summary. Run 1 exits 1 with action event subject record path must be a namespaced repository-relative data path using portable segments, thrown from finishApply after the apply pass.

Root cause

reportPath defaults to a repository-root filename:

// src/clawsweeper.ts:27365
const reportPath = resolve(stringArg(args.report_path, join(ROOT, "apply-report.json")));

finishApply then records it as the ledger subject, guarding only against paths that escape the repository:

// src/clawsweeper.ts:27255-27260
    subject: {
      repository: targetRepo(),
      kind: "publication",
      ...(repoRelativePath(options.reportPath).startsWith("../")
        ? {}
        : { recordPath: repoRelativePath(options.reportPath) }),
    },

The contract requires a namespaced first segment plus at least one more segment, so a repository-root filename can never match:

// src/action-ledger.ts:379-380
export const ACTION_EVENT_RELATIVE_DATA_PATH_PATTERN_SOURCE =
  "^(?:\\.artifacts|artifacts|jobs|ledger|logs|notifications|records|results)(?:/(?!(?:[Cc][Oo][Nn]|...))[A-Za-z0-9_](?:[A-Za-z0-9._+@\\-]{0,253}[A-Za-z0-9_+@\\-])?)+$";

A path inside the repository but outside the allowed namespaces passes the ../ guard and then fails the pattern.

The apply-proof lane already passes a valid path (sweep.yml:4269, --report-path .artifacts/apply-proof/apply-report.json) and the retry lane passes artifacts/... (sweep.yml:3868). The three invocations that were never namespaced are sweep.yml:3505, sweep.yml:4701 and sweep.yml:4761.

Ordering matters here. The throw happens in finishApply, after the apply pass, and set -euo pipefail then aborts the step before cp apply-report.json, merge-apply-reports, write-apply-cursor and publish_changes. Any close performed in that pass is therefore not recorded, the cursor does not advance, and the following run re-selects the same window.

Prior art

PR #537 "fix(ledger): namespace apply decision reports" (opened 2026-07-13T15:30Z, closed unmerged 38 minutes later) diagnosed this same defect and cited upstream run 29254106392. The diagnosis was correct and the defect is still live 11 days later, so I am filing it as an issue with current-main proof rather than reopening that PR.

Sibling surfaces

proof-nudges and bot-proof also default to repository-root report paths (src/clawsweeper.ts:30786, :30969) but do not route through recordApplyActionEvents, so they do not hit this validator. No failures observed on those lanes.

Real behavior proof

Behavior addressed: ledger-enabled apply-decisions aborts after the apply pass because the default report path is not a namespaced ledger record path. Real environment tested: real compiled CLI driven at commit 6284161cdcd27e447ec5478c98327c5325460e43, plus production run logs from openclaw/clawsweeper. Exact steps or command run after this patch: node dist/clawsweeper.js apply-decisions -- --target-repo openclaw/clawhub --skip-dashboard --limit 1 --dry-run, then the same command with --report-path artifacts/apply/apply-report.json. Evidence after fix:

# OBSERVED in production, run 30115556638, step "Apply unchanged proposed decisions with checkpoints"
2026-07-24T19:05:45.7287706Z [apply] 2026-07-24T19:05:45.727Z starting apply: files=1 dry_run=false apply_kind=all min_age=0 days apply_close_reasons=all stale_min_age_days=60 close_delay_ms=2000 sync_comments_only=false suppress_automation_markers=false comment_sync_min_age_days=7 max_runtime_ms=600000 item_numbers=1767 closed=0/1 processed=0/300 counts={}
2026-07-24T19:05:55.5720564Z [action-ledger] failed to finalize partial apply events: action event subject record path must be a namespaced repository-relative data path using portable segments
2026-07-24T19:05:55.7875358Z Error: action event subject record path must be a namespaced repository-relative data path using portable segments

# OBSERVED locally, origin/main 6284161cdc, default report path
$ node dist/clawsweeper.js apply-decisions -- --target-repo openclaw/clawhub --skip-dashboard --limit 1 --dry-run
No items directory.
[action-ledger] failed to finalize partial apply events: action event subject record path must be a namespaced repository-relative data path using portable segments
[action-ledger] finalized 1 immutable workflow shard
Error: action event subject record path must be a namespaced repository-relative data path using portable segments
EXIT=1

# EXPECTED, identical inputs, only --report-path added
$ node dist/clawsweeper.js apply-decisions -- --target-repo openclaw/clawhub --skip-dashboard --limit 1 --dry-run --report-path artifacts/apply/apply-report.json
No items directory.
[apply] 2026-07-24T19:35:22.509Z finished apply closed=0/1 processed=0/50 counts={}
[]
[action-ledger] finalized 1 immutable workflow shard
EXIT=0

Observed result after fix: the command fails or succeeds purely as a function of the default report path, and on the failing path the run aborts before the apply report and cursor are published. What was not tested: I did not observe a run in which an item was closed on GitHub and the record was then lost, so the close-before-record ordering is demonstrated from control flow and step ordering rather than from a captured lost close. I did not exercise the non-dry-run mutation path against a live target. I did not measure how many candidate items have accumulated across the outage.

Additional context

Across the last 600 ClawSweeper workflow runs there are 21 Apply default ClawSweeper closures runs: 11 cancelled, 6 failure, 4 still in flight, and 0 successful. The live sweep status file still reports last_close_apply_health.generated_at of 2026-07-12T23:11:18.296Z, roughly 28 minutes after a8740004c0 feat(ledger): instrument review and apply actions landed at 2026-07-12T22:43Z. openclaw/clawhub#1767 was selected for close at 16:48, 17:23, 18:05, 18:42 and 19:05 today and remains open.

Some runs in that set fail earlier, at the state writer coordinator, before reaching finishApply. Those are a separate contention problem and I am not conflating them with this one; runs 30115556638 and 30112779460 reach the apply pass and then fail with the signature above.

yetval avatar Jul 24 '26 19:07 yetval

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 24, 2026, 3:42 PM ET / 19:42 UTC.

Summary This is a current, reproducible P1 apply-lane bug: the ledger can reject the default report path after an apply pass, preventing report publication and cursor advancement. The earlier matching fix proposal at https://github.com/openclaw/clawsweeper/pull/537 was closed unmerged, so this issue remains the canonical repair target.

Reproducibility: yes. The issue supplies a concrete current-main compiled-CLI comparison with identical inputs except for --report-path, plus matching production workflow output; the default path fails during ledger finalization and a namespaced path succeeds.

Root-cause cluster Relationship: canonical Canonical: https://github.com/openclaw/clawsweeper/issues/833 Summary: This issue is the active canonical report for the default apply-report path and ledger-validation mismatch; the only directly related repair PR was closed unmerged.

Members:

  • fixed_by_candidate: https://github.com/openclaw/clawsweeper/pull/537 - It proposed the same namespaced report-path repair but was closed unmerged, so it cannot replace this open issue as the active fix target.

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Next step A focused repair can make the default report path ledger-valid, preserve existing report publication behavior, and add regression coverage without a product or security decision.

Review details

Best possible solution:

Make the command’s default ledger-valid and update report consumers or compatibility projections so both direct CLI callers and all mutating sweep lanes complete, publish results, and advance the cursor without weakening ledger validation.

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

Yes. The issue supplies a concrete current-main compiled-CLI comparison with identical inputs except for --report-path, plus matching production workflow output; the default path fails during ledger finalization and a namespaced path succeeds.

Is this the best way to solve the issue?

No, a workflow-only repair is not the best complete solution because direct CLI callers retain the invalid default. The narrow durable repair is to make the default ledger-valid while preserving any required legacy report projection and adding focused regression coverage.

AGENTS.md: found and applied where relevant.

Remaining risk / open question:

  • Changing the default report path without preserving consumers that expect a root apply-report.json could break report copying or external scripts; the repair should keep any required legacy projection while recording a ledger-valid path.
  • Workflow-only fixes would leave direct ledger-enabled apply-decisions callers vulnerable to the same invalid default path.

Codex review notes: model internal, reasoning high; reviewed against 6284161cdcd2.

Label changes

Label changes:

  • add P1: The defect blocks the repository’s ledger-enabled apply workflow after it begins processing decisions, leaving closure publication and cursor advancement unavailable.
  • add impact:other: This is a concrete automation-state and workflow-publication failure, but it does not fit the more specific data-loss, message, session, auth, or crash-loop labels.
  • add issue-rating: 🦀 challenger crab: Current issue advisory state selects this label.
  • add clawsweeper:current-main-repro: Current issue advisory state selects this label.
  • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
  • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

Label justifications:

  • P1: The defect blocks the repository’s ledger-enabled apply workflow after it begins processing decisions, leaving closure publication and cursor advancement unavailable.
  • impact:other: This is a concrete automation-state and workflow-publication failure, but it does not fit the more specific data-loss, message, session, auth, or crash-loop labels.
Evidence reviewed

Acceptance criteria:

  • Run the focused apply and action-ledger regression tests added or updated for default and namespaced report paths.
  • Verify every ledger-enabled apply-decisions invocation in .github/workflows/sweep.yml either uses a valid path or safely consumes the repaired default.
  • Run pnpm run check on Node 24 or newer before handoff.

What I checked:

  • Current-main source path: The report identifies the current-main default in apply-decisions as a repository-root apply-report.json, while finishApply forwards an in-repository path into the ledger subject. That allows the root filename past the traversal guard but not past the ledger namespace contract. (src/clawsweeper.ts:27365, 6284161cdcd2)
  • Ledger contract: The reported ledger contract accepts repository-relative data paths only under named namespaces such as .artifacts, artifacts, jobs, ledger, logs, notifications, records, or results; a root apply-report.json cannot satisfy it. (src/action-ledger.ts:379, 6284161cdcd2)
  • Current behavior proof: The issue includes a current-main compiled-CLI reproduction: the default-path dry run exits 1 during ledger finalization, while the otherwise identical run using artifacts/apply/apply-report.json exits 0 and emits the apply summary. It also includes production output from run 30115556638 with the same failure after apply starts. (src/clawsweeper.ts:27255, 6284161cdcd2)
  • Workflow exposure: The report identifies three GitHub-mutating sweep invocations that omit --report-path, whereas other apply lanes already use namespaced artifact paths. The failure occurs before the workflow copies reports, merges them, advances the cursor, or publishes changes. (.github/workflows/sweep.yml:3505, 6284161cdcd2)
  • Related prior implementation: https://github.com/openclaw/clawsweeper/pull/537 proposed the same diagnosis and a two-file repair, but it was closed unmerged on July 13, 2026; it is useful provenance rather than a landing path. (.github/workflows/sweep.yml:3868, 8a4861f6c64c)

Likely related people:

  • ptbyrne: Authored the focused prior repair for this exact report-path and ledger-contract mismatch; the branch is closed unmerged but remains the closest implementation history. (role: prior repair proposer; confidence: medium; commits: 8a4861f6c64c; files: src/clawsweeper.ts, .github/workflows/sweep.yml)
  • yetval: Provided the current-main CLI comparison and production-run evidence that isolate the default-path failure and distinguish it from separate state-writer contention. (role: current reproduction reporter; confidence: high; files: src/clawsweeper.ts, src/action-ledger.ts, .github/workflows/sweep.yml)
How this review workflow works
  • 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.

clawsweeper[bot] avatar Jul 24 '26 19:07 clawsweeper[bot]