Skip to content

Commit 89e4344

Browse files
committed
fix(review): tighten persistent data-model detection
1 parent 3637a94 commit 89e4344

2 files changed

Lines changed: 160 additions & 15 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13768,7 +13768,10 @@ function dataModelChangeFromContext(repo: string, context: ItemContext): DataMod
1376813768
const previousPath =
1376913769
typeof file.previous_filename === "string" ? file.previous_filename.trim() : "";
1377013770
const candidates = [path, previousPath].filter(Boolean);
13771-
const likelyPath = candidates.find(isLikelyOpenClawDataModelPath) ?? "";
13771+
const productionCandidates = candidates.filter(
13772+
(candidate) => !isOpenClawDataModelTestPath(candidate),
13773+
);
13774+
const likelyPath = productionCandidates.find(isLikelyOpenClawDataModelPath) ?? "";
1377213775
const patch = typeof file.patch === "string" ? file.patch : null;
1377313776
const lines = patch === null ? [] : changedPatchLines(patch);
1377413777

@@ -13779,7 +13782,7 @@ function dataModelChangeFromContext(repo: string, context: ItemContext): DataMod
1377913782
surfaces.add(dataModelSurfaceLabel(likelyPath, "unknown-data-model-change"));
1378013783
}
1378113784

13782-
for (const candidate of candidates) {
13785+
for (const candidate of productionCandidates) {
1378313786
if (isDocsPath(candidate)) {
1378413787
if (patch !== null && !configSurfacePatchIsTruncated(patch)) {
1378513788
dataModelSurfacesFromPatch(candidate, lines, { docsOnly: true }).forEach((surface) =>
@@ -14024,7 +14027,7 @@ function dataModelSurfacesFromPatch(
1402414027
) {
1402514028
add("database schema");
1402614029
}
14027-
if (/\b(?:migration|migrate|upgrade|backfill|doctor|repair|reindex|rehydrat\w*)\b/i.test(text)) {
14030+
if (/\b(?:migrations?|migrat(?:e|ed|es|ing)|backfill\w*)\b/i.test(text)) {
1402814031
add("migration/backfill/repair");
1402914032
}
1403014033
if (
@@ -14034,22 +14037,26 @@ function dataModelSurfacesFromPatch(
1403414037
) {
1403514038
add("durable storage schema");
1403614039
}
14037-
if (
14038-
/\b(?:JSON\.(?:parse|stringify)|readFile|writeFile|localStorage|sessionStorage|workspaceState|globalState|serialized|persisted?|statePath)\b/i.test(
14039-
text,
14040-
)
14041-
) {
14040+
const hasExplicitSerializedState =
14041+
/\b(?:localStorage|sessionStorage|workspaceState|globalState|statePath)\b/i.test(text);
14042+
const hasJsonFilePersistence = lines.some((_, index) => {
14043+
const operation = lines.slice(Math.max(0, index - 2), index + 3).join("\n");
14044+
return (
14045+
/\b(?:readFile|writeFile)\w*\b/i.test(operation) &&
14046+
/\bJSON\.(?:parse|stringify)\b/i.test(operation) &&
14047+
/\b(?:state|checkpoint|snapshot|cache|store|storage|record|session|history|queue|registry|cursor|profile|credential|memory|database|db)(?:[ _-]?(?:path|file|dir(?:ectory)?)){0,2}\b/i.test(
14048+
operation,
14049+
)
14050+
);
14051+
});
14052+
if (hasExplicitSerializedState || hasJsonFilePersistence) {
1404214053
add("serialized state");
1404314054
}
14044-
if (
14045-
/\b(?:cache(?:Key|Version|Schema|Namespace)?|cache[_-]?(?:key|version|schema|namespace)|ttl)\b/i.test(
14046-
text,
14047-
)
14048-
) {
14055+
if (/\bcache[ _-]?(?:key|version|schema|namespace|ttl)\b/i.test(text)) {
1404914056
add("persistent cache schema");
1405014057
}
1405114058
if (
14052-
/\b(?:embedding|vector|collection|dimension|metadata|row[_-]?id|document[_-]?id|chunk[_-]?id|similarity[_-]?index)\b/i.test(
14059+
/\b(?:embedding[ _-]?dimension|vector[ _-]?dimension|collection[ _-]?name|row[ _-]?id|document[ _-]?id|chunk[ _-]?id|similarity[ _-]?index)\b/i.test(
1405314060
text,
1405414061
)
1405514062
) {
@@ -14072,6 +14079,14 @@ function isLikelyOpenClawDataModelPath(path: string): boolean {
1407214079
return Boolean(dataModelPathHint(path)) || /\.(?:sql|sqlite|db|prisma)$/.test(path);
1407314080
}
1407414081

14082+
function isOpenClawDataModelTestPath(path: string): boolean {
14083+
return (
14084+
/(^|\/)(?:__tests__|test|tests|fixtures|__snapshots__)(?:\/|$)/i.test(path) ||
14085+
/\.(?:test|spec)\.[cm]?[jt]sx?$/i.test(path) ||
14086+
/\.snap$/i.test(path)
14087+
);
14088+
}
14089+
1407514090
function dataModelPathHint(path: string): string {
1407614091
if (
1407714092
/(^|\/)(?:durable-?objects?|workers?|storage)(?:\/|[-_.])|durable-?object|state-storage/i.test(
@@ -14098,7 +14113,7 @@ function dataModelPathHint(path: string): string {
1409814113
return "vector/embedding metadata";
1409914114
}
1410014115
if (
14101-
/(^|\/)(?:migrations?|backfill|doctor|repair|upgrade)(?:\/|[-_.])|(?:migration|backfill|doctor|repair|upgrade)\.(?:ts|js)$/i.test(
14116+
/(^|\/)(?:migrations?|backfill|doctor|repair|upgrade)(?:\/|[-_.])|(^|\/)(?:migration|backfill|doctor|repair|upgrade)\.(?:ts|js)$/i.test(
1410214117
path,
1410314118
)
1410414119
) {

‎test/pr-surface-policy.test.ts‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,136 @@ test("data model detector ignores query-only and non-semantic docs changes", ()
294294
assert.deepEqual(detection, { change: false, surfaces: [] });
295295
});
296296

297+
test("data model detector ignores runtime repair, telemetry, and test vocabulary", () => {
298+
const detection = dataModelChangeFromPullFilesForTest({
299+
pullFiles: [
300+
{
301+
filename: "src/agents/embedded-agent-runner/run/code-mode-tool-call-repair.ts",
302+
patch: "@@\n+ return repairSmallModelToolCall(payload);",
303+
},
304+
{
305+
filename: "src/agents/tool-search-runtime.ts",
306+
patch: "@@\n+ const repaired = repairToolResult(result);",
307+
},
308+
{
309+
filename: "src/agents/tool-search-telemetry.ts",
310+
patch: "@@\n+ metadata: toolMetadata,\n+ cacheRead: usage.cacheRead,",
311+
},
312+
{
313+
filename: "src/agents/code-mode-tool-input-repair.ts",
314+
patch: "@@\n+ return JSON.parse(candidate);",
315+
},
316+
{
317+
filename: "extensions/qa-lab/src/code-mode-model-matrix.options.test.ts",
318+
patch: "@@\n+ it('preserves cache fields', () => JSON.stringify(result));",
319+
},
320+
],
321+
});
322+
323+
assert.deepEqual(detection, { change: false, surfaces: [] });
324+
});
325+
326+
test("data model detector keeps explicit repair and persistence surfaces", () => {
327+
const detection = dataModelChangeFromPullFilesForTest({
328+
pullFiles: [
329+
{
330+
filename: "src/doctor/repair.ts",
331+
patch: "@@\n+ await repair(database);",
332+
},
333+
{
334+
filename: "src/cache/schema.ts",
335+
patch: "@@\n+ entryFingerprint: string;",
336+
},
337+
{
338+
filename: "src/runtime/checkpoint.ts",
339+
patch:
340+
"@@\n+ const raw = await readFile(checkpointPath, 'utf8');\n+ return JSON.parse(raw);",
341+
},
342+
{
343+
filename: "scripts/config-fixture.ts",
344+
patch:
345+
"@@\n+ await writeFile(configPath, JSON.stringify(config));\n+ return readFile(resultPath, 'utf8');",
346+
},
347+
],
348+
});
349+
350+
assert.deepEqual(detection, {
351+
change: true,
352+
surfaces: [
353+
"migration/backfill/repair: src/doctor/repair.ts",
354+
"persistent cache schema: src/cache/schema.ts",
355+
"serialized state: src/runtime/checkpoint.ts",
356+
],
357+
});
358+
});
359+
360+
test("data model detector keeps production snapshot schemas", () => {
361+
const detection = dataModelChangeFromPullFilesForTest({
362+
pullFiles: [
363+
{
364+
filename: "src/storage/snapshots/schema.sql",
365+
patch: "@@\n+ALTER TABLE snapshots ADD COLUMN format_version INTEGER;",
366+
},
367+
],
368+
});
369+
370+
assert.deepEqual(detection, {
371+
change: true,
372+
surfaces: ["database schema: src/storage/snapshots/schema.sql"],
373+
});
374+
});
375+
376+
test("data model detector recognizes semantic prose forms", () => {
377+
const detection = dataModelChangeFromPullFilesForTest({
378+
pullFiles: [
379+
{
380+
filename: "docs/storage.md",
381+
patch:
382+
"@@\n+The cache version changes when persisted entries become incompatible.\n+The embedding dimension remains part of stored vector metadata.",
383+
},
384+
],
385+
});
386+
387+
assert.deepEqual(detection, {
388+
change: true,
389+
surfaces: [
390+
"persistent cache schema: docs/storage.md",
391+
"vector/embedding metadata: docs/storage.md",
392+
],
393+
});
394+
});
395+
396+
test("data model detector recognizes compound persisted path identifiers", () => {
397+
const detection = dataModelChangeFromPullFilesForTest({
398+
pullFiles: [
399+
{
400+
filename: "src/runtime/load-checkpoint.ts",
401+
patch:
402+
"@@\n+ const raw = await readFile(checkpointFilePath, 'utf8');\n+ return JSON.parse(raw);",
403+
},
404+
{
405+
filename: "src/runtime/load-state.ts",
406+
patch:
407+
"@@\n+ const raw = await readFile(state_file_path, 'utf8');\n+ return JSON.parse(raw);",
408+
},
409+
{
410+
filename: "src/runtime/load-cache.ts",
411+
patch:
412+
"@@\n+ const raw = await readFile(cacheDirectoryPath, 'utf8');\n+ return JSON.parse(raw);",
413+
},
414+
],
415+
});
416+
417+
assert.deepEqual(detection, {
418+
change: true,
419+
surfaces: [
420+
"serialized state: src/runtime/load-cache.ts",
421+
"serialized state: src/runtime/load-checkpoint.ts",
422+
"serialized state: src/runtime/load-state.ts",
423+
],
424+
});
425+
});
426+
297427
test("data model detector flags path-hinted persisted field declarations", () => {
298428
const detection = dataModelChangeFromPullFilesForTest({
299429
pullFiles: [

0 commit comments

Comments
 (0)