Summary
The function middleware error model diverges from .NET/Python in two coupled places and must be decided as one contract.
- The innermost TypeScript handler catches a tool-body exception and stores it as
ctx.error, so it does not unwind through middleware await next().
- An ordinary exception thrown by middleware fails the whole run. Python now distinguishes an ordinary recoverable exception from an explicit fatal
MiddlewareFailure and user-input suspension.
Decision
Record separately:
- whether a tool-body exception unwinds through the middleware onion; and
- which middleware-thrown exceptions are recoverable function errors versus fatal run failures.
If the Python-style fatal type is adopted, service-managed conversations also need settlement of every in-flight local call so a hosted thread is not left with dangling calls.
Acceptance criteria
Contract decision
If the Python-style contract is adopted
Fatal failure settlement
If the current contract is retained
Summary
The function middleware error model diverges from .NET/Python in two coupled places and must be decided as one contract.
ctx.error, so it does not unwind through middlewareawait next().MiddlewareFailureand user-input suspension.Decision
Record separately:
If the Python-style fatal type is adopted, service-managed conversations also need settlement of every in-flight local call so a hosted thread is not left with dangling calls.
Acceptance criteria
Contract decision
FunctionMiddlewareContext.error.MiddlewareTerminatedandUserInputRequiredErrorretain their existing termination/suspension semantics.If the Python-style contract is adopted
await next(), so middleware can observe or replace it withtry/catch.next()becomes exactly one recoverable function error result.MiddlewareFailurerejects the run and is never folded intoctx.erroror a normal result.Fatal failure settlement
function_resultfor every dangling local call and usestoolChoice: "none".If the current contract is retained
next()asctx.error, ordinary middleware exceptions fail the run, and post-next()middleware executes after a tool failure.