Repository navigation
feat(mcp): require approval for destructive batch record writes - #507
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Shadow risk calibration
Calibration result: agreement. Shadow risk never blocks or enables merge. Keep it in observation mode until roughly 50 pull requests have human-reviewed labels, then calibrate before considering any policy use. |
261f406 to
562e605
Compare
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
| failed: unreadable, | ||
| not_attempted: notRead, | ||
| }; | ||
| if (counts.losing === 0) return { additive: preview }; |
There was a problem hiding this comment.
Changed batches skip approval checks
On a mixed batch's confirmation call, counts.losing can become zero because the destructive record now fails to read or another user cleared it. The additive branch then writes without checking the token or comparing the approved state. A record that matched during preview can become empty and get filled without returning stale_preview.
Keep checking the full batch state when confirmation_token or requestState is present. Only fresh additive calls should skip approval.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/mcp/src/tools/record-writes.ts
Line: 626
Comment:
**Changed batches skip approval checks**
On a mixed batch's confirmation call, `counts.losing` can become zero because the destructive record now fails to read or another user cleared it. The additive branch then writes without checking the token or comparing the approved state. A record that matched during preview can become empty and get filled without returning `stale_preview`.
Keep checking the full batch state when `confirmation_token` or `requestState` is present. Only fresh additive calls should skip approval.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const binding: ConfirmationBinding = { | ||
| tool: plan.tool, | ||
| args, | ||
| accountId: await context.accountId(), | ||
| credentialHash: await context.credentialKey(), | ||
| channel: channel.kind, | ||
| }; |
There was a problem hiding this comment.
Identity reads exceed the deadline
The new calls to accountId() and credentialKey() run outside the batch deadline. API-key calls without a gateway account need /me for accountId(), and user or agent calls need it for credentialKey(). A slow /me can hold a destructive preview or confirmation past the gateway's 20-second budget and 30-second function limit, leaving the caller with a timeout instead of a result.
Bound these required lookups by the remaining request budget and return without writing when it expires.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/mcp/src/tools/write-kit.ts
Line: 828-834
Comment:
**Identity reads exceed the deadline**
The new calls to `accountId()` and `credentialKey()` run outside the batch deadline. API-key calls without a gateway account need `/me` for `accountId()`, and user or agent calls need it for `credentialKey()`. A slow `/me` can hold a destructive preview or confirmation past the gateway's 20-second budget and 30-second function limit, leaving the caller with a timeout instead of a result.
Bound these required lookups by the remaining request budget and return without writing when it expires.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const read = await forEachRecord( | ||
| plan.ids, | ||
| (id) => plan.planRecord(id), | ||
| readDeadlineAt, | ||
| ); | ||
| planned = read.done; | ||
| unreadable = read.failed; | ||
| notRead = read.not_attempted; | ||
| if (read.rateLimit !== undefined) { |
There was a problem hiding this comment.
Read limits still allow writes
This branch only sees a 429 after the SDK finishes its automatic GET retries, which the real server leaves enabled. If a record read receives Retry-After: 30, the roughly 10-second read budget expires first. The record becomes not_attempted, read.rateLimit stays unset, and other records can still be written. The response also loses the API's requested wait.
Make batch reads expose 429 immediately, or pass the rate-limit signal through before retrying, so the batch stops writes and preserves Retry-After.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/mcp/src/tools/record-writes.ts
Line: 568-576
Comment:
**Read limits still allow writes**
This branch only sees a 429 after the SDK finishes its automatic GET retries, which the real server leaves enabled. If a record read receives `Retry-After: 30`, the roughly 10-second read budget expires first. The record becomes `not_attempted`, `read.rateLimit` stays unset, and other records can still be written. The response also loses the API's requested wait.
Make batch reads expose 429 immediately, or pass the rate-limit signal through before retrying, so the batch stops writes and preserves `Retry-After`.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Destructive
set_party_roleandset_custom_fieldcalls now preview every planned change and require approval. Purely additive calls still run immediately, including without a confirmation secret. Mixed batches wait as a whole; approvals bind every record read, including unchanged records. Preserve the existing per-record result shape and gateway deadline.Second part of #451 / DEV-14372, based on #506. Includes token and form-elicitation wiring, party-ID validation, custom-field
updated_atand role-assignment replay protection, tracking-create auditing, and fixture-backed transport tests. Original author: Akshay Dodeja.Also resolves the outstanding #451 batch-429 review finding: stop starting further writes, retain Retry-After and partial results, release approval only if no write succeeded or may have applied. Five regression tests cover read limits, fully refused retries, partial success, untouched records, and an attach succeeding before a rate-limited detach.
Deployment: set
T49_MCP_CONFIRMATION_SECRET(at least 32 characters) on the HTTP gateway before deploying. Destructive writes fail closed without it; stdio generates a process-local secret when none is configured.Validation: full
npm run agent-verify; separately, 37 real gateway-handler tests pass. No live account writes performed. Lifecycle tools remain in the next PR.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Review order: #506 → #507 → #508 → #509. Each diff is against its predecessor; #509 is the combined QA target.
Follow-up review: Starting tracking now explicitly warns about tracking quota and possible pay-as-you-go charges, and advertises client interaction despite remaining additive/non-destructive. Clients own approval UI; metadata does not guarantee a prompt. Concurrent record edits between preview/read and save remain possible because backend writes are unconditional.
Fix the batch confirmation checks, unbounded identity reads, and hidden read limits before merging.
Fix with agent prompt
Summary
Adds approval previews for destructive
set_party_roleandset_custom_fieldbatches while keeping additive calls immediate.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Read batch records] --> B{Any destructive change?} B -->|No| C[Write additive changes] B -->|Yes| D[Build account and credential binding] D --> E{Approval supplied?} E -->|No| F[Return preview or ask client] F --> A E -->|Yes| G[Check token and batch state] G -->|Changed| F G -->|Matches| H[Reserve approval and write] H --> I[Return per-record results and audit]Reviews (1) · Last reviewed commit: "fix(mcp): flag tracking quota and billin..." · Reviewed by Greptile