Skip to content

fix: detect duplicate node_id in Load() and SetForTest (PILOT-136)#3

Merged
TeoSlayer merged 2 commits into
mainfrom
openclaw/pilot-136-20260528-134059
May 28, 2026
Merged

fix: detect duplicate node_id in Load() and SetForTest (PILOT-136)#3
TeoSlayer merged 2 commits into
mainfrom
openclaw/pilot-136-20260528-134059

Conversation

@matthew-pilot
Copy link
Copy Markdown
Collaborator

What failed

Load() in data.go:111-130 silently accepts duplicate node_id entries — the last duplicate wins via map overwrite. If a maintainer accidentally duplicates an agent entry in trusted-agents.json, the duplicate silently replaces the original hostname. A corrupted or malicious refresh could also inject a name collision without detection.

Why this fix

Load() now detects duplicate node_id entries during the loop and returns a descriptive error before committing the map. The previous known-good list is preserved — a bad refresh fails safe.

SetForTest() panics on duplicates since test lists must be well-formed (the function signature has no error return).

Verification

  • go build ./...
  • go vet ./...
  • go test ./... ✅ (new TestLoadDuplicateNodeID passes)
  • 2 files changed: data.go (+7), zz_test.go (+16)

Closes PILOT-136

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

🔍 Matthew PR Explain — #3 PILOT-136

What this PR does

Adds duplicate node_id detection to Load() and SetForTest() in the trustedagents registry.

Changes

  • data.go (+7): Load() now detects duplicate node_id entries during the loop and returns a descriptive error before committing the map. Previously the last duplicate silently won via map overwrite.
  • zz_test.go (+16): New TestLoadDuplicateNodeID to verify the detection. SetForTest() panics on duplicates since the function has no error return (test lists must be well-formed).

Why

If a maintainer accidentally duplicates an agent entry in trusted-agents.json, the duplicate silently replaces the original hostname. A corrupted or malicious refresh could also inject a name collision without detection. This fix fails safe.

Verification

  • go build ./...
  • go vet ./...
  • go test ./... ✅ (new TestLoadDuplicateNodeID passes)

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

🦾 Matthew PR Check — #3 PILOT-136

Status

  • State: OPEN · MERGEABLE · CLEAN ✅
  • CI: 2/2 green ✅
    • test — SUCCESS
    • codecov/patch — SUCCESS
  • Canary: N/A (no canary harness for this repo)
  • Jira: PILOT-136

PR details

  • Branch: openclaw/pilot-136-20260528-134059main
  • Files: 2 changed (+23 / −0)
  • Review: no reviews yet

matthew-pilot added 2 commits May 28, 2026 10:42
Adds a test that Load() must reject JSON with duplicate node_id entries.
Current code silently overwrites (last entry wins), so this test FAILS
until the fix lands.
… (PILOT-136)

Load() now returns a descriptive error when the JSON contains duplicate
node_id entries (previously the last duplicate silently won). SetForTest
panics on duplicates since test lists must be well-formed.

Load protects the daemon's trusted-agents list from silently accepting
the wrong agent when a maintainer accidentally duplicates a node_id.
A bad refresh (network corruption, whatnot) that produces duplicate
entries also fails safe — the previous known-good list is not replaced.

Closes PILOT-136
@TeoSlayer TeoSlayer force-pushed the openclaw/pilot-136-20260528-134059 branch from 2a04ef3 to ed15d7a Compare May 28, 2026 17:43
@TeoSlayer TeoSlayer merged commit 36cc436 into main May 28, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the openclaw/pilot-136-20260528-134059 branch May 28, 2026 17:45
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.

2 participants