@@ -662,7 +662,14 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
662662 const registryRef = yield * Ref . make < AcpRegistryIndex | undefined > ( undefined ) ;
663663 const registryRevision = yield * Ref . make ( 0 ) ;
664664 const registrySemaphore = yield * Semaphore . make ( 1 ) ;
665- const installSemaphore = yield * Semaphore . make ( 1 ) ;
665+ // Downloads and package installs can take minutes, so each agent waits only
666+ // for its own install work, not for another agent's.
667+ const installPermits = new Map < string , Semaphore . Semaphore > ( ) ;
668+ const withInstallPermit = ( agentId : string ) => {
669+ const permit = installPermits . get ( agentId ) ?? Semaphore . makeUnsafe ( 1 ) ;
670+ installPermits . set ( agentId , permit ) ;
671+ return permit . withPermits ( 1 ) ;
672+ } ;
666673 const preparedBinaryReservations = yield * Ref . make < ReadonlyMap < string , number > > ( new Map ( ) ) ;
667674
668675 const managerBinDirectory = Effect . fn ( "AcpRegistryCatalog.managerBinDirectory" ) ( function * (
@@ -1646,13 +1653,13 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
16461653 if ( distribution . kind === "binary" ) {
16471654 // A PATH executable can be a different version with different ACP
16481655 // capabilities. Only an explicit command override opts into that copy.
1649- yield * installSemaphore . withPermits ( 1 ) (
1656+ yield * withInstallPermit ( agent . id ) (
16501657 installBinary ( agent , distribution . binaryTarget ! ) . pipe (
16511658 Effect . tap ( ( ) => reservePreparedBinary ( agent . id ) ) ,
16521659 ) ,
16531660 ) ;
16541661 } else {
1655- yield * installSemaphore . withPermits ( 1 ) (
1662+ yield * withInstallPermit ( agent . id ) (
16561663 ensureGlobalPackage ( agent , distribution . kind , distribution . packageName ! , hostEnvironment ) ,
16571664 ) ;
16581665 }
@@ -1729,7 +1736,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
17291736 }
17301737
17311738 if ( distribution . kind === "binary" ) {
1732- return yield * installSemaphore . withPermits ( 1 ) (
1739+ return yield * withInstallPermit ( agent . id ) (
17331740 Effect . gen ( function * ( ) {
17341741 const paths = binaryPaths ( agent , distribution . binaryTarget ! ) ;
17351742 if ( paths === undefined ) {
@@ -1841,7 +1848,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18411848 command = resolvedOverride ;
18421849 args = distribution . args ;
18431850 } else if ( distribution . kind === "npx" || distribution . kind === "uvx" ) {
1844- const installed = yield * installSemaphore . withPermits ( 1 ) (
1851+ const installed = yield * withInstallPermit ( agent . id ) (
18451852 ensureGlobalPackage (
18461853 agent ,
18471854 distribution . kind ,
@@ -1854,7 +1861,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18541861 commandBinDirectory = installed . binDirectory ;
18551862 } else {
18561863 const target = distribution . binaryTarget ! ;
1857- command = yield * installSemaphore . withPermits ( 1 ) (
1864+ command = yield * withInstallPermit ( agent . id ) (
18581865 installBinary ( agent , target ) . pipe (
18591866 Effect . tap ( ( ) => consumePreparedBinaryReservation ( agent . id ) ) ,
18601867 ) ,
@@ -1887,7 +1894,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
18871894 const uninstallManagedBinary : AcpRegistryCatalog [ "Service" ] [ "uninstallManagedBinary" ] = ( input ) =>
18881895 hostSettings
18891896 . withSnapshot ( ( settings ) =>
1890- installSemaphore . withPermits ( 1 ) (
1897+ withInstallPermit ( input . agentId ) (
18911898 Effect . gen ( function * ( ) {
18921899 const safeAgentId = yield * decodeBoundedAgentId ( input . agentId ) . pipe (
18931900 Effect . mapError (
0 commit comments