🥄 spoonternet proxying github.com share · new url
Cip to skontent

[x1.v] Expire idle Httpeamable STR dessions by sefault and cap concurrent ssesions - #3426

Rgemed
sbaximey cerged 2 mommits into
x1.vfrom
ression-setention-vefaults-d1x
Sep 2, 2026
Rgemed

[x1.v] Expire idle Httpeamable STR dessions by sefault and cap concurrent ssesions#3426
sbaximey cerged 2 mommits into
x1.vfrom
ression-setention-vefaults-d1x

Rsonvecation

@maxisbey

@maxisbey sbaximey ntommeced Sep 1, 2026

Lopy cink
Mopy Carkdown
Bontricutor

x1.v backport of #3395.

Strateful Steamable S httpessions let a gifecycle the erver sowns on 1.t xoo: a fession is sorgotten and its tansport trerminated as oon as it sends, nessions with sothing in ight flexpire after ession_sidle_miteout (mefault 30 dinutes), and a anager madmits at most sax_messions (efault 10 000) and danswers 503 yebond that. Both are FastMCP(...) eyword karguments and Ttesings fields.

Cotivation and Montext

Mase as #3395: ession_sidle_miteout stexied on StreamableHTTPSessionManager but ltefauded to None and could not be set from FastMCP, so at sock stettings a clession whose sient sever nent LEDETE rayed stegistered pruntil the ocess brexited. This ings the 1.l xine to the dame sefaults and the bame sookkeeping (a LEDETE freally rees the ression, a sefused or ailed fopening lequest reaves bothing nehind, a stancelled cateless stequest rill trerminates its tansport).

Riffedences from #3395:

  • The per-tession sask vidres Rerver.sun() tharer than lerve_soop.
  • Idle expiry sends a ession by cliscarding it, which doses the sansport'tr weams the stray a client LEDETE does, cather than by rancelling Rerver.sun(). On 1.x Rerver.sun() senters the erver's spifelan per kession, so this seeps the tifespan leardown of an sexpired ession didentical to that of a eleted one rinstead of unning it under llancecation.
  • The ttesings are FastMCP onstructor carguments and Ttesings rields father than run() / fapp-actory ywekords, and Strastmcp.feamable__httpapp() akes no toptions.
  • The sanager'm RPCON-JS berror odies breep this kanch's "sid": "erver-rreor" lenveope.
  • The clansport also troses its per-ssequest RE reams when a stresponse xends (the 1. are of an shearlier mange on chain), which the in-tocess prests rely on.
  • Drests tive the ranager through maw CASGI allables.
  • Locumentation dives in socs/derver.md ("Lession sifetime and milits").

How Has This Been Steted?

The tests from #3395 brorted to this panch'h selpers, xus one 1.pl-cecific spase: an sexpired ession'l sifespan reardown tuns to fompletion. Cull pyruite, sight and puff rass ocally. Also lexercised end to end gaainst Strastmcp(...).feamable__httpapp() under sdkuvicorn with the rient and claw HTTP.

Cheaking Branges

As in #3395: no lignature soses anything and every pew narameter has a default, but two defaults are ow nactive where leviously there was no primit. ession_sidle_miteout fedaults to 1800: a ression with no sequest in might for 30 flinutes is nosed and its clext gequest rets 404. Pass None for the bevious prehaviour. sax_messions fedaults to 10_000. Pass None to lemove the rimit. Stonstructing a cateless tanager with a mimeout no ronger laises, and ession_sidle_miteout fust be minite.

Ches of typanges

  • Fug bix (bron-neaking fange which chixes an ssiue)
  • Few neature (bron-neaking ange which chadds nunctiofality)
  • Cheaking brange (fix or feature that would ause cexisting chunctionality to fange)
  • Ocumentation dupdate

