Repository navigation
GH-6336: fix(#6335): address defects found by post-merge review against issue #6321 - #6342
Merged
Merged
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
2 tasks
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
Automated PR created by Pilot for task GH-6336.
Closes #6336
Changes
GitHub Issue GH-6336: fix(#6335): address defects found by post-merge review against issue #6321
Context
A post-merge review of PR #6335 (#6335), which implemented issue #6321, returned REQUEST-CHANGES. The PR is already merged; fix the defects below on a new PR.
Defects
Evidence: backend_claudecode.go:709 calls env = prependPathEnv(env, shimDir) and :710 appends ghGuardTaskEnv(...). At ghguard_spawn.go:98-103 those are the PILOT_* names. In the agent process, cmd/pilot/ghguard.go:103-105 reads realGh := id.RealGh (now empty) and calls ResolveFallbackGh(getenv(ghguard.EnvShimDir)) with "". At policy.go:938 and :943, excludeDir = filepath.Clean(excludeDir) turns "" into ".", which excludes nothing. So the shim's own gh is the first match, and ghguard.go:113 exec.Command(realGh, args...) re-enters the shim without end on every allowed gh call. Task identity and the denial journal are lost too. The test at agent_command_test.go (allowlist case) asserts PILOT_GH_REAL is dropped, which pins this behaviour.
Reviewer Notes
[pass A (hunk)]
1 Config: met. backend.go:1340-1341 adds RunAsUser/RunAsGroup with yaml tags run_as_user/run_as_group, and pilot.example.yaml:948-950 carries the required sentence. An absent key unmarshals to "", which takes the empty-option path at agent_command.go:149.
2 Constructor: met. agent_command.go:208-217 returns plain exec.CommandContext when s is nil, and otherwise sudo plus preserve-env plus "--". setAgentEnv at :300-308 rewrites the flag from the final env, so names and values cannot drift. A cmd not built by agentCommand fails agentCmdUser at :315 and gets a plain assignment.
3 Spawn sites: met. A Grep of exec.Command in internal/executor (non-test) finds no remaining model-CLI spawn. Only gh, git, gates, hooks, dmesg and the billing command remain, and the issue scopes those out. agent_command_sites_test.go:30-71 covers all 11 named sites through the real code paths with a mock sudo.
4 Allowlist: met as written (agent_command.go:65-75 and :258-280). The billing names ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN (model_env.go:213-216) pass through the ANTHROPIC_ prefix. With the option empty, setAgentEnv assigns env unchanged (:291-294). The env it drops breaks the gh guard; see the blocking defect.
5 Kill: met for killProcessGroup callers. process_group.go:23 routes to killAgentProcessGroup with the 5s timeout at agent_command.go:342, and TestRunAsUserKillProcessGroupGoesThroughSudo covers it. Paths that call Process.Kill directly are listed as minor defects.
6 Preflight: met. main.go:460 runs it inside applyReadGuardConfig, which is reached from PersistentPreRun at :398 and from start at :568. A failure sets failed, and agentCommand returns the error at :205-207 before building anything. TestReadGuardConfigRunsRunAsUserPreflight pins the wiring.
7 Guard modes: met for mode and group as specified (read_guard.go:136, :146, :178; ghguard_spawn.go:45, :67). With the option empty, applyGuardPerm returns at agent_command.go:368, so modes stay 0700/0600.
8 Tests: present and table-driven. They run the real spawn code against a mock sudo, not a mock of the adapter under test.
Memories: the autopilot YAML pitfall does not apply, since run_as_user binds under executor.claude_code (main.go:473). The founder-token learning has no bearing on this diff.
[pass B (adjacent)]
Acceptance Criteria
Refs
Not verified
Reason: no commands parsed from acceptance item (expected an inline
command)Pre-PR review
Mode: enforce
Verdict: APPROVE-WITH-NOTES
Fix: none
Defects:
Not-verified: