Skip to content

fix(source-control): defer the MCP linkage gate to a consumer's own tracked copy - #2068

Merged
kyle-sexton merged 4 commits into
mainfrom
fix/mcp-gate-defer-guard
Aug 9, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
fix/mcp-gate-defer-guard

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No linked issue

Summary

Executes #2021 remediation line 4 (de-dup the double-fired MCP linkage gate) per the read-only investigation's verdict: the plugin copy yields to a consumer repo's own tracked equivalent, and the repo-local hook tests join CI so the two copies can never drift silently again.

Fix

  • plugins/source-control/hooks/pr-linkage-mcp-gate.sh: after the gate-file and scope checks, the hook defers (emit_tel "deferred", exit 0) when <repo>/.claude/settings.json wires any PreToolUse command naming pr-linkage-mcp-gate. The plugin side is the sound place to yield — the settings file states the wiring authoritatively; the repo-local script has no reliable "plugin active" signal (plugin source present ≠ plugin enabled). Named, accepted cost documented in the script and changelog: a same-named no-op script suppresses the gate; it is a policy gate, and the required pr-issue-linkage CI check remains the authority.
  • scripts/run-plugin-tests.sh now also runs .claude/hooks/*.test.sh — .claude/hooks/pr-linkage-mcp-gate.test.sh never ran in CI, which is how the two copies drifted apart silently. (This also activates the telemetry-sink drift test added on chore: wire the claude-ops reference telemetry sink for this repo's own hooks #2048.)
  • Tests: two new defer cases in the plugin suite (consumer's tracked gate defers; unrelated settings wiring does not) — plugin suite 22/0, repo-local suite 17/0.
  • source-control 0.49.1 → 0.49.2 with changelog.

Verification

Both suites green locally (22/0, 17/0); shellcheck clean at info severity; catalog/cheat-sheet regeneration: no diff. The cheaper alternative (deleting the repo-local settings entry) was rejected because docs/CLOUD-SESSIONS.md and docs/MIGRATION-PLAYBOOK.md currently contradict each other on whether cloud sessions load the plugin at all — tracked as #2053; this defer-guard is sound in both worlds.

Related

Refs #2021 (line 4), #2053 (the doc contradiction gating the cheaper fix), #2048 (the drift-test this runner extension activates).

🤖 Generated with Claude Code

…racked copy

A repo wiring its own pr-linkage-mcp-gate in .claude/settings.json (the
marketplace repo does; its copy is deliberately kill-switch-free tracked
policy) got both gates firing exit-2 on every MCP PR call. The plugin copy
now defers when the consumer's settings wire a PreToolUse command naming
the gate: the settings file states the wiring authoritatively, while the
repo-local script has no sound plugin-active signal. Accepted, named cost:
a same-named no-op script suppresses the gate — policy gate, not a
security guard; the required CI check stays the authority.

Also extends scripts/run-plugin-tests.sh to .claude/hooks/*.test.sh: the
repo-local gate's test never ran in CI, which is how the two copies
drifted silently. source-control 0.49.1 -> 0.49.2.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 56s —— View job


Review complete ✅

  • Gather context (PR body, diff, CLAUDE.md)
  • Review plugins/source-control/hooks/pr-linkage-mcp-gate.sh defer logic
  • Review test coverage additions
  • Review scripts/run-plugin-tests.sh change
  • Review CHANGELOG/version bump
  • Post findings

No blocking issues. The defer-guard is correctly scoped and the logic traces cleanly:

  • The new block (pr-linkage-mcp-gate.sh L121-137) sits after the gate-file check and the out-of-scope guard, so it only fires when this repo would otherwise actually be enforced — matching the PR description.
  • I confirmed the plugin registers its own hook via hooks/hooks.json (${CLAUDE_PLUGIN_ROOT}/hooks/pr-linkage-mcp-gate.sh), not via .claude/settings.json — so the jq scan of .claude/settings.json for a command containing pr-linkage-mcp-gate won't self-match the plugin's own registration in the normal (non-redundant) install path. It only matches a genuine repo-local copy, e.g. this repo's own .claude/hooks/pr-linkage-mcp-gate.sh, whose wiring I checked in .claude/settings.json (L14-26) — command string is "$CLAUDE_PROJECT_DIR"/.claude/hooks/pr-linkage-mcp-gate.sh, so the contains() check matches it.
  • Fail-direction is correct in both failure modes I traced: malformed/missing settings.json → jq -e fails → condition false → falls through to normal enforcement (fails toward enforcing, not toward silently skipping). .hooks.PreToolUse absent/null → []? yields empty → any() false → same fallthrough.
  • The two new test cases in pr-linkage-mcp-gate.test.sh (L102-114) exercise exactly the two branches: a body that would normally block (NO_RELATED) passes when the consumer's settings name the gate (defer wins over body validation), and stays blocked when settings wire something unrelated. That ordering — defer checked before body validation — is exactly what's needed to prove the defer isn't just "body happened to pass."
  • scripts/run-plugin-tests.sh's find plugins .claude/hooks -type f -name '*.test.sh' 2>/dev/null correctly folds in the repo-local suite; I confirmed .github/workflows/ci.yml actually invokes this runner, so the fix's stated premise (the repo-local test never ran in CI) is real and now addressed.
  • Changelog entry and version bump (0.49.1 → 0.49.2, Fixed section) are consistent with the file's existing style; confirmed no other tracked file still references 0.49.1, so no stale catalog/version references were missed.

Named, accepted tradeoff (already documented by the author, not a new finding): the contains("pr-linkage-mcp-gate") substring match means any command path containing that string defers the plugin gate, including a deliberate or accidental no-op script of the same name. This is called out explicitly in both the script comment and the changelog as an accepted cost of a policy gate (vs. a security guard), so I'm not raising it as a separate issue.

Could not independently verify (tool restrictions in this lane):

  • Bash script execution was not approved in this session, so I could not run pr-linkage-mcp-gate.test.sh, the repo-local suite, or run-plugin-tests.sh myself, nor shellcheck. The PR's stated "22/0", "17/0", and shellcheck-clean results are author-claimed and unverified by me — my confidence is from static tracing of the added logic and test cases against the script's control flow, not from execution.
  • The catalog/cheat-sheet "no diff" claim is likewise author-claimed; I did confirm via grep that no other tracked file still references the old 0.49.1 version string, which is consistent with that claim but not a full regeneration check.

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 52s —— View job


Security review complete ✅

  • Gather context (diff, changed files)
  • Read changed files in full
  • Analyze pr-linkage-mcp-gate.sh defer logic for trust-boundary / bypass issues
  • Analyze run-plugin-tests.sh changes
  • Analyze test file changes
  • Post findings

Scope: the 5 files changed in this PR (plugin.json version bump, CHANGELOG.md, hooks/pr-linkage-mcp-gate.sh, hooks/pr-linkage-mcp-gate.test.sh, scripts/run-plugin-tests.sh), diffed against origin/main.

Findings

No CRITICAL or IMPORTANT security issues found. This is a shell-hook policy change, not a workflow/permissions/trigger change, so there's nothing in zizmor's advisory lane to defer here — the review below is my own logic/trust-boundary read.

SUGGESTION / informational — the disclosed defer-bypass is real but is exactly the cost the author already named and bounded
plugins/source-control/hooks/pr-linkage-mcp-gate.sh#L132-L137

The new defer-guard checks only that some PreToolUse hook command string in the consumer's .claude/settings.json contains the substring pr-linkage-mcp-gate — it never verifies the referenced file exists, is executable, or actually performs the body validation. A repo (or a compromised PR against one) could wire a no-op script under that name and silently disable the plugin-side gate with no error, no telemetry anomaly beyond deferred, and no fallback re-check.

This is the exact tradeoff the PR's own comment and changelog call out ("a same-named no-op script suppresses the gate... this is a policy gate, not a security guard, and the required CI check remains the authority"), so I'm not flagging it as a new/undisclosed risk — the author already reasoned about it and the real enforcement backstop (pr-issue-linkage required CI check, server-side) is unaffected by anything a local hook does. I mention it only because the review brief asks to hunt for authorization/bypass logic specifically: confirmed present, confirmed already priced in, confirmed bounded (worst case = same UX as having no local hook at all, which is the pre-PR status quo for every repo that lacks a local copy).

No issues found with:

  • jq usage — the filter passed to jq -e at L133 is a static expression; the untrusted value (.claude/settings.json contents) is only ever data jq reads, never concatenated into the filter program, so there's no jq-injection surface.
  • Path handling — $REPO_ROOT/.claude/settings.json reuses the same REPO_ROOT already trusted for the pre-existing GATE_FILE scope check earlier in the script; this PR doesn't introduce a new untrusted-path source.
  • Fail direction — malformed/unreadable settings JSON makes jq -e fail, so the if is false and the hook falls through to normal (stricter) enforcement rather than deferring — fails closed, not open.
  • scripts/run-plugin-tests.sh — widening the test glob to include .claude/hooks/*.test.sh doesn't cross a new trust boundary; both trees already require repo-commit access to modify, and both were already executed as trusted shell in CI.
  • Test fixtures (pr-linkage-mcp-gate.test.sh) — synthetic, self-contained, no secrets or unsafe patterns.
  • plugin.json / CHANGELOG.md — version bump and prose only.
    · branch fix/mcp-gate-defer-guard

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 55981ea477

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude has reviewed this PR 4 times. The lane skips further automatic reviews after 5; deleting this comment resets the count.

Review findings: the defer projection read only .command, so exec-form
wiring (command "bash" with the gate script in args) did not defer — args
strings now join the projection with a test pinning the form; and the
deferral envelope used the undocumented "deferred" status, which the
reference sink maps to error/exit 2 — it now emits status "skipped" with
outcome "deferred" in data.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Both findings fixed in 7de935b: the defer projection now includes exec-form args strings (with a test pinning {"command":"bash","args":["…/pr-linkage-mcp-gate.sh"]} deferring — suite 23/0), and the deferral envelope rides the documented skipped status with outcome: deferred in data, per the telemetry contract and the reference sink's unknown-status→error mapping.

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 51s —— View job


Security review complete ✅

  • Gather context (PR diff, custom instructions)
  • Read changed files in full
  • Analyze pr-linkage-mcp-gate.sh defer logic for trust-boundary/bypass issues (incl. Codex's exec-form finding)
  • Analyze run-plugin-tests.sh changes
  • Analyze test file changes
  • Post findings

Scope: the 5 files changed in this PR, at HEAD 7de935b — plugin.json (version bump), CHANGELOG.md, hooks/pr-linkage-mcp-gate.sh, hooks/pr-linkage-mcp-gate.test.sh, scripts/run-plugin-tests.sh. This review supersedes my earlier pass on 55981ea: the branch picked up a second commit (7de935b) since then that responds directly to Codex's two review comments.

No CRITICAL or IMPORTANT security issues found

Both Codex findings on the prior commit were about detection completeness, not a bypass in the security-relevant direction, and both are now fixed:

  • Exec-form args now inspected — pr-linkage-mcp-gate.sh#L143-L146 now projects (.command // empty), (.args[]? | strings) before the contains("pr-linkage-mcp-gate") check, so a consumer wiring the gate as {"command":"bash","args":[".../pr-linkage-mcp-gate.sh"]} is now detected. Note the security direction here was benign even before the fix: missing this case meant the plugin gate did not defer, i.e. it over-enforced (both gates fire) rather than under-enforcing — a reliability/UX bug, not a bypass. strings correctly filters .args[] to string elements only, so a non-string arg element can't crash the filter.
  • Telemetry status now documented — pr-linkage-mcp-gate.sh#L121-L130 emits envelope status skipped (domain detail deferred stays in data.outcome), matching the documented ok|error|skipped|blocked contract. I confirmed against the actual sink logic at plugins/claude-ops/hooks/hook-telemetry-sink.sh (unchanged in this PR, read for context only) that skipped maps to exit_code 0 — the fix's premise holds. This is an observability-correctness fix, not a security fix (nothing about enforcement or authorization depended on the telemetry status).

Re-verified from my prior pass, still holds on the current HEAD:

  • jq filter is a static expression — the untrusted .claude/settings.json content is only ever read as data by jq -e, never concatenated into the filter program, so there's no jq-injection surface at L144-146.
  • Fail-direction stays fail-closed (enforcing) — malformed/unreadable settings JSON, or absent .hooks.PreToolUse, makes the if condition false and the hook falls through to normal (stricter) body validation rather than deferring.
  • scripts/run-plugin-tests.sh — widening the test glob to .claude/hooks/*.test.sh doesn't cross a new trust boundary; both trees already require repo-commit access, both already ran as trusted shell in CI.
  • Test file, plugin.json, CHANGELOG.md — synthetic fixtures / version+prose only, no security surface.

Named, accepted tradeoff (author-disclosed, unchanged by this commit, not a new finding): the contains("pr-linkage-mcp-gate") substring match still means any command/arg string containing that substring defers the plugin gate, including a same-named no-op script. This is explicitly called out in the script comment (L140-142) and changelog as a bounded policy-gate cost, with the required pr-issue-linkage CI check remaining the real (server-side) enforcement backstop.
· branch fix/mcp-gate-defer-guard

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 13s —— View job


Code review complete ✅

  • Gather context (PR diff via gh pr diff 2068, CLAUDE.md/AGENTS.md, telemetry + hook-config-delivery docs)
  • Verify the two Codex P2 findings against the latest commit
  • Review pr-linkage-mcp-gate.sh defer-guard logic (full file read)
  • Review pr-linkage-mcp-gate.test.sh coverage
  • Review run-plugin-tests.sh, plugin.json, CHANGELOG.md
  • Post findings

No blocking issues. The follow-up commit (7de935b) already addresses both P2 findings Codex raised on 55981ea, and I independently verified both fixes against the actual downstream code and docs rather than taking the commit message at its word:

  • Exec-form args — pr-linkage-mcp-gate.sh#L143-L146 now scans (.command // empty), (.args[]? | strings) instead of .command alone. I checked this against docs/conventions/hook-config-delivery/README.md fact chore: initialize marketplace scaffold #1, which confirms exec-form hooks ({"command":"bash","args":[...]}) are a documented delivery shape — so the fix targets a real gap, not a hypothetical one. strings correctly filters non-string args elements before contains() would error on them, and // empty on a missing/null .command avoids the same class of error. New test at pr-linkage-mcp-gate.test.sh:110-113 exercises exactly this form.
  • Telemetry status — emit_tel_deferred (pr-linkage-mcp-gate.sh#L123-L130) now emits envelope status:"skipped" with data.outcome:"deferred", replacing the old emit_tel "deferred" call that put "deferred" in status itself. I read the actual reference sink (plugins/claude-ops/hooks/hook-telemetry-sink.sh#L57-L71) to confirm the bug Codex described was real: its case "$STATUS" maps any value outside ok|error|skipped|blocked to STATUS_OUT=error and EXIT_CODE=2 — so the pre-fix code really did record every successful defer as a hook failure. "skipped" is also the semantically correct choice per docs/conventions/hook-telemetry/README.md's documented status table ("the hook did not apply").
  • Defer-guard placement, fail-direction (malformed/missing settings.json → falls through to normal enforcement, not silent skip), and the three new test cases (command-form defers, exec-form defers, unrelated wiring still blocks) all trace correctly — the unrelated-wiring case reuses a body (NO_RELATED) that would otherwise block, so it actually proves the defer isn't a false pass.
  • run-plugin-tests.sh's widened find glob, the plugin.json version bump, and the CHANGELOG.md entry are all consistent and unremarkable.

One inline suggestion posted (non-blocking, test-coverage): none of the three new defer-guard tests assert on the actual telemetry envelope — they only check the hook's exit code. Since this PR's whole telemetry fix was about what value lands in status, and the sibling emit_tel "ok"/emit_tel "blocked" pattern right above emit_tel_deferred is an easy template to regress toward, I'd suggest one stub-sink test asserting status=="skipped" / data.outcome=="deferred", following the existing pattern in markdown-format.test.sh. See the inline comment on pr-linkage-mcp-gate.sh L123-130 for detail and a fix-this link.

Not independently re-verified (already covered by the two automated review passes earlier in this thread, and unchanged by the new commit): the security review's bounded-bypass analysis, and the author-claimed 22/0 · 17/0 suite results / shellcheck-clean claim — I did not execute the test suites or shellcheck myself in this pass either.
· branch fix/mcp-gate-defer-guard

A stub sink captures the envelope on a deferred call and the case asserts
status "skipped" with data.outcome "deferred" — the exact regression the
prior fix addressed (an unknown status maps to error in the reference
sink). Suite: 24/0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Fixed — a stub-sink capture case now asserts the deferral envelope carries status "skipped" and data.outcome "deferred" (suite 24/0), pinning the exact regression the status fix addressed.

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 15s —— View job


Security review complete ✅

  • Gather context (gh/local diff against origin/main, HEAD 22b90a3)
  • Read changed files in full
  • Analyze pr-linkage-mcp-gate.sh defer logic for trust-boundary / bypass issues
  • Analyze run-plugin-tests.sh changes
  • Analyze test file changes
  • Post findings

Scope: the 5 files changed in this PR at HEAD 22b90a3 — plugin.json (version bump), CHANGELOG.md, hooks/pr-linkage-mcp-gate.sh, hooks/pr-linkage-mcp-gate.test.sh, scripts/run-plugin-tests.sh. This supersedes my two earlier passes on 55981ea and 7de935b; the only delta since 7de935b is the new commit 22b90a3, which adds a stub-sink telemetry-envelope assertion to the test file — no production code changed.

No CRITICAL or IMPORTANT security issues found

  • The new test block (pr-linkage-mcp-gate.test.sh#L119-L140) is test-only: it points HOOK_TELEMETRY_SINK at a throwaway script under a mktemp -d workdir and asserts the captured envelope has status == "skipped" and data.outcome == "deferred". No new trust boundary — the sink path is process-local and not attacker-influenced, and this exercises emit_tel_deferred() (unchanged by this commit, already reviewed on 7de935b), not new logic.
  • pr-linkage-mcp-gate.sh itself is byte-for-byte the same defer-guard I reviewed on 7de935b: exec-form args[] inspection at L143-146, skipped-status telemetry at L123-130, fail-closed on malformed/missing settings.json (jq failure → falls through to enforcement, not silent skip). Both Codex P2 findings from the first commit remain fixed; nothing regressed them.
  • scripts/run-plugin-tests.sh's widened find plugins .claude/hooks -type f -name '*.test.sh' glob doesn't cross a new trust boundary — both trees require repo-commit access and both already run as trusted shell in CI.
  • plugin.json / CHANGELOG.md — version bump and prose only.

Named, accepted tradeoff (author-disclosed, unchanged by this commit, not a new finding): the contains("pr-linkage-mcp-gate") substring match over command/args still means any consumer command string containing that substring defers the plugin gate, including a same-named no-op script. This is explicitly documented in the script comment (L140-142) and the changelog as a bounded policy-gate cost; the required pr-issue-linkage CI check remains the real (server-side) enforcement backstop, unaffected by anything a local hook does.

No test-coverage or style commentary included per this review's scope (security only); my prior test-coverage suggestion on 7de935b (assert the telemetry envelope, not just exit code) is exactly what commit 22b90a3 now adds.
· branch fix/mcp-gate-defer-guard

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 25s —— View job


Code review complete ✅

  • Gather context (PR diff via gh pr diff 2068, CLAUDE.md/AGENTS.md, prior review threads)
  • Review pr-linkage-mcp-gate.sh defer-guard logic
  • Review pr-linkage-mcp-gate.test.sh coverage
  • Review run-plugin-tests.sh change
  • Review changelog/version bump
  • Post findings

Scope: this pass reviews HEAD 22b90a3 (the branch's latest commit, "test: assert the deferral telemetry envelope fields"), which lands the exact test the code-review lane suggested on the prior commit — I focused on what's new since then rather than re-litigating ground already covered by the security lane and earlier passes in this thread.

No blocking issues. The new telemetry-envelope test (pr-linkage-mcp-gate.test.sh:119-140) correctly closes the coverage gap flagged earlier: it stubs HOOK_TELEMETRY_SINK, captures the emitted envelope, and asserts both status == "skipped" and data.outcome == "deferred" — which is exactly the field split that matters, since the reference sink (plugins/claude-ops/hooks/hook-telemetry-sink.sh) maps any unrecognized status to error/exit 2. It also correctly reuses NO_RELATED (a body that would otherwise block) as the payload, so the assertion actually proves the defer path fires rather than the body happening to pass.

Two non-blocking suggestions posted inline:

  1. pr-linkage-mcp-gate.sh:121-130 — emit_tel_deferred duplicates most of emit_tel to get one behavioral difference (outcome deferred needs to ride status skipped). A second optional arg to emit_tel (emit_tel "deferred" "skipped") would collapse the two functions into one and leave only a single call site for any future status-mapping fix — notable because a status/outcome split is precisely the bug class Codex caught earlier in this same PR.
  2. pr-linkage-mcp-gate.test.sh:130-132 — the new sink-flush wait reimplements (with 10× coarser polling, same ~3s bound) the wait_for_sink() pattern already established in markdown-format.test.sh:107-118. Not a correctness issue, just a style inconsistency worth a note given this PR's own theme is "the two copies must not drift silently."

Both prior review-thread findings (Codex's exec-form-args gap and telemetry-status mapping) were verified fixed in commit 7de935b by earlier passes in this thread and remain correct at HEAD.

Not independently re-verified this pass (already covered by earlier passes in this thread, and unchanged since): the security-review's bounded-bypass analysis of the contains() substring match, and the author-claimed suite results (23/0 plugin, 17/0 repo-local) / shellcheck-clean / catalog-no-diff claims — I did not execute the test suites, shellcheck, or catalog regeneration myself in this session either.
· branch fix/mcp-gate-defer-guard

…k wait

Review suggestions: emit_tel now takes an optional status override
(emit_tel "deferred" "skipped") instead of a near-duplicate function; the
capture-wait polls in 20ms steps matching the established wait_for_sink
shape instead of a coarse 0.3s sleep. Suite: 24/0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Both suggestions applied: emit_tel gained an optional status-override parameter (emit_tel "deferred" "skipped") replacing the near-duplicate function, and the capture-wait now polls in 20ms steps matching the established wait_for_sink shape. Suite 24/0.

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 46s —— View job


Code review complete ✅

  • Gather context (diff across the PR's four commits, prior review threads in this PR)
  • Review the refactor commit (786e988) against the two non-blocking suggestions it targets
  • Re-check test coverage and control flow for regressions
  • Post findings

Scope: this pass reviews the delta introduced by the latest commit, 786e988 ("refactor: fold the deferred emitter into emit_tel and tighten the sink wait"), on top of 22b90a3 which earlier passes in this thread already reviewed. No new production logic beyond this refactor — pr-linkage-mcp-gate.sh's defer-guard placement, fail-direction, and exec-form/status fixes are unchanged from what was already reviewed on 7de935b/22b90a3.

No blocking issues. This commit is exactly what it says on the tin — it applies both non-blocking suggestions I left on the prior commit, and both are correctly done:

  1. emit_tel_deferred collapsed into emit_tel — pr-linkage-mcp-gate.sh#L116-L123 now takes an optional second status arg (${2:-$1}), and the defer call site becomes emit_tel "deferred" "skipped" (L140). I checked the other two call sites — emit_tel "ok" (L154) and emit_tel "blocked" (L165) — both omit the second arg, so ${2:-$1} correctly falls back to the outcome itself for those, which were already documented statuses; no behavior change there. Confirmed no leftover references to emit_tel_deferred anywhere in the tree (grep -rn emit_tel_deferred . returns nothing). This is a strict simplification — one function, one call site for any future status-mapping fix — with no semantic change to the telemetry envelope.
  2. Sink-wait polling tightened to match wait_for_sink — pr-linkage-mcp-gate.test.sh#L134 now polls 150× at 0.02s instead of 10× at 0.3s. I compared this against the actual helper it cites, wait_for_sink() in plugins/markdown-format/hooks/markdown-format.test.sh:107-118 — default tries=150 at sleep 0.02, i.e. an identical bound (3s total) and identical granularity. The consistency concern from the earlier review is fully resolved; the two copies no longer diverge in polling style, which is on-theme for a PR whose whole point is "the two copies must not drift silently."

Nothing else changed in this commit (CHANGELOG.md and plugin.json are untouched since 22b90a3, which is correct — this is an internal, behavior-neutral refactor of already-shipped 0.49.2 logic, not a new fix needing its own changelog entry).

Not independently re-verified this pass (already covered by earlier passes in this thread, and unchanged by this commit): the defer-guard's control flow, fail-direction, exec-form detection, and the security-review's bounded-bypass analysis of the contains() substring match. As in every prior pass in this thread, I was not able to get Bash execution approved in this session, so the author-claimed suite results (24/0 plugin) and shellcheck-clean claim remain author-claimed and unverified by me — my confidence here is from reading the diff and the referenced helper directly, not from running the tests.
· branch fix/mcp-gate-defer-guard

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 57s —— View job


Security review complete ✅

  • Gather context (git diff 22b90a3..786e988, prior review threads in this PR)
  • Read changed files in full
  • Analyze pr-linkage-mcp-gate.sh refactor (emit_tel_deferred folded into emit_tel) for trust-boundary / bypass issues
  • Analyze test file changes
  • Post findings

Scope: this PR is now at HEAD 786e988. The only delta since my last review pass (22b90a3) is commit 786e988, "refactor: fold the deferred emitter into emit_tel and tighten the sink wait" — a pure refactor addressing the two non-blocking maintainability/style suggestions from the earlier code-review pass. It touches only plugins/source-control/hooks/pr-linkage-mcp-gate.sh and plugins/source-control/hooks/pr-linkage-mcp-gate.test.sh.

No CRITICAL or IMPORTANT security issues found

  • pr-linkage-mcp-gate.sh#L111-L123 — emit_tel now takes an optional second status argument ("${2:-$1}"), and the defer call site becomes emit_tel "deferred" "skipped" (L140). This is behaviorally identical to the previous two-function version: data.outcome is still "deferred" and the envelope status is still the documented "skipped" value (not the unmapped "deferred" string the reference sink would coerce to error). No new trust boundary, no change to what's read, no change to the defer-guard's jq projection or its fail-closed behavior.
  • The defer-guard block itself (L125-141) is untouched by this commit — same command/args[] substring-contains scan over .claude/settings.json, same fallthrough-to-enforcement on malformed/missing settings, already reviewed on 7de935b and 22b90a3.
  • Test-file change (pr-linkage-mcp-gate.test.sh) only tightens the sink-flush poll from 10×0.3s steps to 150×0.02s steps (same ~3s bound). Test-only, no security surface.

Named, accepted tradeoff (author-disclosed, unchanged by this commit, not a new finding): the contains("pr-linkage-mcp-gate") substring match over command/args still means any consumer command/arg string containing that substring defers the plugin gate, including a same-named no-op script. Documented in the script comment (L131-133) and the changelog as a bounded policy-gate cost; the required pr-issue-linkage CI check remains the real server-side enforcement backstop, unaffected by anything a local hook does.

No test-coverage or style commentary included per this review's security-only scope; both maintainability suggestions from my prior code-review pass on 22b90a3 are exactly what commit 786e988 addresses.
· branch fix/mcp-gate-defer-guard

@kyle-sexton
kyle-sexton merged commit e6ee72e into main Aug 9, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the fix/mcp-gate-defer-guard branch August 9, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant