fix(http_request): stabilize credential_profile env resolution#2570
fix(http_request): stabilize credential_profile env resolution#2570theonlyhennygod merged 2 commits intomainfrom
Conversation
|
Caution Review failedPull request was closed or merged during review Note
|
| Cohort / File(s) | Summary |
|---|---|
HttpRequest tool core src/tools/http_request.rs |
Adds credential_cache: Mutex<HashMap<String, String>>, helper methods read_non_empty_env_var, cache_secret, cached_secret, and resolve_secret_for_profile. Normalizes profile names to lowercase, preloads cache from env, and replaces direct env reads with cache-backed resolution and warnings when falling back to cached secrets. |
Tests (http_request) src/tools/.../http_request_tests.rs, tests/... |
Adds tests covering: caching when env var becomes temporarily missing, cache refresh after secret rotation, and behavior when env var is empty (should not fall back to cache). Duplicated/parallel test blocks present for these scenarios. |
Metadata / deps Cargo.toml |
Minor dependency/declaration adjustments referenced by the diff (lines added/removed related to implementation). |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant HttpRequestTool
participant Env as Environment
participant Cache as CredentialCache
Client->>HttpRequestTool: request with credential_profile "clawhub"
HttpRequestTool->>Cache: lookup("CLAWHUB_TOKEN")
alt cache hit
Cache-->>HttpRequestTool: return cached_secret
else cache miss
HttpRequestTool->>Env: read "CLAWHUB_TOKEN"
alt env has non-empty value
Env-->>HttpRequestTool: return secret
HttpRequestTool->>Cache: store secret
else env missing/empty
alt cache has entry
Cache-->>HttpRequestTool: return cached_secret (warn)
else
HttpRequestTool-->>Client: error (missing credential)
end
end
end
HttpRequestTool->>Client: attach header and perform request
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- feat(http_request): add env-backed credential profiles and onboarding policy presets #2148: Introduced env-backed
credential_profilesandresolve_credential_profileinsrc/tools/http_request.rs; this PR extends that work by adding caching and cache-backed secret resolution.
Suggested reviewers
- chumyin
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | The PR description provides a clear summary of changes (3 bullets), links to issue #2562, and includes validation commands. However, it lacks the comprehensive metadata required by the template, including risk/size labels, change type, security/privacy assessments, and detailed validation evidence. |
Complete the PR description to match the template structure by adding Label Snapshot, Change Metadata, Security Impact assessment, Privacy review, Compatibility details, and Human Verification sections. | |
| Docstring Coverage | Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The PR title 'fix(http_request): stabilize credential_profile env resolution' directly describes the main change: adding credential caching and fallback mechanisms to stabilize environment variable resolution for credential profiles. |
| Linked Issues check | ✅ Passed | The PR implementation directly addresses issue #2562's objectives: adds credential caching mechanism, implements fallback to cached secrets on env var lookup failures, supports secret rotation, and includes tests covering all scenarios including the empty env var edge case. |
| Out of Scope Changes check | ✅ Passed | All changes in src/tools/http_request.rs are scoped to credential profile env resolution: credential caching, helper methods for cache management, and updated credential resolution flow with new tests. No unrelated modifications detected. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
- 📝 Generate docstrings (stacked PR)
- 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
- Commit unit tests in branch
issue-2562-http-request-credential-profile
Comment @coderabbitai help to get the list of available commands and usage tips.
PR intake checks found warnings (non-blocking)Fast safe checks found advisory issues. CI lint/test/build gates still enforce merge quality.
Action items:
Detected Linear keys: none Run logs: https://github.com/zeroclaw-labs/zeroclaw/actions/runs/22647234298 Detected blocking line issues (sample):
Detected advisory line issues (sample):
|
|
Thanks for contributing to ZeroClaw. For faster review, please ensure:
See |
|
@theonlyhennygod You are on the right path, although there is still some work that needs to be done. Keep going. |
|
Out of curiosity I locally pulled this PR, it compiles perfectly but still env vars for configured credential_profiles are not found |
f0b00e8 to
cade681
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/tools/http_request.rs (1)
954-1032: Add a boundary test for the empty-env branch in credential resolution.Lines 954-1032 cover missing-env and rotation well, but the new empty-value branch (Line 58 onward) is not explicitly tested. Please add one deterministic test to lock intended behavior for that failure mode.
As per coding guidelines: "For security/runtime/gateway/tools changes, include at least one boundary/failure-mode validation."
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tools/http_request.rs`:
- Around line 58-66: The current logic treats an empty env value
(secret.is_empty()) as safe to reuse a cached secret via
self.cached_secret(env_var) which must be removed; instead, when
secret.is_empty() is detected, do not fall back to cached secrets—log a
warning/error referencing requested_name and env_var and return a hard error
(e.g., bail! or Err) from the surrounding method so credential revocation is
honored. Update the branch containing secret.is_empty(), remove the return
Ok(cached) path that calls self.cached_secret(env_var), and ensure callers
handle the propagated error; keep tracing fields (profile=requested_name,
env_var) in the log for context.
|
Addressing the remaining review point in commit What was fixed
Regression coverage added
Targeted validation run (all passed)
Broader safety pass
|
1989de3 to
f316e78
Compare
Closes #2562
Summary
Validation
Summary by CodeRabbit