Skip to content

fix(gateguard): deny same-batch siblings of a first-touch denial - #3938

Merged
haelyra merged 1 commit into
affaan-m:mainfrom
gaurav0107:fix/3936-gateguard-deny-same-file-siblings-of-a-f
Nov 19, 2026
Merged

haelyra merged 1 commit into
affaan-m:mainfrom
gaurav0107:fix/3936-gateguard-deny-same-file-siblings-of-a-f

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

What Changed

  • scripts/hooks/gateguard-fact-force.js: a first-touch denial now records batch_locks[<file key>] = { batch, at } in the same state write that marks the file checked. It does this only when the denied call's own tool_use_id is in the transcript, and batch is that call's assistant message id. A later Edit, Write, MultiEdit entry or NotebookEdit of the file is denied when its own tool_use_id is in the same batch. The denial says the earlier edit to the file in this batch was denied and that every edit to the file from the batch should be resent with the retry. When the lock is recorded, the first-touch denial (full and condensed) says the siblings are denied too, instead of "may already have been applied".
  • scripts/lib/gateguard-state.js: getBatchLocks / mergeBatchLocks / capBatchLocks, built like the dir_gates helpers: validated { batch, at } entries, null-prototype map, newest at wins on merge, capped at 50.
  • scripts/lib/gateguard-metrics.js, scripts/gateguard-report.js: new batch-deny decision, counted as a denial but not as a first touch.
  • docs/gateguard/design-notes.md: a new "Same-batch siblings" section, plus batch_locks under "State file is untrusted".
  • CHANGELOG entry under Unreleased / Changed.

Why This Change

As #3936 describes, the first-touch denial marks the file checked so the retry passes. That also let the other edits to the same file in that batch apply, which left tables without headers, code without its comment, and so on. Since #3136 the hook only warned. The comment said a batch cannot be locked, but gateguard-turn-scan.js already maps every tool_use_id to its assistant message id, so the lock the issue proposes is possible.

The lock needs the pending call to be found by its own tool_use_id. There is deliberately no fallback to the newest assistant message: a guessed batch could match the retry and deny it every time. With no tool_use_id, no transcript, or the call not in the transcript yet, nothing is locked and the #3136 warning still applies. The design notes now document this, as the issue asked. A same-batch denial does not add to fact_force_denials, so the denial cap and the condensed ordinals are unchanged. The transcript is read on a checked file only when a lock exists for its key, so checked edits keep the same lazy loading.

Fixes #3936

