fix(cli): survive agent-relay credential masking in session and workspace reads - #380
Conversation
…pace reads Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAgent Relay credential and workspace resolution now requests unmasked secrets, supports older CLI fallbacks, rejects masked tokens, and recovers workspace keys from environment variables or the local workspace store when resolver errors are redacted. ChangesAgent Relay resolution
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant RelayfileCLI
participant AgentRelay
participant WorkspaceStore
participant RelaycastValidation
RelayfileCLI->>AgentRelay: Request revealed active workspace
AgentRelay-->>RelayfileCLI: Workspace data or resolver error
RelayfileCLI->>WorkspaceStore: Resolve fallback workspace key
WorkspaceStore-->>RelayfileCLI: Return active workspace key
RelayfileCLI->>RelaycastValidation: Validate workspace key
RelaycastValidation-->>RelayfileCLI: Return classification
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Relayfile Eval ReviewRun: Passed: 4 | Needs human: 0 | Reviewable: 0 | Missing output: 0 | Failed: 0 | Skipped: 0 Human Review CasesNo reviewable human-review cases captured Relayfile output. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
cmd/relayfile-cli/main_test.go (1)
2902-2943: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd legacy fallback coverage for
workspace active.These tests cover
cloud session --reveal-token, but notworkspace active --reveal-secretsreturningunknown optionand succeeding through the plainworkspace active --jsonretry. This is a separate compatibility path.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/relayfile-cli/main_test.go` around lines 2902 - 2943, Add a test alongside TestCloudCredentialsFallBackWhenRevealTokenUnsupported that makes the fake agent reject workspace active --json --reveal-secrets with an unknown-option error, then return valid credentials for workspace active --json. Assert cloudCredentialsFromAgentRelay succeeds and preserves the returned access token, covering the separate legacy workspace fallback path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/relayfile-cli/main.go`:
- Around line 1365-1368: Update the environment-key lookup loop in the resolver
to ignore masked or redacted values such as “rk_live_…redacted” before returning
a key. Only accept an actual usable live relay key, then continue to the store
fallback when the environment value is masked; preserve the existing precedence
among the listed environment variable names.
---
Nitpick comments:
In `@cmd/relayfile-cli/main_test.go`:
- Around line 2902-2943: Add a test alongside
TestCloudCredentialsFallBackWhenRevealTokenUnsupported that makes the fake agent
reject workspace active --json --reveal-secrets with an unknown-option error,
then return valid credentials for workspace active --json. Assert
cloudCredentialsFromAgentRelay succeeds and preserves the returned access token,
covering the separate legacy workspace fallback path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b071abd7-67d2-497f-b6b5-922895fe9dad
📒 Files selected for processing (2)
cmd/relayfile-cli/main.gocmd/relayfile-cli/main_test.go
Agent Relay's redacted workspace-key display retains the rk_live_ prefix. That made a failure value observationally identical to a usable credential under the previous prefix-only check, so a masked environment value could block fallback to a valid workspaces.json key. Normalize external candidates to an empty sentinel unless they match the complete credential shape, and cover both masked-env/store fallback and the legacy reveal-secrets unknown-option retry.
Agent Relay intentionally keeps masked workspace keys credential-shaped so humans and tools can recognize a redacted credential; that display contract belongs to Relay and must not be tightened from relayfile. Prove instead that relayfile normalizes masked input to its empty sentinel before store fallback. Also isolate the regex-miss test from the operator's Agent Relay environment and workspaces.json: that path was read-only, but previously could read a live host key and forward it to the loopback test server.
agent-relay is adding credential masking to its CLI output (AgentWorkforce/relay#1380):
cloud session --jsonmasksaccessTokenunless--reveal-token,workspace active --jsonmasks keys unless--reveal-secrets, and error messages redact embedded credentials. Three relayfile read paths depend on those raw values; this makes each robust across old and new agent-relay CLIs:cloudCredentialsFromAgentRelay()requestscloud session --json --reveal-tokenfirst and falls back to the plain form when the CLI rejects the flag as unknown. A maskedaccessTokenis rejected with a clear error instead of being written to the credentials file (where it would 401 silently on every call).activeWorkspaceFromAgentRelay()requestsworkspace active --json --reveal-secretswith the same fallback.$AGENT_RELAY_HOME/~/.agentworkforce/relay/workspaces.jsonbefore validating against Relaycast.Safe to merge before the agent-relay change lands; required before it ships.
Test run: full
./cmd/relayfile-clisuite green (110s), plus new tests for the reveal-token fallback, the masked-token guard, and the store-fallback classification.🤖 Generated with Claude Code
Test isolation note
Commit
08c9c3aalso isolatesTestClassifyAgentRelayActiveWorkspaceErrorPreservesRegexMissfrom the operator’s Agent Relay environment andworkspaces.json. This is a pre-existing read-only test defect bundled here because it blocked verification of this PR: on a regex miss, the test could read a live host workspace key and forward it only to its loopbackhttptest.Server, producing credential exposure to the test process and machine-dependent results. The path never writes or mutates the host store.