Skip to content

fix: use PATCH /v1/sdk/agents/{id}/identity for DID registration#34

Merged
beonde merged 2 commits intomainfrom
fix/identity-endpoint
Feb 20, 2026
Merged

fix: use PATCH /v1/sdk/agents/{id}/identity for DID registration#34
beonde merged 2 commits intomainfrom
fix/identity-endpoint

Conversation

@beonde
Copy link
Member

@beonde beonde commented Feb 20, 2026

Summary

Updates the DID registration call to use the new dedicated identity endpoint with PATCH method.

Changes

  • Changed HTTP method from PUT to PATCH
  • Updated endpoint path from /v1/sdk/agents/{id} to /v1/sdk/agents/{id}/identity
  • Updated tests to match new endpoint

Why

The server's previous PUT /v1/sdk/agents/{id} endpoint overwrote ALL agent fields, causing:

  • name field to become empty string (violating NOT NULL constraint)
  • HTTP 500 errors during DID registration

The new dedicated endpoint only updates identity fields (DID, publicKey) and enforces RFC-003 §9.5 immutability rules.

Testing

  • All unit tests pass (go test ./...)
  • Integration tests with local server: passing

Dependencies

⚠️ Requires: capiscio/capiscio-server#29 to be deployed first

Related PRs

PR 2/4 in the identity recovery fix series:

  1. ✅ capiscio-server#29 - New endpoint
  2. capiscio-core (this PR) - Update Init RPC
  3. capiscio-sdk-python - SDK recovery fixes
  4. capiscio-e2e-tests - 14 new tests

- Change HTTP method from PUT to PATCH for identity registration
- Update endpoint path from /v1/sdk/agents/{id} to /v1/sdk/agents/{id}/identity
- Update tests to match new endpoint

This change aligns with the server's new dedicated identity endpoint that
enforces RFC-003 §9.5 immutability rules.

Requires: capiscio/capiscio-server#29
Copilot AI review requested due to automatic review settings February 20, 2026 03:05
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/rpc/simpleguard_service.go 50.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the SimpleGuard Init (internal RPC) DID registration call to use the new server identity endpoint, preventing agent record overwrites during registration.

Changes:

  • Switch DID registration request from PUT /v1/sdk/agents/{id} to PATCH /v1/sdk/agents/{id}/identity.
  • Treat HTTP 409 Conflict from the identity endpoint as non-fatal (immutability case).
  • Update unit tests to assert the new method and path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
internal/rpc/simpleguard_service.go Updates DID registration URL/method and adds special handling for HTTP 409 responses.
internal/rpc/simpleguard_service_test.go Updates expectations for the DID registration request method/path.

Comment on lines +662 to +665
// 409 Conflict means identity already exists (RFC-003 §9.5 immutability) - not an error
if resp.StatusCode == http.StatusConflict {
return nil // Identity already registered, this is expected
}
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

registerDIDWithServer now treats HTTP 409 Conflict as a non-error, but this new behavior isn't covered by unit tests. Add a test case asserting that a 409 response returns nil (and, if applicable, that callers handle it appropriately) to prevent regressions.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +662 to +665
// 409 Conflict means identity already exists (RFC-003 §9.5 immutability) - not an error
if resp.StatusCode == http.StatusConflict {
return nil // Identity already registered, this is expected
}
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

By returning nil on HTTP 409, callers cannot distinguish between “identity updated” and “identity already existed / update rejected”. In Init, this currently results in registered = true even when the server may not have accepted the new DID. Consider returning an explicit status (e.g., (updated bool, err error) or a sentinel error) so InitResponse.registered can accurately reflect what happened and clients can surface a clear message to the user.

Copilot uses AI. Check for mistakes.
Comment on lines +632 to 637
// Uses PATCH /v1/sdk/agents/{id}/identity to update only the agent's DID (RFC-003).
func (s *SimpleGuardService) registerDIDWithServer(serverURL, apiKey, agentID, didKey string) error {
// Normalize URL to prevent double-slash issues
normalizedURL := strings.TrimRight(serverURL, "/")
url := fmt.Sprintf("%s/v1/sdk/agents/%s", normalizedURL, agentID)
url := fmt.Sprintf("%s/v1/sdk/agents/%s/identity", normalizedURL, agentID)

Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The PR updates DID registration in SimpleGuardService, but there is still a code path in the CLI that uses the legacy PUT /v1/sdk/agents/{id} endpoint (cmd/capiscio/init.go registerDID). This looks inconsistent with the PR title/description and may leave the original overwrite/500 issue unresolved for CLI-based registration. Consider updating the CLI registration call to PATCH /v1/sdk/agents/{id}/identity as well (or narrow the PR description/title if this change is intentionally scoped to the Init RPC only).

Copilot uses AI. Check for mistakes.
- Change PUT /v1/sdk/agents/{id} to PATCH /v1/sdk/agents/{id}/identity
- Handle 409 Conflict as success (RFC-003 §9.5 immutability)
- Add test for 409 Conflict handling

Addresses Copilot review comments on PR #34
@beonde beonde merged commit 5a816a8 into main Feb 20, 2026
3 checks passed
@beonde beonde deleted the fix/identity-endpoint branch February 20, 2026 07:59
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.

1 participant

Comments