feat(kiloclaw): add generic patchSecrets endpoint with catalog-driven validation#947
Merged
feat(kiloclaw): add generic patchSecrets endpoint with catalog-driven validation#947
Conversation
Contributor
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)No new issues on diff lines. Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (14 files)
|
…schema Address two code review findings on PR #947: 1. SecretsPatchSchema now validates keys against the secret catalog, rejecting unknown field keys at the worker layer (defense in depth). 2. updateSecrets remaps field keys to env var names at the storage boundary so buildEnvVars/mergeEnvVarsWithSecrets works correctly. A reverse map (ENV_VAR_TO_FIELD_KEY) ensures reading back from encryptedSecrets doesn't accumulate phantom entries. No changes to env.ts or encryption.ts — the read pipeline works as-is since encryptedSecrets now stores env var names.
…nt double-count
- Add post-merge allFieldsRequired validation in updateSecrets to reject
partial clears (e.g. removing one Slack token while keeping the other)
- Filter channel env vars from secretCount to prevent double-counting
with channelCount
- Add test for partial clear rejection
pandemicsyn
approved these changes
Mar 9, 2026
Contributor
pandemicsyn
left a comment
There was a problem hiding this comment.
pre-approving, but heads up - i think you have some of your browser image update in here as well.
… to catalog keys
- Throw validation errors with status 400 and 'Invalid secret patch:'
prefix so sanitizeError passes the message through instead of generic 500
- Add prefix to SAFE_ERROR_PREFIXES in platform routes
- Filter configured return to only include ALL_SECRET_FIELD_KEYS,
preventing non-catalog env var names from leaking into the response
…ingle-field rotations The patch-only check rejected valid operations like rotating slackBotToken when slackAppToken was already stored. The DO's post-merge check is the authoritative guard since it sees existing state + patch together
…law/config The config route still used raw Object.keys(encryptedSecrets).length, double-counting channel tokens that are already reported by channelCount. Apply the same CHANNEL_ENV_VARS filter used in getStatus().
446547e to
fb6be31
Compare
…in patchSecrets - Export SecretFieldKey union from secret-catalog package - Use Partial<Record<SecretFieldKey, ...>> for patchSecrets input/response types - Preserve response body in KiloClawApiError for structured error handling - Translate worker 4xx responses into TRPCErrors with actionable messages
…event field-key collisions
- Export SecretFieldKey union from secret-catalog package
- Use Partial<Record<SecretFieldKey, ...>> for patchSecrets input/response types
- Preserve response body in KiloClawApiError for structured error handling
- Translate worker 4xx responses into TRPCErrors with actionable messages
- Track non-catalog secrets separately in updateSecrets to prevent
field-key collisions from silently rewriting generic secrets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
feat(kiloclaw): add generic patchSecrets endpoint with catalog-driven validation
Adds patchSecrets tRPC mutation and PATCH /api/platform/secrets worker endpoint
alongside existing patchChannels. Uses secret catalog for key validation,
pattern matching, maxLength enforcement, and allFieldsRequired enforcement.
Makes updateChannels delegate to updateSecrets internally so both storage fields
(channels + encryptedSecrets) stay in sync regardless of which endpoint is
called. Eliminates interleave drift risk.
Key design decisions:
(e.g., TELEGRAM_BOT_TOKEN) so the existing buildEnvVars/mergeEnvVarsWithSecrets
pipeline works unchanged. A reverse map (ENV_VAR_TO_FIELD_KEY) converts back to
field keys when reading into the working set.
(existing secrets + patch), not just the incoming patch. This allows
single-field rotations (e.g., rotating slackBotToken when slackAppToken is
already stored) while still rejecting invalid partial clears.
encryptedSecrets but excluded from secretCount (via CHANNEL_ENV_VARS filter)
since they're already counted by channelCount. Applied in getStatus(),
getDebugState(), and /api/kiloclaw/config.
Invalid secret patch: prefix so the route handler returns the actual message
instead of a generic 500.
Verification
Visual Changes
N/A
Reviewer Notes