fix: persist and recover did:key identity in dev mode#44
Conversation
When private.pem already exists on disk, _load_or_generate_keys() loaded the key but never recovered the did:key identity, leaving agent_id stuck at the placeholder 'local-dev-agent'. Fix: persist did:key to capiscio_keys/did_key.txt on first generation, read it back on subsequent loads. No cross-repo changes needed.
|
✅ Documentation validation passed!
|
|
✅ All checks passed! Ready for review. |
|
✅ SDK server contract tests passed (test_server_integration.py). Cross-product scenarios are validated in capiscio-e2e-tests. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Fixes SimpleGuard(dev_mode=True) identity persistence so a previously generated did:key is recovered when reusing an existing capiscio_keys/private.pem, avoiding the "local-dev-agent" placeholder across restarts/reruns.
Changes:
- Persist generated
did:keytocapiscio_keys/did_key.txtduring dev-mode key generation. - Recover
did:keyfromdid_key.txtwhen loading an existing key in dev mode (whenagent_idwasn’t explicitly provided).
You can also share your feedback on Copilot code review. Take the survey.
| self.agent_id = did_key_path.read_text().strip() | ||
| logger.info(f"Dev Mode: Recovered did:key identity: {self.agent_id}") |
| # Persist did:key for recovery on subsequent loads | ||
| did_key_path.write_text(did_key) |
| # Recover did:key identity from sidecar file if in dev mode | ||
| if self.dev_mode and not self._explicit_agent_id and did_key_path.exists(): | ||
| self.agent_id = did_key_path.read_text().strip() | ||
| logger.info(f"Dev Mode: Recovered did:key identity: {self.agent_id}") |
|
✅ Documentation validation passed!
|
|
✅ All checks passed! Ready for review. |
|
✅ SDK server contract tests passed (test_server_integration.py). Cross-product scenarios are validated in capiscio-e2e-tests. |
Problem
When
SimpleGuard(dev_mode=True)is called andcapiscio_keys/private.pemalready exists on disk (from a prior run),_load_or_generate_keys()takes the "load existing key" branch which only setssigning_kid— it never recovers thedid:keyidentity. Theagent_idstays stuck at the"local-dev-agent"placeholder set by_resolve_identity().This causes
test_dev_mode_auto_generates_did_keyto fail in CI because the E2E runner reuses the key directory across test runs.Root Cause
Two-part issue:
did:keyfrom the gRPC response but never persists itdid:keysince it's not in theLoadKeygRPC responseFix
did:keytocapiscio_keys/did_key.txtsidecar filedid_key.txtback when in dev mode with no explicit agent_idThis is entirely within the Python SDK — no cross-repo gRPC proto changes needed.
Testing
test_process.py— unrelated binary path tests)test_simple_guard.pyunit tests pass