Skip to content

fix(records): write front matter keys and values literally - #1138

Merged
brokemac79 merged 3 commits into
openclaw:mainfrom
dwin-gharibi:fix/frontmatter-regex-escape
Aug 12, 2026
Merged

brokemac79 merged 3 commits into
openclaw:mainfrom
dwin-gharibi:fix/frontmatter-regex-escape

Conversation

@dwin-gharibi

Copy link
Copy Markdown
Contributor

Closes #1135.


What Problem This Solves

Fixes an issue where syncing labels for an item in a reviewed repository writes a
corrupted labels: field — and in some cases damages the rest of the record — when
any label name contains $&, $`, $' or $$.

The label apply lane stores the synced label set with

markdown = replaceFrontMatterValue(markdown, "labels", JSON.stringify(item.labels));

That value went into String.prototype.replace as a replacement string, where
$&, $` and $' are expansion patterns rather than literal text. The label
names come from the reviewed repository, so any repository whose labels contain
those characters produces a record that no longer says what the sync decided.

Two distinct outcomes, both observed:

  • $` and $' expand to the text before / after the match, which yields invalid
    JSON and pulls surrounding record content into the field.
  • $& expands to the matched line, so the field silently reads back the previous
    label state instead of the new one.

Downstream, frontMatterStringArray falls back to comma-splitting when the value
does not parse, so the corrupted text becomes a plausible-looking but wrong label
list. That list is what PROOF_OVERRIDE_LABEL, AUTOFIX_LABEL and the priority and
rating checks read.

Why This Change Was Made

replaceFrontMatterValue never intended $ expansion — it is a writer storing a
value verbatim — so the replacement argument is now a function, which inserts the
text literally. The same function interpolated the caller's key straight into a
RegExp source; that is now escaped, so keys are matched literally as the
key: string signature advertises. Both readers in the file (frontMatterField)
were interpolating the key the same way and are escaped alongside it.

Non-goals: the front matter format is unchanged, no key is renamed, and the label
sync logic itself is untouched — only how the chosen value is written down.

User Impact

Repositories whose labels contain $ characters now get records that match what the
sync actually decided. Operators reading a record's labels: field, and the
override and priority checks that read it back, see the real label set instead of a
mangled one.

For the overwhelming majority of repositories — whose label names contain no $ —
nothing changes; the ordinary case is byte-for-byte identical before and after.

OpenClaw Bay Impact

Bay reads labels from published records. This change makes that field correct for
the affected repositories rather than changing its shape, so no Bay change is
needed. No new field, no removed field, no status or telemetry contract change.

Documentation Lifecycle

No documentation lifecycle changes. The new file under
docs/proof/record-front-matter-literal-write/ is PR evidence, not a runbook or
reference.

Evidence

Change

  • src/clawsweeper-record-metadata.ts — import escapeRegExp; escape key in the
    two frontMatterField regexes and in replaceFrontMatterValue; pass the
    replacement as a function in both replace calls.
  • test/clawsweeper-record-metadata.test.ts — two regression tests.

17 changed lines in source, 51 added in tests.

Focused tests

$ node --test test/clawsweeper-record-metadata.test.ts
✔ front matter fields are ambiguous when the same key occurs after the leading block
✔ front matter fields preserve current-format, duplicate, and no-block behavior
✔ label names containing replacement patterns survive a front matter write
✔ front matter keys are matched literally, not as regular expressions
ℹ pass 4   ℹ fail 0

Reverting only src/clawsweeper-record-metadata.ts and rebuilding turns both new
tests red (pass 2 / fail 2) while the two pre-existing tests stay green.

Full suite and static gates

pnpm run check:static, pnpm run lint, pnpm run format:check and
pnpm run build:all all pass. The full suite is 2050 / 2067 with 6 failures, none
of which is caused by this change:

Failure Verdict
action-ledger-runtime.test.ts temp-dir cleanup fails identically on unmodified main
automerge-metrics.test.ts CLI JSON fails identically on unmodified main
apply-runtime-budget.test.ts ×2 passes 10/0 in isolation — contention flake
codex-process.test.ts 9 pass / 1 fail on unmodified main too
codex-review-runner.test.ts 17 pass / 2 fail on main; this branch is 18 / 1
dashboard-worker.test.ts ×9 passes 328/0 in isolation — cascade after one timeout

None of those files import clawsweeper-record-metadata.

Real Behavior Proof

Claim. A label whose name contains $&, $`, $' or $$ is stored in
labels: exactly as given, the record around it is unchanged, and front matter keys
are matched literally rather than compiled as regular expressions.

