Repository navigation
fix(records): write front matter keys and values literally - #1138
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 12, 2026, 9:02 AM ET / 13:02 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherClawSweeper 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]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest 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 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
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. |
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 — whenany label name contains
$&,$`,$'or$$.The label apply lane stores the synced label set with
That value went into
String.prototype.replaceas a replacement string, where$&,$`and$'are expansion patterns rather than literal text. The labelnames 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 invalidJSON and pulls surrounding record content into the field.
$&expands to the matched line, so the field silently reads back the previouslabel state instead of the new one.
Downstream,
frontMatterStringArrayfalls back to comma-splitting when the valuedoes not parse, so the corrupted text becomes a plausible-looking but wrong label
list. That list is what
PROOF_OVERRIDE_LABEL,AUTOFIX_LABELand the priority andrating checks read.
Why This Change Was Made
replaceFrontMatterValuenever intended$expansion — it is a writer storing avalue verbatim — so the replacement argument is now a function, which inserts the
text literally. The same function interpolated the caller's
keystraight into aRegExpsource; that is now escaped, so keys are matched literally as thekey: stringsignature 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 thesync actually decided. Operators reading a record's
labels:field, and theoverride 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
labelsfrom published records. This change makes that field correct forthe 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 orreference.
Evidence
Change
src/clawsweeper-record-metadata.ts— importescapeRegExp; escapekeyin thetwo
frontMatterFieldregexes and inreplaceFrontMatterValue; pass thereplacement as a function in both
replacecalls.test/clawsweeper-record-metadata.test.ts— two regression tests.17changed lines in source,51added in tests.Focused tests
Reverting only
src/clawsweeper-record-metadata.tsand rebuilding turns both newtests 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:checkandpnpm run build:allall pass. The full suite is2050 / 2067with 6 failures, noneof which is caused by this change:
action-ledger-runtime.test.tstemp-dir cleanupmainautomerge-metrics.test.tsCLI JSONmainapply-runtime-budget.test.ts×210/0in isolation — contention flakecodex-process.test.ts9 pass / 1 failon unmodifiedmaintoocodex-review-runner.test.ts17 pass / 2 failonmain; this branch is18 / 1dashboard-worker.test.ts×9328/0in isolation — cascade after one timeoutNone of those files import
clawsweeper-record-metadata.Real Behavior Proof
Claim. A label whose name contains
$&,$`,$'or$$is stored inlabels:exactly as given, the record around it is unchanged, and front matter keysare matched literally rather than compiled as regular expressions.
Exercised surface.
createRecordMetadata(...).replaceFrontMatterValueand thematching readers
.frontMatterField/.frontMatterValue/.frontMatterStringArrayindist/clawsweeper-record-metadata.js— the writersrc/clawsweeper-apply-report-labels.tscalls at three sites.Scenario / fixture.
docs/proof/record-front-matter-literal-write/run-proof.mjswrites label setsthrough the shipped writer and reads them back through the shipped readers:
verbatim storage (including a mixed set
["needs-triage", "$&"]that mirrors a realsync result),
JSON.parseround-trip, record integrity (title,number, body and---delimiters unchanged), and literal key matching for keys containing. + ( [ | *.Command and environment.
local-container(runtimedocker)node:24→v24.19.0,Linux aarch64cbx_241c2987e276(swift-crab)run_b5d44f1fa51f5439582b·src/clawsweeper-record-metadata.ts· sha256df480a1e…83f10The 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, sostage-before.shwritesthe 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 failstitle survivesanddelimiters are unchanged— theexpansion 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 expressionor match the wrong line, anda.cmatches a line readingaXc:. On this branch every assertion passes. Theordinary
["bug"]case passes in both runs, and the script fails the proof ifthat 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:
Artifact / trace.
.crabbox/runs/run_b5d44f1fa51f/run_b5d44f1fa51f-artifacts.tgzcontaining.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 insrc/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.tsand two scripts; those are out ofscope 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.