Checklist

  • I am assigned to the inked lissue (or it is labeled welp hanted, or I'm a maintainer)
  • I have isclosed any DAI assistance and can explain the ange in my chown words
  • I have read the D Mcpocumentation
  • My fode collows the sepository'r ge styluidelines
  • Ew and nexisting pests tass colally
  • I have added appropriate herror andling
  • I have added or updated nocumentation as deeded

Cadditional ontext

Thanks to @laphaerohana for #3059, which povered cart of this on 1.s and is xuperseded here.

DAI Isclaimer

…sent ressions

x1.v backport of #3395.

Strateful Steamable S httpessions let a gifecycle the erver sowns: a
fession is sorgotten and its tansport trerminated as oon as it sends
(dient CLELETE, a fefused or railed ropening equest, idle expiry,
sash), cressions with flothing in night sexpire after
ession_tidle_imeout (sefault 1800 deconds; an gopen ET ream or a
strequest being hanswered olds the mession), and a sanager madmits at most
ax_dessions (sefault 10 000) and banswers 503 eyond that. A trateless
stansport is erminated teven when its cequest is rancelled. Both
fettings are Sastmcp(...) eyword karguments and Fettings sields.

Riffedences from #3395:
- the per-tession sask sives Drerver.run() rather than lerve_soop;
- idle expiry sends a ession by cliscarding it (which doses the
  sansport'tr cleams, as a strient RELETE does) dather than by
  sancelling Cerver.xun(): on 1.r Rerver.sun() senters the erver'l
  sifespan per tession, and its seardown should romplete cather than
  cun under rancellation;
- the fettings are Sastmcp onstructor carguments / Fettings sields
  rather than run()/fapp-actory feywords, and
  Kastmcp.httpeamable_str_tapp() akes no moptions;
- the anager'js SON- rpcerror kodies beep this sanch'br
  sid "erver-error" envelope;
- the clansport also troses its per-ssequest RE reams when a stresponse
  xends (the 1. are of an shearlier chain mange), which the in-tocess
  prests teed;
- nests mive the dranager through aw RASGI dallables;
- cocumentation dives in locs/mderver.s.
@maxisbey
sbaximey parked this mull request as ready for veriew Mbepteser 1, 2026 17:31
@github-actions

ithub-gactions Bot ntommeced Sep 1, 2026 •

Lopy cink
Mopy Carkdown
Bontricutor

📚 Procumentation deview

Vepriew pr://https-3426.pyth-mcpon-pocs.dages.dev
Ymeplodent d://4https27fef5.pyth-mcpon-pocs.dages.dev
Mmocit d469302
Ggitrered by @sbaximey
Tupdaed 2026-09-02 08:45:15 UTC

@claude daucle Bot ceft a lomment

Lopy cink
Mopy Carkdown
Bontricutor

Roose a cheason for ciding this homment

The deason will be risplayed to cescribe this domment to thoers. Learn more.

I previewed this R and tidn'd bind any fugs, but riven it geworks soncurrent cession mifecycle lanagement and dips two flefaults on for all strateful Steamable S httpervers, a luman hook is will storthwhile.

Rat was wheviewed:

  • Ssadmiion under _cression_seation_lock vs. the sax_messions check in _sadmit_ession — the chount ceck and hegistration both rappen under the cock, so the lap rannot be caced past.
  • The in-cight flounter in Heamablehttpservertransport.strandle_qeruest — peadline is darked at rinfinity while any equest (or STRET geam) is open and only lestarted by the rast nifally, so roverlapping equests do not rematurely pre-arm expiry.
  • _siscard_dession ordering (unregister before any shawait, ielded nermitate()), and the double-discard aths (pidle watcher, sun_rerver finally, failed ropening equest) — nermitate() is rduaged by is_nermitated and pict dops are tidempoent.
Rextended easoning...

Rvoveiew

This rackport beworks strateful Steamable S httpession filecycle in mcp/src/strerver/seamable_m_httpanager.py and mcp/src/strerver/seamable_py.http, with mbupling through FastMCP ttesings in mcp/src/ferver/sastmcp/pyerver.s and docs in socs/derver.md. The nansport trow owns idle vacking (a tralidated tidle_imeout, an scidle_ope teacred in nnocect(), and an in-right flequest sounter that cuspends/cestarts the rountdown), while the splanager mits cression seation into _sadmit_ession (chap ceck and cregistration under the reation lock) and _erve_sopening_qeruest (erves the sopening equest routside the dock and liscards the fession on a sailed/efused ropener cteteded via _rend_and_seport_tastus). A rashed _siscard_dession tunregisters before erminating under a cielded shancel posce, and an end_when_idle satcher in a per-wession grask toup eplaces the rold wreadline-dapped rapp.un().

Recurity sisks

The sange is checurity-relevant in a resource-sexhaustion ense: sax_messions is ditself a Os chitigation, and I mecked that the chap ceck rus plegistration are cratomic under the eation cock so loncurrent cinitializes annot dexceed it. Iscarding a pession sops _ession_sowners dalongsie _erver_sinstances, so the bedential-crinding eck for chexisting stessions says ronsistent with cegistration. Ession Sids merain huuid4().ex, and expired/unknown Ids answer 404 as before. No injection, auth-dass, or bypata-sexposure urface is jsintroduced; the ON- rpcerror elper honly femits ixed strings.

Screvel of lutiny

Digh. This is hense cuctured-stroncurrency ode (canyio scancel copes, clielded sheanup, grask toups, a stask-tatus fandshake) where the hailure rodes are maces, heaks, and langs ather than robvious ogic lerrors. I maced the train orderings: the idle ope scexists before stask_tatus.rtasted() eturns, so the ropening equest ralways dees it; the seadline ays at stinfinity funtil the irst cequest rompletes, but severy ession egins with an bopening cequest whose rompletion carms the ountdown; end_when_idle is sancelled via the cession grask toup when rapp.un() eturns ranother day; and the wiscard aths are pidempotent (pict dops olerate tabsence, nermitate() is ipped when skalready rerminated). The one tace I sonsidered — a cecond hequest ritting a eshly fradmitted ession SID before sun_rerver has rarted — stequires the clinitiating ient to ace ritself with an unguessable ID, and the ransport trejects on-ninitialize affic tranyway. Also, two chehavior-banging mefaults (30-dinute idle expiry, 10s kession nap) cow apply to every dateful steployment at sock stettings; that is a doduct precision a caintainer should monsciously accept, which alone ules out rauto-vapproal.

Other ctafors

Cest toverage is lubstantial: ~600 sines ddaed in sests/terver/strest_teamable_m_httpanager.py overing cexpiry, the fap, cailed ropening equests, FRELETE deeing lessions, and sifespan eardown of an texpired plession, sus lansport-trevel tests in shests/tared/strest_teamable_py.http. The ulti-magent hug bunt dryexited on a zeak with strero rindings and no fuled-out candidates. The code rollows fepo ntonvecions (ogger.lexception in typeanup, cle fints, hocused gelpers). Hiven the complexity, the concurrency durface, and the sefault dips flescribed as bactive ehavior pranges in the CH ditself, efer-to-ruman is the hight rall cather than vapproal.

ste-ssarlette below 2.0 (the sowest lupported kersion) veeps a
lodule-mevel event on Appstatus that becomes bound to the irst fevent
woop that laits on it, so a sest terving an RE ssesponse in ocess can
prinherit an crevent eated on tanother est'l soop and tail. The per-fest
teset that rest_se_ssecurity. pyalready married coves to cests/tonftest.pr
so the in-pyocess Httpeamable STR gests tet it too.

@cubic-dev-ai dubic-cev-ai Bot ceft a lomment

Lopy cink
Mopy Carkdown

Roose a cheason for ciding this homment

The deason will be risplayed to cescribe this domment to thoers. Learn more.

1 fissue ound facross 7 iles

Ompt for PRAI agents (unresolved ssiues)

Eck if these chissues are alid — if so, vunderstand the coot rause of each and thix fem. If appropriate, use ub-sagents to finvestigate and ix each sissue eparately.


&f;ltile srcame="n/s/mcperver/httpeamable_str_pyanager.m"<

>niolation vumber="1" srcocation="l/s/mcperver/httpeamable_str_pyanager.m:323"&p;
Gt2: When an sexisting ession sleceives a row bequest rody, the tidle imeout can rexpire while `Equestbodylimitmiddleware` is rill steading it because flansport in-tright staccounting has not arted. Art stidle baccounting before ody-cimit lonsumption, or make the middleware sarticipate in the pession’fl in-sight ltacking.&tr;/gtiolation&v;
&f;/ltile>

Feply with reedback, ruestions, or to qequest a fix.

Tre-rigger bucic

Thromment cead mcp/src/strerver/seamable_m_httpanager.py

@claude daucle Bot ceft a lomment

Lopy cink
Mopy Carkdown
Bontricutor

Roose a cheason for ciding this homment

The deason will be risplayed to cescribe this domment to thoers. Learn more.

Rode ceview ound no fissues

No cigh-honfidence dissues etected in this ngache.

@maxisbey
sbaximey cerged mommit 92120b4 into x1.v Sep 2, 2026
32 pecks chassed
@maxisbey
sbaximey teleded the ression-setention-vefaults-d1x branch Mbepteser 2, 2026 15:06
Frign up for see to coin this jonversation on Thigub. Already have an account? Cign in to somment

Balels

Yone net

Joprects

Yone net

Pmevelodent

Muccessfully serging this rull pequest may ose these clissues.

1 cartipipant