Testing Done

  • Automated tests pass locally: tests/hooks/gateguard-fact-force.test.js has 8 new cases. They cover: the sibling is denied, the denial count stays 1, and the retry and resent sibling from the next message pass; one record per tool_use sharing a message id counts as one batch; another file in the batch gets its own first-touch gate; with no tool_use_id, or the pending call missing from the transcript, nothing is locked; MultiEdit and NotebookEdit siblings are denied; a Write followed by an Edit in one batch is denied; the condensed denial carries the locked note on one line; malformed or __proto__ batch_locks entries are ignored. 5 of them fail on main. The 3 fail-open and validation cases pass on both, by design. tests/lib/gateguard-state.test.js gets a helper test, and the metrics enum test is updated.
  • node tests/run-all.js: the only failures also fail on main on this machine: audit-closed-references (page-two fixture), the gateguard supports multiple comma-separated exempt globs (Write + non-match) case, agent-payment-x402-seller-guard (no express in local node_modules), and the codex-hooks real-scanner cases (need ripgrep with PCRE2). All scripts/ci/* validators, npm run lint and npm run command-registry:check pass.
  • Edge cases considered and tested: see above. The existing gateguard: a parallel batch of edits is partially denied — dependent edits to one file can land without each other #3136 tests pass unchanged, because without a transcript nothing is locked.

Type of Change

  • fix: Bug fix

Security & Quality Checklist

  • No secrets or API keys committed (ghp_, sk-, AKIA, xoxb, xoxp patterns checked)
  • JSON files validate cleanly
  • Shell scripts pass shellcheck (if applicable): not applicable
  • Pre-commit hooks pass locally (if configured)
  • No sensitive data exposed in logs or output: batch_locks holds the canonical file key and a message id, the same kind of data checked already stores
  • Follows conventional commits format

Documentation

  • Updated relevant documentation (design notes, CHANGELOG)
  • Added comments for complex logic
  • skills/gateguard/SKILL.md not changed in this PR: its "Parallel Batches and Partial Application" section ("A batch-wide lock is not possible") and the metrics decision list should mention the lock and batch-deny. Any byte change to a SKILL.md makes the skill-triggers manifest stale (tests/ci/context-profiles.test.js), and the rebind is maintainer-owned. I'm happy to push that doc edit if you want it here.

🤖 Opened with Superhuman, an open-source contribution agent.

🤖 Generated with Claude Code

@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Security Evidence

Commit: 3896209976dfdf52d02827ad22fafb80529c6bff

Security scanner evidence required (action_required)

Detected 1 security-sensitive predictive risk signal(s) without scanner evidence.

Mode: enforce

Findings:

  • Security-sensitive changes may ship without scanner evidence: The PR touches billing, secrets, auth, webhooks, agent, or CI-sensitive surfaces without adding obvious security scanner, code scanning, or security-focused validation evidence. (2 security-sensitive paths changed; 0 security scanner or security-focused validation artifacts changed)

Touched security-sensitive paths:

  • scripts/hooks/gateguard-fact-force.js
  • tests/hooks/gateguard-fact-force.test.js

Expected evidence:

  • Security scanner, code scanning, secret scanning, dependency/security review, or focused security regression output.
  • SARIF/code-scanning upload or equivalent pass/fail gate for the changed surface.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / PR Risk Taxonomy

Commit: 3896209976dfdf52d02827ad22fafb80529c6bff

PR taxonomy review recommended (neutral)

Detected 3 PR taxonomy bucket(s): Security Evidence, Harness Drift, CI/CD Recommendation.

Scanned 9 changed file(s).

Roadmap taxonomy buckets:

Security Evidence

Security-sensitive changes should carry explicit scanner, code-scanning, or focused regression evidence.

Signals:

  • Security-sensitive changes may ship without scanner evidence
  • 0 security-sensitive path(s) changed

Paths:

  • CHANGELOG.md
  • docs/gateguard/design-notes.md
  • scripts/gateguard-report.js

Harness Drift

Harness-facing changes can drift across Claude Code, Codex, OpenCode, and shared adapter surfaces.

Signals:

  • Harness config changes may ship without compatibility evidence
  • 0 harness-facing path(s) changed

Paths:

  • CHANGELOG.md
  • docs/gateguard/design-notes.md
  • scripts/gateguard-report.js

CI/CD Recommendation

CI, dependency, coverage, and contract signals should be routed into follow-up checks or verification work.

Signals:

  • 3 CI or workflow path(s) changed

Paths:

  • tests/hooks/gateguard-fact-force.test.js
  • tests/lib/gateguard-metrics.test.js
  • tests/lib/gateguard-state.test.js

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Reference Set Readiness

Commit: 3896209976dfdf52d02827ad22fafb80529c6bff

Reference set readiness gaps detected (neutral)

Reference evidence present for 0/7 areas (0%) across 9 changed file(s).

This check is based on files changed in this PR. Repository-level readiness is still reported by /ecc-tools analyze comments and generated manifests.

Area Status Evidence / Next Step
Deep analyzer corpus Missing Add analyzer fixture, golden, benchmark, or reference-set files that can catch analyzer regressions.
RAG/evaluator comparison Missing Add retrieval or evaluator reference-set comparison fixtures with expected ranking behavior.
PR salvage/review corpus Missing Add stale-PR, review-thread, reopen-flow, or salvage reference cases for queue cleanup automation.
Discussion triage corpus Missing Add public discussion triage fixtures, golden cases, or reference sets for informational, answered, and no-response classifications.
Harness compatibility Missing Add cross-harness, adapter-compliance, or harness-audit evidence for Claude, Codex, OpenCode, Zed, dmux, and agent surfaces.
Security evidence Missing Attach security evidence such as SBOMs, SARIF, audit reports, or AgentShield evidence packs.
CI failure-mode evidence Missing Add captured CI failure logs, dry-run fixtures, or troubleshooting docs for common workflow failure modes.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Hosted Promotion Readiness

Commit: 3896209976dfdf52d02827ad22fafb80529c6bff

Hosted promotion readiness passed (success)

No hosted promotion evidence gaps detected across 9 changed file(s); 0 corpus scenarios had matching evidence.

This check compares PR file changes against the evaluator/RAG promotion corpus in src/analyzers/fixtures/evaluator-rag-corpus.ts.
Hosted output scoring inspected 0 completed cached hosted job results.

No evaluator corpus scenarios matched this PR.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

A first-touch denial marks its file checked so the retry passes, which
also let the other edits to that file in the same parallel batch apply
and left the file half-edited (affaan-m#3136 only warned about this).

When the denied call's own tool_use_id is found in the transcript, the
denial now records the batch (assistant message id) for that file in
the same state write. A later Edit/Write/MultiEdit/NotebookEdit of the
file from that batch is denied with a message that says to resend every
edit with the retry. Calls from any other message pass, including the
retry. There is no newest-message fallback, so a guessed batch can never
deny the retry; without a located batch the affaan-m#3136 warning still applies.

Same-batch denials are recorded as the new `batch-deny` metrics
decision and do not count toward fact_force_denials. batch_locks is
validated on read, merged by newest `at` and capped at 50 entries.

Fixes affaan-m#3936

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gaurav0107
gaurav0107 force-pushed the fix/3936-gateguard-deny-same-file-siblings-of-a-f branch from 3896209 to b2fa2d9 Compare November 15, 2026 04:08
@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Security Evidence

Commit: b2fa2d93eed9e138b4a60fd4ac5bf9b96b8f2ca7

Security scanner evidence required (action_required)

Detected 1 security-sensitive predictive risk signal(s) without scanner evidence.

Mode: enforce

Findings:

  • Security-sensitive changes may ship without scanner evidence: The PR touches billing, secrets, auth, webhooks, agent, or CI-sensitive surfaces without adding obvious security scanner, code scanning, or security-focused validation evidence. (2 security-sensitive paths changed; 0 security scanner or security-focused validation artifacts changed)

Touched security-sensitive paths:

  • scripts/hooks/gateguard-fact-force.js
  • tests/hooks/gateguard-fact-force.test.js

Expected evidence:

  • Security scanner, code scanning, secret scanning, dependency/security review, or focused security regression output.
  • SARIF/code-scanning upload or equivalent pass/fail gate for the changed surface.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / PR Risk Taxonomy

Commit: b2fa2d93eed9e138b4a60fd4ac5bf9b96b8f2ca7

PR taxonomy review recommended (neutral)

Detected 3 PR taxonomy bucket(s): Security Evidence, Harness Drift, CI/CD Recommendation.

Scanned 9 changed file(s).

Roadmap taxonomy buckets:

Security Evidence

Security-sensitive changes should carry explicit scanner, code-scanning, or focused regression evidence.

Signals:

  • Security-sensitive changes may ship without scanner evidence
  • 0 security-sensitive path(s) changed

Paths:

  • CHANGELOG.md
  • docs/gateguard/design-notes.md
  • scripts/gateguard-report.js

Harness Drift

Harness-facing changes can drift across Claude Code, Codex, OpenCode, and shared adapter surfaces.

Signals:

  • Harness config changes may ship without compatibility evidence
  • 0 harness-facing path(s) changed

Paths:

  • CHANGELOG.md
  • docs/gateguard/design-notes.md
  • scripts/gateguard-report.js

CI/CD Recommendation

CI, dependency, coverage, and contract signals should be routed into follow-up checks or verification work.

Signals:

  • 3 CI or workflow path(s) changed

Paths:

  • tests/hooks/gateguard-fact-force.test.js
  • tests/lib/gateguard-metrics.test.js
  • tests/lib/gateguard-state.test.js

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Reference Set Readiness

Commit: b2fa2d93eed9e138b4a60fd4ac5bf9b96b8f2ca7

Reference set readiness gaps detected (neutral)

Reference evidence present for 0/7 areas (0%) across 9 changed file(s).

This check is based on files changed in this PR. Repository-level readiness is still reported by /ecc-tools analyze comments and generated manifests.

Area Status Evidence / Next Step
Deep analyzer corpus Missing Add analyzer fixture, golden, benchmark, or reference-set files that can catch analyzer regressions.
RAG/evaluator comparison Missing Add retrieval or evaluator reference-set comparison fixtures with expected ranking behavior.
PR salvage/review corpus Missing Add stale-PR, review-thread, reopen-flow, or salvage reference cases for queue cleanup automation.
Discussion triage corpus Missing Add public discussion triage fixtures, golden cases, or reference sets for informational, answered, and no-response classifications.
Harness compatibility Missing Add cross-harness, adapter-compliance, or harness-audit evidence for Claude, Codex, OpenCode, Zed, dmux, and agent surfaces.
Security evidence Missing Attach security evidence such as SBOMs, SARIF, audit reports, or AgentShield evidence packs.
CI failure-mode evidence Missing Add captured CI failure logs, dry-run fixtures, or troubleshooting docs for common workflow failure modes.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Hosted Promotion Readiness

Commit: b2fa2d93eed9e138b4a60fd4ac5bf9b96b8f2ca7

Hosted promotion readiness passed (success)

No hosted promotion evidence gaps detected across 9 changed file(s); 0 corpus scenarios had matching evidence.

This check compares PR file changes against the evaluator/RAG promotion corpus in src/analyzers/fixtures/evaluator-rag-corpus.ts.
Hosted output scoring inspected 0 completed cached hosted job results.

No evaluator corpus scenarios matched this PR.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@haelyra
haelyra merged commit 66d1ff3 into affaan-m:main Nov 19, 2026
1 check passed
@haelyra

haelyra commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Thank you for denying same-batch siblings after a correlated first-touch denial. We merged your original commit history through #4048 so the related changes could be tested together. The maintainer pass aligns the canonical guidance and metrics with the conditional same-file batch lock, including the missing-transcript limitations.

The resulting main commit fbb1a85c59a8468c96454fc5b48cf7e4f8f79b55 passed CI, CodeQL, and Supply-Chain Watch. Thank you for helping improve ECC!

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.

gateguard: deny same-file siblings of a first-touch denial by batch id (follow-up to #3136)

2 participants