Skip to content

feat: harden MRTR workflows and defer Tasks - #386

Merged
mohanagy merged 7 commits into
developmentfrom
feat/366-mrtr-tasks
Aug 11, 2026
Merged

feat: harden MRTR workflows and defer Tasks#386
mohanagy merged 7 commits into
developmentfrom
feat/366-mrtr-tasks

Conversation

@mohanagy

@mohanagy mohanagy commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • bind approval continuations to the authenticated request-context correlation as well as the exact operation, profile, upstream, target, and arguments
  • record cancelled requests explicitly and prove upstream cancellation, request-scoped cleanup, and unchanged profile lock/lease state
  • exercise a real modern MRTR approval round trip through the installed npm tarball and reject cross-chat use plus replay
  • document why the experimental Tasks extension remains unimplemented for startup, OAuth, diagnostics, audit export, and recovery, with concrete reopen gates
  • make the continuation tamper test deterministic by changing a decoded signature byte and encoding it canonically

Acceptance evidence

  • supported TypeScript client + packed miftah serve --transport http: one elicitation, one upstream mutation, and requested / approved / consumed audit actions
  • a second authenticated chat cannot use the continuation with its own valid profile handle; the originating chat can consume it once
  • modern HTTP and stdio cancellation record cancelled / REQUEST_CANCELLED; the selected upstream receives cancellation and the request-scoped session closes
  • clients without form elicitation retain the existing fail-closed actionable fallback
  • Tasks have no selected Miftah use case, so durable task lookup is intentionally not applicable and no interoperability claim is made

Validation

  • npm test — 1,943 passed, 34 platform skips
  • npm run test:package
  • npm run build
  • npm run typecheck
  • npm run lint
  • npm run check:test-fixture
  • npm run check:pack
  • npm audit --omit=dev — 0 vulnerabilities
  • approval continuation test repeated 5 times

Fixes #366
Fixes #384

Summary by CodeRabbit

  • Security
    • Confirmation approvals are bound to the originating operation and authenticated context.
    • Invalid, altered, mismatched, or replayed approval continuations are rejected.
  • Enhancements
    • Added modern form-based confirmation flows with one-time continuation state.
    • Cancelled operations now produce clear cancellation outcomes and audit records.
  • Documentation
    • Documented confirmation workflows, audit outcomes, security requirements, and the decision not to implement Tasks.
  • Testing
    • Expanded end-to-end coverage for approvals, cancellations, audit logging, redaction, and protocol interoperability.

Fixes #387

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e2de10de-93ab-4f19-88dc-79adb284c9b5

📥 Commits

Reviewing files that changed from the base of the PR and between d15c291 and 14947d0.

📒 Files selected for processing (4)
  • docs/plans/2026-08-11-mrtr-tasks-decision.md
  • tests/mcp-v2-serving.test.ts
  • tests/mrtr-tasks-decision.test.ts
  • tests/stateless-profile-context-runtime.test.ts

📝 Walkthrough

Walkthrough

The change binds MRTR approval continuations to authenticated request context and exact operations. It adds explicit cancellation errors and audit status handling. Documentation defines the MRTR boundary and keeps Tasks unimplemented. Integration tests cover approval, replay, mismatch, cancellation, redaction, and audit behavior.

Changes

MRTR confirmation and lifecycle handling

Layer / File(s) Summary
Request-bound approval continuations
src/approvals/approval-store.ts, src/mcp/server/operation-pipeline.ts, src/mcp/server/miftah-server.ts, tests/approval-continuation-store.test.ts
Approval bindings include request correlation in signed state. Tests verify deterministic tamper rejection and cross-context rejection.
Cancellation error and audit lifecycle
src/utils/errors.ts, src/cli/exit-codes.ts, src/audit/audit-types.ts, src/mcp/server/..., tests/cli-exit-codes.test.ts, tests/mcp-v2-serving.test.ts, tests/mcp-wrapper.test.ts
Aborted operations produce REQUEST_CANCELLED, map to the operation exit code, close upstream sessions, and emit cancelled audit records.
Packaged MRTR HTTP validation
tests/package-contract.test.ts, tests/stateless-profile-context-runtime.test.ts
HTTP tests cover elicitation approval, request-context binding, replay rejection, redaction, single execution, and approval audit events.
MRTR boundary and supporting documentation
docs/config.md, docs/library-api.md, docs/plans/..., CHANGELOG.md, tests/mrtr-tasks-decision.test.ts, vitest.config.ts
Documentation and tests define MRTR confirmation semantics, fallback behavior, lifecycle outcomes, and the decision not to implement Tasks. The test timeout is platform-specific.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MCPClient
  participant MiftahHTTPServer
  participant OperationPipeline
  participant ApprovalStore
  participant AuditLog
  MCPClient->>MiftahHTTPServer: call confirmation-protected operation
  MiftahHTTPServer->>OperationPipeline: process operation
  OperationPipeline->>ApprovalStore: create request-bound continuation
  OperationPipeline-->>MCPClient: return input_required and requestState
  MCPClient->>MiftahHTTPServer: retry with inputResponses
  MiftahHTTPServer->>ApprovalStore: validate and consume continuation
  OperationPipeline->>AuditLog: record approval lifecycle
  OperationPipeline-->>MCPClient: return operation result