Exercised surface. createRecordMetadata(...).replaceFrontMatterValue and the
matching readers .frontMatterField / .frontMatterValue /
.frontMatterStringArray in dist/clawsweeper-record-metadata.js — the writer
src/clawsweeper-apply-report-labels.ts calls at three sites.

Scenario / fixture.
docs/proof/record-front-matter-literal-write/run-proof.mjs writes label sets
through the shipped writer and reads them back through the shipped readers:
verbatim storage (including a mixed set ["needs-triage", "$&"] that mirrors a real
sync result), JSON.parse round-trip, record integrity (title, number, body and
--- delimiters unchanged), and literal key matching for keys containing
. + ( [ | *.

Command and environment.

bash docs/proof/record-front-matter-literal-write/stage-before.sh
crabbox run --provider local-container --local-container-image node:24 --no-hydrate \
  --artifact-glob '.artifacts/**' -- \
  bash docs/proof/record-front-matter-literal-write/run-proof.sh
provider local-container (runtime docker)
image node:24 → v24.19.0, Linux aarch64
lease cbx_241c2987e276 (swift-crab)
run run_b5d44f1fa51f
base staged 5439582b · src/clawsweeper-record-metadata.ts · sha256 df480a1e…83f1
exit 0

The script refuses to run below Node 24, builds the Node lane, then runs the
fixtures twice — once against the module compiled from the base commit and once
against this branch. Container images carry no .git, so stage-before.sh writes
the base version of the changed file into the proof package on the host and it
rsyncs in; when git is available the script re-derives that file, so it cannot
drift from the base commit.

Observed result. Pre-fix: 17 failing assertions. Beyond the label sets, a label
named $' also fails title survives and delimiters are unchanged — the
expansion drags following record text into the field, so the write damages the
record body, not just the one value. Keys containing (, [, |, + or *
either throw SyntaxError: Invalid regular expression or match the wrong line, and
a.c matches a line reading aXc:. On this branch every assertion passes. The
ordinary ["bug"] case passes in both runs, and the script fails the proof if
that ever stops holding — which is what shows the change is confined to names
carrying a replacement pattern.

The 17 pre-fix failures inside the lease:

pre-fix exit: 1
  FAIL  labels ["$&"]          FAIL  labels ["$`"]        FAIL  labels ["$'"]
  FAIL  labels ["a$&b"]        FAIL  labels ["$$"]        FAIL  labels ["needs-triage","$&"]
  FAIL  JSON.parse round-trips ["$`"] / ["$'"] / ["$&"]
  FAIL  title survives         FAIL  delimiters are unchanged
  FAIL  key "a+b" / "x(y" / "k[0]" / "q|r" / "n*m" reads and updates in place
  FAIL  `a.c` does not match `aXc`

Artifact / trace.
.crabbox/runs/run_b5d44f1fa51f/run_b5d44f1fa51f-artifacts.tgz containing
.artifacts/record-front-matter-literal-write-proof/ — before-output.txt,
proof-output.txt, focused-tests.txt, install and build logs.

Limits. This proves the record reader and writer in
src/clawsweeper-record-metadata.ts. The same raw-interpolation shape exists in
src/repair/workflow-utils.ts, src/repair/create-job.ts,
src/repair/target-fanout.ts, src/repair/comment-router-core.ts,
src/commit-sweeper.ts, src/decision-packets.ts and two scripts; those are out of
scope here and named in the linked issue. The proof does not call GitHub — it starts
from the label set the sync returns. No shipped caller passes a key containing regex
syntax today, so the key-escaping half hardens the advertised contract rather than
fixing an observed failure; the value half is the reachable defect.

Copilot AI lite review requested due to automatic review settings August 12, 2026 11:42
@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 12, 2026
@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 12, 2026, 9:02 AM ET / 13:02 UTC.

ClawSweeper review

What this changes

The PR escapes front-matter keys and writes front-matter values through replacement callbacks so label names and keys are handled literally.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still passes synced label data as a replacement string, so dollar-pattern label names can corrupt record metadata. The submitted callback-based write is a narrow, proof-backed repair with no actionable review findings.

Priority: P2
Reviewed head: cba2193d2c9eda60a1d04b723a3953f865868388

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The patch is a focused correction with regression coverage and detailed real-behavior proof for the reachable failure mode.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The PR body records a current-head Node 24 Crabbox before/after run that exercises the compiled record writer and readers, showing 17 pre-fix failures and passing after-fix assertions.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR body records a current-head Node 24 Crabbox before/after run that exercises the compiled record writer and readers, showing 17 pre-fix failures and passing after-fix assertions.
Evidence reviewed 5 items Current main has the reachable defect: The current writer passes the assembled line directly as String.replace replacement text, allowing replacement-pattern expansion in label data.
Synced labels reach the writer: The apply lane serializes repository-controlled item labels and writes them through replaceFrontMatterValue at three label-sync paths.
Submitted repair and proof: The supplied PR patch at the current head escapes keys with the existing helper and uses replacement callbacks; its Crabbox Node 24 before/after proof reports 17 pre-fix assertion failures and all assertions passing after the change.
Findings None None.
Security None None.

How this fits together

ClawSweeper persists review reports as Markdown front matter, and the apply lane rewrites the stored label list after syncing GitHub labels. Later automation and dashboard readers consume that stored list to determine labels, priorities, and overrides.

flowchart LR
  A[GitHub label set] --> B[Apply label sync]
  B --> C[Record metadata writer]
  C --> D[Markdown front matter]
  D --> E[Record metadata readers]
  E --> F[Automation decisions]
  E --> G[Dashboard audit]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch composition production +12/-5, tests +51, proof material +435 The functional change is small and isolated; most added material documents and exercises the before/after runtime proof.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #1135
Summary: This PR is the bounded candidate fix for the linked front-matter label-corruption report.

Members:

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

Technical review

Best possible solution:

Land the surgical callback and literal-key repair with its focused regression coverage, preserving the existing front-matter format and label-sync behavior.

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

Yes: current main sends JSON-serialized repository labels into replacement-string position, so a label containing $&, $', $`` or $$` has a direct source path to corruption; the PR also supplies a recorded before/after container run.

Is this the best way to solve the issue?

Yes: a replacement callback is the narrowest way to insert record data literally, and reusing the existing regular-expression escaping helper keeps the advertised key contract literal without changing the format.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded record-integrity bug that can misrepresent synced labels and affect later automation decisions.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body records a current-head Node 24 Crabbox before/after run that exercises the compiled record writer and readers, showing 17 pre-fix failures and passing after-fix assertions.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records a current-head Node 24 Crabbox before/after run that exercises the compiled record writer and readers, showing 17 pre-fix failures and passing after-fix assertions.

Evidence

What I checked:

  • Current main has the reachable defect: The current writer passes the assembled line directly as String.replace replacement text, allowing replacement-pattern expansion in label data. (src/clawsweeper-record-metadata.ts:262, ac340908bf69)
  • Synced labels reach the writer: The apply lane serializes repository-controlled item labels and writes them through replaceFrontMatterValue at three label-sync paths. (src/clawsweeper-apply-report-labels.ts:153, ac340908bf69)
  • Submitted repair and proof: The supplied PR patch at the current head escapes keys with the existing helper and uses replacement callbacks; its Crabbox Node 24 before/after proof reports 17 pre-fix assertion failures and all assertions passing after the change. (src/clawsweeper-record-metadata.ts:75, cba2193d2c9e)
  • Feature provenance: Blame attributes the vulnerable reader and writer lines to the commit that introduced this record-metadata surface. (src/clawsweeper-record-metadata.ts:261, dc6fc0b4a479)
  • Release and current-main provenance: The record-metadata file was introduced after v0.3.0, and current main still contains the vulnerable implementation; this PR therefore addresses an active main-only surface rather than an already released fix. (src/clawsweeper-record-metadata.ts:259, dc6fc0b4a479)

Likely related people:

  • steipete: Current-main blame and file history attribute the record metadata reader and writer to the commit that introduced this surface. (role: feature introducer; confidence: high; commits: dc6fc0b4a479; files: src/clawsweeper-record-metadata.ts)

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-12T11:44:58.938Z sha 72eff79 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-12T12:18:43.336Z sha 57a5d2a :: needs maintainer review before merge. :: none

@dwin-gharibi

Copy link
Copy Markdown
Contributor Author

@steipete

@brokemac79
brokemac79 merged commit 04cd809 into openclaw:main Aug 12, 2026
9 checks passed
@brokemac79

Copy link
Copy Markdown
Contributor

Thanks @dwin-gharibi — merged as 04cd809. This ensures dollar-pattern label names are stored literally without corrupting review records. Appreciate the contribution and validation work.

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

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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.

A GitHub label containing $& corrupts the record it is written to

3 participants