Skip to content

Reject task_claim_file on protected branches at MCP layer#496

Merged
NagyVikt merged 1 commit intomainfrom
agent/claude/task-claim-file-protected-branch-guard-2026-05-08-19-34
May 8, 2026
Merged

Reject task_claim_file on protected branches at MCP layer#496
NagyVikt merged 1 commit intomainfrom
agent/claude/task-claim-file-protected-branch-guard-2026-05-08-19-34

Conversation

@NagyVikt
Copy link
Copy Markdown
Collaborator

@NagyVikt NagyVikt commented May 8, 2026

Summary

  • task_claim_file now returns PROTECTED_BRANCH_CLAIM_REJECTED when the task's branch is a protected base branch (main/master/dev/develop/production/release).
  • Previously guardedClaimFile returned protected_branch_rejected (gated by rejectProtectedBranchClaims: true, the default) but the MCP handler at apps/mcp-server/src/tools/task.ts fell through all status checks and silently recorded the claim anyway. This closes that gap.
  • PROTECTED_BRANCH_CLAIM_REJECTED added to TASK_THREAD_ERROR_CODES in packages/core/src/task-thread.ts.
  • Two new integration tests in apps/mcp-server/test/task-threads.test.ts (isolated describe block with its own store/server using rejectProtectedBranchClaims: true to avoid disturbing the existing false fixture setup).

Closes

Planned-work memory entry project_protected_branch_claim_reject.md — MCP-layer guard to block claims on main/dev from primary checkout. CLAUDE.md rule #12 enforcement.

Note

The same guardedClaimFile call inside task_plan_claim_subtask (apps/mcp-server/src/tools/plan.ts) has the identical gap. That is intentionally out of scope for this PR.

Test plan

  • pnpm --filter @colony/core typecheck — clean
  • pnpm --filter @colony/mcp-server typecheck — clean
  • Full mcp-server test suite: 244 passed (includes 2 new protected-branch tests)
  • New test rejects task_claim_file with PROTECTED_BRANCH_CLAIM_REJECTED when task branch is main confirms error code and no claim row written
  • New test allows task_claim_file when task branch is an agent/* branch confirms success path unaffected

🤖 Generated with Claude Code

guardedClaimFile already returned protected_branch_rejected but the
handler fell through and recorded the claim silently. Now checks for
that status and returns PROTECTED_BRANCH_CLAIM_REJECTED with a
message directing the agent to start a sandbox worktree first.

Adds PROTECTED_BRANCH_CLAIM_REJECTED to TASK_THREAD_ERROR_CODES and
two integration tests covering the reject and allow paths.

Closes planned-work note: project_protected_branch_claim_reject.md
CLAUDE.md rule #12 enforcement at the MCP boundary.
@NagyVikt NagyVikt merged commit e6c5766 into main May 8, 2026
1 of 3 checks passed
NagyVikt added a commit that referenced this pull request May 8, 2026
The "Storage at rest (per observation)" reference row claimed
1000→300 tokens of compression savings and mapped to live
savings_report calls. savings_report emits structured JSON
(~3.5k tokens per call) that the caveman compressor leaves
byte-for-byte (rule #3: technical tokens preserved). The live
comparison projected the row's 1k baseline against ~3.5k actual
tokens and reported negative savings like -155% in colony gain.

The compression claim itself is real for prose observations, so
the row stays in the static reference. But the claim is structural
(applies to the storage layer overall), not per-call. Setting
`mcp_operations: []` keeps the row in the static catalog and
removes the misleading live attribution. savings_report calls
now surface in `unmatched_operations` instead.

Picks up an automatic biome format fix on
apps/mcp-server/test/task-threads.test.ts that #496 left over the
column threshold.

Verification:
- pnpm --filter @colony/core test (230 passed, +1 new regression test)
- pnpm typecheck (clean)
- pnpm lint (clean)

Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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