Loading

Possibly related PRs

  • mohanagy/miftah#379: Establishes the authenticated request context used for continuation binding.
  • mohanagy/miftah#380: Provides the stateless profile-context flow extended with request-bound continuations.
  • mohanagy/miftah#381: Provides the MCP SDK v2 serving and integration-test paths extended here.

Suggested labels: security, area:mcp, documentation

Poem

A rabbit signs each form with care,
And checks the matching context there.
Replays and mismatches meet “no”;
Cancelled paths close cleanly so.
MRTR forms guide the way,
While Tasks wait another day.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Docstring Coverage ❌ Error Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: MRTR workflow hardening and the decision to defer Tasks.
Description check ✅ Passed The description includes a focused summary and detailed validation evidence; security impact is covered but not under a separate heading.
Linked Issues check ✅ Passed The changes address the coding objectives in #366, #384, and #387, including MRTR security, deterministic tamper testing, cancellation, audit, and finite timeouts.
Out of Scope Changes check ✅ Passed The documentation, implementation, configuration, and tests are directly related to the linked MRTR, tamper-testing, and timeout-stability objectives.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/366-mrtr-tasks

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added area:mcp MCP protocol server and proxy behavior security Security, trust boundary, or credential-safety work labels Aug 11, 2026
coderabbitai[bot]
coderabbitai Bot previously requested changes Aug 11, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/plans/2026-08-11-mrtr-tasks-decision.md`:
- Line 54: Update the Tasks ownership requirements to include tasks/update
alongside tasks/get, tasks/result, and tasks/cancel, ensuring task lookup,
inputResponses updates, and cancellation enforce the same ownership check. Add a
corresponding ownership assertion in tests/mrtr-tasks-decision.test.ts.

In `@tests/mcp-v2-serving.test.ts`:
- Around line 63-85: Update waitForAuditEvent so malformed or partially written
JSONL lines are ignored during parsing rather than propagating SyntaxError.
Preserve valid parsed events and the existing ENOENT handling, allowing the next
polling iteration to discover the completed trailing line.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4dd8d3e9-e6bc-41b7-86fe-c10896715d2d

📥 Commits

Reviewing files that changed from the base of the PR and between 6efa9c7 and 3c77e23.

📒 Files selected for processing (17)
  • CHANGELOG.md
  • docs/config.md
  • docs/library-api.md
  • docs/plans/2026-08-11-mrtr-tasks-decision.md
  • src/approvals/approval-store.ts
  • src/audit/audit-types.ts
  • src/cli/exit-codes.ts
  • src/mcp/server/miftah-server.ts
  • src/mcp/server/operation-pipeline.ts
  • src/utils/errors.ts
  • tests/approval-continuation-store.test.ts
  • tests/cli-exit-codes.test.ts
  • tests/mcp-v2-serving.test.ts
  • tests/mcp-wrapper.test.ts
  • tests/mrtr-tasks-decision.test.ts
  • tests/package-contract.test.ts
  • tests/stateless-profile-context-runtime.test.ts

Comment thread docs/plans/2026-08-11-mrtr-tasks-decision.md Outdated
Comment thread tests/mcp-v2-serving.test.ts
coderabbitai[bot]
coderabbitai Bot previously requested changes Aug 11, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/plans/2026-08-11-mrtr-tasks-decision.md`:
- Line 54: Remove tasks/result from the task-method list in
docs/plans/2026-08-11-mrtr-tasks-decision.md at line 54, retaining tasks/get,
tasks/update, and tasks/cancel. Update the matching assertion in
tests/mrtr-tasks-decision.test.ts at line 26 to expect the same current
contract, since tasks/get returns terminal results.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 53dbe500-8722-4038-932f-65f51b8ba8cf

