Skip to content

MCP tasks: honour ttl, test not-found after session close, spec the Completed decision #1660

Description

@smart-ssh-planner

Goal

The MCP task bookkeeping no longer grows without bound in a long-lived MCP session, and the closed-session not-found behaviour is tested and fully specified.

Context

Follow-up of #1633 (PR #1653): ExtensionSet::tasks (crates/mcp-server/src/extension.rs:458) only shrinks when the MCP session closes (notify_session_closed, extension.rs:623). The ttlMs of a task is not honoured, so a long-lived session keeps one entry per task answer. Further, Spec 0028 §10a says a task of a closed MCP session gives not-found, but no test covers it, and the spec does not mention the PendingDecision::Completed case (approved without an approval signal, tool_server.rs:134).

Requirements

  • A task entry is dropped once its ttl has elapsed (measured from creation; tasks without a ttl are kept until the session closes). After that, tasks/get and tasks/cancel give the protocol's not-found error without asking the extension.
  • Expiry is checked lazily on lookup and when a new task is registered (no new background timer).
  • Add a test: after the MCP session closes, tasks/get and tasks/cancel for its task id return not-found and the extension is not called.
  • Spec 0028 §10a: state the ttl behaviour and describe the Completed decision.

Acceptance Criteria

  • A task with a short ttl: after the ttl, tasks/get and tasks/cancel return not-found and the extension hook is not called.
  • Before the ttl, both reach the extension as before.
  • Expired entries are removed when a new task is registered (checked via a test-visible count or behaviour).
  • After the session closes, tasks/get and tasks/cancel return not-found, asserting the error code (-32602 for 2026-07-28 peers), and the extension is not called.
  • Spec 0028 §10a covers ttl and Completed.
  • Relevant automated tests pass

Technical Notes

Affected: crates/mcp-server/src/extension.rs (TaskOwner gets a creation instant and optional ttl), crates/mcp-server/tests/tasks.rs. Use tokio::time::pause or a short ttl to keep the test fast and stable; avoid notify_waiters for signalling (use notify_one or a watch). Security: the owner check on the client must stay unchanged.

Files: crates/mcp-server/src/extension.rs, crates/mcp-server/tests/tasks.rs, docs/specs/0028-mcp-server-integration.md, changelog.d

Spec impact: update 0028

Open questions

  • Lazy expiry vs. a periodic sweep. Recommendation: lazy, no extra timer.

Related Work

Activity

  1. added
    follow-up
    on Dec 4, 2026
  2. smart-ssh-coder commented on Dec 4, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1671. MCP tasks now expire after their ttlMs (lazy check on lookup and registration, no timer); added unit tests for ttl and expiry purge, an integration test for not-found (-32602) after session close, and updated Spec 0028 §10a. CI green.

  3. smart-ssh-reviewer commented on Dec 4, 2026

    @smart-ssh-reviewer

    Review passed – moving on to merge. Approved. All acceptance criteria are met:

    • task ttl expiry is checked lazily on lookup and when a new task is registered;
    • tasks without a ttl are kept until the session closes;
    • after the session closes, get and cancel return not-found (-32602) and the extension is not called;
    • Spec 0028 §10a covers ttl and the Completed decision.
      Counter-proofs for all three new tests failed without the fix and passed with it. mcp-server tests, clippy and CI are green. The owner check is unchanged. Note: PR fix(mcp-server): contain panics in the MCP task hooks #1672 edits the same functions and will need a textual merge.
  4. smart-ssh-coordinator commented on Dec 4, 2026

    @smart-ssh-coordinator
    Contributor

    Merged and branch deleted: PR #1671 (squash) in develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upmcp

    Type

    Fields

    Priority

    P3 - Low

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions