Repository navigation
fix(mcp-server): contain panics in the MCP task hooks - #1672
smart-ssh-coordinator[bot] merged 5 commits into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated (issue label security; crates/mcp-server/ is a security-critical path)
Blocking
- Merge conflict with
develop(GitHub:CONFLICTING). Since this branch was cut,developgained #1657 (per-extensioncommand_hook_timeout) and #1660 (task TTL / not-found after session close). Both reworkcrates/mcp-server/src/extension.rsand thetests/tasks.rsharness (start_server_withtakesOption<TaskExt>again, and there is a newstart_server_set). Please merge the base and resolve the conflicts. After the merge,answer_as_task,task_statusandcancel_taskmust still be wrapped incontain_panicinside whatever timeoutdevelopuses now. Re-run the three new tests after the merge. crates/mcp-server/tests/tasks.rs:574-588(test_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usable): AC 3 asks for "the protocol's not-found error", but the test only assertsis_err(). Any error passes: an internal error, a transport error, or a different code. Please assert that both errors carry the not-found code thattask_not_found()produces (McpError::resource_not_found, i.e.ErrorCode::RESOURCE_NOT_FOUND).- AC 4 ("the log entry contains no content of the panic message") has no test for the three new hooks. The PR says "met by construction". The code does read correctly:
contain_panicdrops the payload, and the warnings are constant strings. But the only test-side check is!text(&result).contains("secret-panic-payload")in the first test, which checks the tool result, not the log. The crate already has a log-capture pattern for exactly this (extension.rs, unit test foron_session_closed, which asserts a line withpanicked in on_session_closedand nosecret-panic-payload; helper incrates/mcp-server/src/test_support.rs). Please add the same check foranswer_as_task,task_statusandcancel_task: the warning is logged withoriginmcp, and the payload never appears.
Non-blocking
- PR body:
Threat model: no change – the existing panic sentence covers extension hooks generally.THREAT-MODEL.mdhas no MCP panic sentence; the only panic mention, at line 345, is about observers. The conclusion itself holds: no new surface, a panic only yieldsNone/not-found/false, and "nothing runs without approval" is unchanged. Please correct the stated reason. - Without the fix, tests 2 and 3 hang (I stopped them at 300 s) instead of failing, because
task_of/get_taskhave no timeout. Wrapping them intokio::time::timeoutwould make a regression fail fast with a clear message. tasks.rs:540assert!(!call.is_finished())is a weak check: it is true on a fast runner regardless of the fix. The real proof is the later"finished"result. This is harmless.
Verified
- files read: 2/2 logic files (
crates/mcp-server/src/extension.rsdiff pluscontain_panicand the trait defaults;crates/mcp-server/tests/tasks.rsdiff plus the test backend), andtool_server.rsget_task/cancel_task(read) - counter-proof (executed: restored
extension.rsfromorigin/develop, ran each new test, then restored HEAD; the worktree is clean again):test_panicking_answer_as_task_still_waits_for_core_outcome→ FAILED ("call hung") without the fix, passes with ittest_second_extension_answers_after_first_panics_in_answer_as_task→ hangs without the fix (stopped at 300 s), passes with ittest_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usable→ hangs without the fix (stopped at 300 s), passes with it
- tests run locally:
cargo test --locked -q -p mcp-server→ 54 passed, 0 failed (executed);cargo fmt --all --check→ ok (executed) - CI: all checks green on head
24d8fbf9(gh pr checks). The PR is now in conflict with the base, so CI will run again after the merge. - edge cases (read):
- panic in the first of two extensions → the second is asked (test 2) → ok
- panic in the only extension → the core path decides; the call returns
"finished"only aftergate/finish→ ok - panic → the task is not inserted into the task map; the insert only happens on
Ok(Ok(Some))→ ok - panic while the
tasksmutex is held → not possible; the lock is not held across the hook → ok - panic →
tasks/cancelreturnsfalse→ not-found, neverOk→ ok
- callers checked (read):
ExtensionSet::answer_as_task(propose_command path intool_server.rs),task_status(get_task, 1 call site),cancel_task(cancel_task, 1 call site). Return types are unchanged → ok - UI: not a UI change
- data: not touched
Timing analysis
- 1 test file analysed (3 new tests and the harness change): no timing dependency found.
tasks.rs:540is_finishedassertion: weak but not flaky (possible) → non-blocking, listed above. Thenotify_onepermits are correct for the ordering.
Spec
- visible behaviour changed: a panicking extension in the task hooks now yields "no answer" / "not found" instead of breaking the call or the request.
- spec searched (
rg -il 'panic|abgestürzt' docs/specs/); the area is covered by 0028 §10a ("Fehlerhafte Erweiterung") - verdict: the spec change is present and matches the code (task answer → next extension or core;
tasks/get/tasks/cancel→ not found; the log contains no panic content). The changelog fragment is present, in English and user-facing.
Security checks
- Loosening (elevated,
extension.rs): the only change is extra wrapping incontain_panic. The timeout is unchanged, and no new path leads toSome/true. Before this PR, a panic propagated into the request; now it maps toNone/false. That is strictly tighter, and I found no input that is now accepted that was refused before. - Bypass attempts (checked against the code):
- panic after partially building an answer → dropped
- panic in the first extension combined with a second extension returning a duplicate task id → the existing duplicate check still applies
- panic in
task_statusfor another session's id →task_ownerrefuses first - panic payload that contains secrets → never formatted
- panic in
cancel_task→ never reported as a successful cancel - a hang plus a panic → the timeout still applies, because
contain_panicis insidetimeout
- Invariants: no AutoExec, no filter bypass, no pending decision turned into an approval (AC 5, shown by test 1: the call waits for the gate). No unredacted content is added to logs.
- Threat model: no change is justified, but the stated reason is inaccurate (see non-blocking).
Previous findings (follow-up round only)
- not applicable (first round)
Follow-ups
None.
…-hook panics (#1659) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…-panics-in-the-mcp-task-hooks
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated (issue label security; crates/mcp-server/src/extension.rs, crates/mcp-server/tests/tasks.rs)
Blocking
crates/mcp-server/tests/tasks.rs:661-663(test_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usable). AC 3 requires "a following built-in tool call on the same session works". The test sendslist_tools(atools/listrequest), not a tool call. So nothing shows thattools/callstill goes through the tool server on that session after the two panics. A related request does not stand in for the criterion. Fix: after the two not-found assertions, make a real built-in tool call on the sameclient(for exampleclient.call_tool(propose("run"))orlist_servers) and assert its result, not justis_ok().
Non-blocking
- Two of the new integration tests (
test_second_extension_answers_after_first_panics_in_answer_as_task,test_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usable) still hang when the fix is removed instead of failing (see counter-proof below). Round 1 already noted this. Wrappingtask_of/get_task/cancel_taskintokio::time::timeoutwould make them fail quickly. Test quality only, no behaviour change.
Verified
- files read: 2/2 logic files (
extension.rs,tasks.rs) in full in the diff, pluscontain_panic/HookPanickedand the existing not-found tests for context (read) - counter-proof (executed): I replaced
contain_panic(...)inanswer_as_task,task_statusandcancel_taskwith a pass-throughasync { Ok(hook.await) }. Results:test_panicking_answer_as_task_still_waits_for_core_outcomefails with "call hung".test_second_extension_answers_after_first_panics_in_answer_as_taskandtest_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usablehang (killed bytimeout 300).extension::tests::test_task_hook_panics_log_a_warning_without_payloadfails.- After
git checkout --, all pass again.
- not-found code (read:
rmcp-3.9.0/src/handler/server.rs:325): rmcp sendsRESOURCE_NOT_FOUNDto 2026-07-28 peers asINVALID_PARAMS(-32602). This matches the existing #1660 test, so assertingINVALID_PARAMSplus"task not found"is correct. - edge cases (read):
- Panic in
answer_as_task: no task-map entry is inserted (insertion only onOk(Ok(Some))), and the next extension is asked → ok. - Panic after the hook entered (state recorded before the panic) → the
Statemutex is not poisoned → ok. - The timeouts are still the current ones (
HOOK_TIMEOUTaroundcontain_panic) → ok. - The workspace has no
panic = "abort"profile, socatch_unwindtakes effect → ok.
- Panic in
- AC 5 (read + executed): after a panic in
answer_as_taskthe call keeps waiting on the core outcome (assert!(!call.is_finished())until the gate is released). A panic only maps toNone/None/false, never to an approval. - callers checked (read):
answer_as_task,task_statusandcancel_taskonExtensionSetkeep their signatures and return values, sotool_server.rsis unchanged → ok. - tests run locally (executed):
cargo test --locked -q -p mcp-server→ 66 passed (lib 38, extension 11, integration 5, tasks 12) - CI (executed:
gh pr checks 1672): all green, includingthreat-model-note - UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed (
tasks.rs,extension.rstest module): no timing dependency found. The log capture is serialised byCAPTURE_LOCK; the busy-wait onanswered_callsis bounded at 20 s; there are no fixed sleeps.
Spec
- visible behaviour changed: a panicking MCP extension in the task hooks now counts as "no answer" / "not found" instead of breaking the call
- spec searched:
rg -il 'tasks/get|answer_as_task|Aufgaben-Hook|Fehlerhafte Erweiterung' docs/specs/→ 0028 (and unrelated 0045) - verdict: the spec change is present (0028 §10a, "Fehlerhafte Erweiterung" extended to the task hooks) and matches the code. The changelog fragment is present and in English.
Security checks
-
Invariants: no filter bypass and no new action type. A panic never becomes an approval (it maps to
None/false). The panic payload is never logged (unit test asserts it). There is no fail-open into execution: when the task hook fails, the call falls back to the core confirmation wait. -
Loosening (read, previous vs. new for all three hooks): the timeout arms are unchanged, and the new arms only add a mapping for
HookPanicked. No check is weaker. -
Bypass attempts considered (read against the code):
- panic in the first extension with a task from the second
- panic in
task_statusfor a task owned by another session (blocked earlier bytask_owner) - panic in
cancel_taskafter a partial cancellation (returnsfalse, no core action cancelled or approved) - a panic payload with secret content (dropped unread)
- a hook that panics only after a slow await (still inside the timeout)
All handled.
-
Threat model:
Threat model: no changewith the reason "THREAT-MODEL.md has no statement on MCP extension hook panics" (read:grep -n panic THREAT-MODEL.md, only an unrelated observer note). The reason holds.
Manual checks pending
- None.
Previous findings (follow-up round)
- Merge conflicts with develop → fixed in db9d575 / ec6653a.
contain_panicsits inside the currentHOOK_TIMEOUTfor all three hooks. - AC 3: the not-found code was not asserted → fixed. Code
INVALID_PARAMSand message"task not found"are now asserted for bothget_taskandcancel_task. - AC 4: there was no log-capture test → fixed:
extension.rs:test_task_hook_panics_log_a_warning_without_payload. Verified red without the fix. - Threat model reason (non-blocking) → fixed.
- Timeouts so tests fail instead of hanging (non-blocking) → still open for two tests, see Non-blocking.
Follow-ups
- None.
…l after panicking task hooks (#1659) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Review follow-up: AC 3 test now makes a real built-in tool call ( |
There was a problem hiding this comment.
Review
Verdict: approved
Review level: elevated (issue label security; crates/mcp-server/src/extension.rs, crates/mcp-server/tests/tasks.rs)
Blocking
- None.
Non-blocking
crates/mcp-server/tests/tasks.rs: two tests still hang instead of failing when the containment is removed. The new timeout only guards the final call.test_second_extension_answers_after_first_panics_in_answer_as_task(task_of) and the firstget_task/cancel_taskintest_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usableare still unguarded. This affects test quality only; the tests do go red (by hanging) without the fix.
Verified
- follow-up round: the delta
ec6653a4..17ed2d77touches one file (tasks.rs, +5/−3) (executed:git diff ec6653a4..HEAD) - files read: 1/1 logic files in the delta (read in full)
- counter-proof (executed): I replaced
contain_panic(...)intask_statusandcancel_taskwith a pass-through.cargo test -p mcp-server --test tasks test_panicking_task_statusthen hung, andtimeout 300killed it. Aftergit checkout --, it passes. The worktree is clean. - AC 3 (read): after both not-found assertions (
INVALID_PARAMS,"task not found"), the test makes a realtools/callof the built-inpropose_commandon the same client. It is wrapped in a 20 s timeout, and the test asserts that a task comes back. This fulfils "a following built-in tool call on the same session works". - tests run locally (executed):
cargo test --locked -q -p mcp-server→ 66 passed (lib 38, extension 11, integration 5, tasks 12).cargo fmt --all --check→ ok. - CI (executed):
wait-ci 1672→ all checks green on17ed2d77 - edge cases (read): the final call comes after both panicking hooks and runs on the same session with the same extension, whose
answer_as_taskdoes not panic → ok - callers checked: the delta changes no production code → not applicable
- UI: not a UI change
- data: not touched
Timing analysis
- 1 test file analysed (delta of
tasks.rs): no timing dependency found. The 20 s timeout is only a hang guard around a plain request/response.
Spec
- visible behaviour changed: unchanged since the last round (panicking task hooks → no answer / not found)
- spec searched:
rg -il 'Fehlerhafte Erweiterung|answer_as_task|tasks/get' docs/specs/→ 0028 (also the unrelated 0045) - verdict: the spec change in 0028 §10a is present and matches the code. The changelog fragment is present and does not collide with #1675, which uses a different fragment file.
Security checks
- The delta is test-only. The production code is unchanged since the last round, which checked it for loosening and bypass attempts. A panic still maps to
None/ not-found /false, never to an approval, andcontain_panicsits insideHOOK_TIMEOUT.
Manual checks pending
- None.
Previous findings (follow-up round only)
- AC 3: the session check used
tools/listinstead of a tool call → fixed in 17ed2d7 - Timeouts so tests fail instead of hanging (non-blocking) → partly done (final call only); the rest is still open, see Non-blocking
Follow-ups
- None.
Closes #1659
Summary
answer_as_task,task_statusandcancel_tasknow run inside the existingcontain_panicwithin the timeout. A panic counts asNone/ not-found /false; a warning (originmcp) is logged without the panic payload.Acceptance Criteria
answer_as_taskstill waits for core outcome: met (tasks.rs:test_panicking_answer_as_task_still_waits_for_core_outcome)test_second_extension_answers_after_first_panics_in_answer_as_task)test_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usable)contain_panic, the warning is a constant string); the tests also assert the payload is absent from resultsNone/false, never an approval; first test shows the core outcome decides)Tests
Counter-proof: with the fix reverted, the new tests fail or hang; with it they pass.
Assumptions
Panic in
cancel_taskreturnsfalse(not-found), as recommended in the issue.Spec
updated 0028 (§10a)
Threat model: no change – THREAT-MODEL.md has no statement on MCP extension hook panics; this only contains a panic in three more hooks (behaviour tightens, no new surface, no new data leaves the process).
Follow-ups
None.
🤖 Generated with Claude Code
Review round
contain_panicsits inside the current timeouts foranswer_as_task,task_status,cancel_task.tasks.rs:test_panicking_task_status_and_cancel_task_are_not_found_and_session_stays_usablenow asserts the not-found error (task not found, code INVALID_PARAMS, which rmcp mapsRESOURCE_NOT_FOUNDto for 2026-07-28 peers) forget_taskandcancel_task.extension.rs:test_task_hook_panics_log_a_warning_without_payloadchecks a WARN with originmcpfor each of the three hooks and no panic payload.