📥 Commits

Reviewing files that changed from the base of the PR and between 3c77e23 and c97a34b.

📒 Files selected for processing (3)
  • docs/plans/2026-08-11-mrtr-tasks-decision.md
  • tests/mcp-v2-serving.test.ts
  • tests/mrtr-tasks-decision.test.ts

Comment thread docs/plans/2026-08-11-mrtr-tasks-decision.md Outdated
@coderabbitai coderabbitai Bot added the documentation Improvements or additions to documentation label Aug 11, 2026
@mohanagy

Copy link
Copy Markdown
Owner Author

@coderabbitai review

All three actionable threads are addressed on exact head 665b3a8, including the current SEP-2663 method contract. Please submit a fresh review decision for this head.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

@mohanagy I will review pull request #386 at commit 665b3a8 and submit a fresh review decision.

⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mohanagy

Copy link
Copy Markdown
Owner Author

@coderabbitai review

Exact head d15c291 is green without reruns. All actionable review threads are addressed, including SEP-2663 methods and bounded fixture cleanup. Please submit a fresh review decision for this head.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

@mohanagy I will perform a fresh review of pull request #386 at head d15c291.

⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mohanagy

Copy link
Copy Markdown
Owner Author

@coderabbitai review

Please review exact head d15c291 and submit a fresh decision. All prior actionable findings are resolved, and exact-head CI passed every job without reruns.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

@mohanagy I will review pull request #386 at commit d15c2911849d852d3c7d996e9bfa08ab4c5e4a15 and submit a fresh decision.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/plans/2026-08-11-mrtr-tasks-decision.md (1)

28-28: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Correct the audit retention contract.

requestState, inputResponses, profile-context handles, and approval bearers remain excluded. Operation arguments are redacted and stored when audit.includeArguments is enabled; otherwise they are omitted. State that MRTR operation records follow this policy on every round, and add contract coverage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/2026-08-11-mrtr-tasks-decision.md` at line 28, Update the audit
retention contract near the audit journal description to state that MRTR
operation records apply the policy on every round: continue excluding
requestState, inputResponses, profile-context handles, and approval bearers;
redact and store operation arguments only when audit.includeArguments is
enabled, omitting them otherwise. Add contract coverage verifying these
retention rules.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docs/plans/2026-08-11-mrtr-tasks-decision.md`:
- Line 28: Update the audit retention contract near the audit journal
description to state that MRTR operation records apply the policy on every
round: continue excluding requestState, inputResponses, profile-context handles,
and approval bearers; redact and store operation arguments only when
audit.includeArguments is enabled, omitting them otherwise. Add contract
coverage verifying these retention rules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1cf83772-c7d1-47e9-9b4b-9159db2115c5

📥 Commits

Reviewing files that changed from the base of the PR and between e8ca072 and d15c291.

📒 Files selected for processing (4)
  • docs/plans/2026-08-11-mrtr-tasks-decision.md
  • tests/mcp-v2-serving.test.ts
  • tests/mrtr-tasks-decision.test.ts
  • vitest.config.ts

@mohanagy

Copy link
Copy Markdown
Owner Author

@coderabbitai review

Exact head 14947d0 now passes the complete CI matrix without retries, and the MRTR audit-retention finding has executable coverage in both argument modes. Please submit a consolidated fresh review decision for this exact head.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

@mohanagy I will review pull request #386 at commit 14947d035765c2932abfe50f7efcee64dd66427d and submit a fresh decision.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mohanagy
mohanagy dismissed stale reviews from coderabbitai[bot] and coderabbitai[bot] August 11, 2026 19:32

Superseded by exact head 14947d0: all findings addressed; exact-head CodeRabbit check and full CI matrix passed.

@mohanagy
mohanagy merged commit 6156927 into development Aug 11, 2026
12 checks passed
@mohanagy
mohanagy deleted the feat/366-mrtr-tasks branch August 11, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:mcp MCP protocol server and proxy behavior documentation Improvements or additions to documentation security Security, trust boundary, or credential-safety work

Projects

None yet

1 participant