Skip to content

fix: preserve ERC-8021 service attribution#200

Open
steipete wants to merge 2 commits into
BlockRunAI:mainfrom
steipete:fix/preserve-builder-service-codes
Open

fix: preserve ERC-8021 service attribution#200
steipete wants to merge 2 commits into
BlockRunAI:mainfrom
steipete:fix/preserve-builder-service-codes

Conversation

@steipete

@steipete steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve valid pre-existing builder-code.info.s service codes
  • append BlockRun's registered code only when absent
  • return a fresh service-code array without mutating the payment challenge

Fixes #199.

Proof

  • focused builder-code tests: 7 passed
  • full suite: 652 passed, 3 skipped
  • Node 22.22.2/npm 10.9.7: typecheck, lint, Prettier, and build pass
  • source-blind behavior contract: existing attribution retained; already-stamped payload deduplicated; prior overwrite implementation rejected

No changelog edit: contributor PR; maintainer release notes own the entry.

Summary by CodeRabbit

  • Bug Fixes

    • Preserves any existing builder-code.info.s service code entries when updating builder code.
    • Avoids adding duplicate BlockRun service codes.
    • Filters out invalid/non-string entries while ensuring the required service code is present.
  • Tests

    • Added Vitest cases covering preservation, invalid-entry handling, and idempotency for builder code updates.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

withBuilderCodeServiceCode now preserves existing builder-code.info.s entries, filters invalid values, and appends BLOCKRUN_SERVICE_CODE only when needed. The test coverage was expanded to verify ordering, preservation, malformed input handling, and idempotency.

Changes

Builder code service code preservation

Layer / File(s) Summary
Preserve and de-duplicate info.s merge logic with tests
src/builder-code.ts, src/builder-code.test.ts
withBuilderCodeServiceCode now keeps valid existing info.s values, preserves other builder-code/info fields, and appends BLOCKRUN_SERVICE_CODE only if it is missing. New tests cover append ordering, preservation of info.a, invalid entry filtering, and no duplication when the code already exists.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • BlockRunAI/ClawRouter#198: Introduces the original withBuilderCodeServiceCode stamping logic that this PR updates to preserve existing service codes.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: preserving existing ERC-8021 service attribution when stamping builder code.
Linked Issues check ✅ Passed The code and tests match #199 by preserving existing valid service codes, appending BlockRun only when absent, and covering both regression cases.
Out of Scope Changes check ✅ Passed The changes stay focused on builder-code service attribution and regression tests, with no unrelated functionality introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/builder-code.ts (1)

30-33: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Discards entire array if a single entry is invalid.

If info.s contains one non-string entry alongside otherwise-valid codes, .every(...) fails and the whole array falls back to [], dropping all previously valid attribution codes. The issue asks to "keep any existing valid service codes already present" — filtering out only the invalid entries would better preserve attribution.

♻️ Proposed fix to filter instead of discard
-  const existingServiceCodes =
-    Array.isArray(existing.info?.s) && existing.info.s.every((code) => typeof code === "string")
-      ? existing.info.s
-      : [];
+  const existingServiceCodes = Array.isArray(existing.info?.s)
+    ? existing.info.s.filter((code): code is string => typeof code === "string")
+    : [];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/builder-code.ts` around lines 30 - 33, The existing service-code
extraction in the builder logic currently drops the entire list when any entry
in existing.info.s is invalid. Update the existingServiceCodes handling to
preserve valid strings by filtering existing.info.s for string entries instead
of requiring all entries to pass via every(...), so the builder code keeps any
already-valid attribution codes while ignoring only bad values. Use the
existingServiceCodes assignment in src/builder-code.ts as the target for this
change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/builder-code.ts`:
- Around line 30-33: The existing service-code extraction in the builder logic
currently drops the entire list when any entry in existing.info.s is invalid.
Update the existingServiceCodes handling to preserve valid strings by filtering
existing.info.s for string entries instead of requiring all entries to pass via
every(...), so the builder code keeps any already-valid attribution codes while
ignoring only bad values. Use the existingServiceCodes assignment in
src/builder-code.ts as the target for this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9f81ebde-bebc-44db-8829-7ae85c6058c6

📥 Commits

Reviewing files that changed from the base of the PR and between 9ae23c3 and 95f1ee8.

📒 Files selected for processing (2)
  • src/builder-code.test.ts
  • src/builder-code.ts

@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the malformed-array review note in 4d18feb: src/builder-code.ts:30 now filters out only non-string entries while preserving valid service codes, with regression coverage at src/builder-code.test.ts:35. Focused tests (8), typecheck, lint, and autoreview pass.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/builder-code.test.ts (1)

35-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider asserting non-mutation for the malformed-array path too.

The first test verifies the input array reference/content is untouched (Line 31-32); this test doesn't, leaving that guarantee unverified when the array contains non-string entries.

♻️ Suggested addition
   it("preserves valid service codes from a partially malformed array", () => {
+    const serviceCodes = ["bc_existing", 42, null];
     const ext = withBuilderCodeServiceCode({
-      "builder-code": { info: { s: ["bc_existing", 42, null] } },
+      "builder-code": { info: { s: serviceCodes } },
     });

     expect((ext["builder-code"] as BuilderCodeExtension).info.s).toEqual([
       "bc_existing",
       BLOCKRUN_SERVICE_CODE,
     ]);
+    expect(serviceCodes).toEqual(["bc_existing", 42, null]);
   });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/builder-code.test.ts` around lines 35 - 44, Add a non-mutation assertion
for the malformed-array case in the withBuilderCodeServiceCode test. Keep the
same input object/array reference before calling the helper, then verify that
the original builder-code.info.s array still contains the mixed values after the
call while the returned extension has the filtered/normalized codes. This should
mirror the existing immutability check from the valid-array test and cover the
path with non-string entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/builder-code.test.ts`:
- Around line 35-44: Add a non-mutation assertion for the malformed-array case
in the withBuilderCodeServiceCode test. Keep the same input object/array
reference before calling the helper, then verify that the original
builder-code.info.s array still contains the mixed values after the call while
the returned extension has the filtered/normalized codes. This should mirror the
existing immutability check from the valid-array test and cover the path with
non-string entries.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b5465b7d-a46e-4102-8d55-d07cce0d08b0

📥 Commits

Reviewing files that changed from the base of the PR and between 95f1ee8 and 4d18feb.

📒 Files selected for processing (2)
  • src/builder-code.test.ts
  • src/builder-code.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/builder-code.ts

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.

fix: preserve existing ERC-8021 service codes when stamping builder code

1 participant